Skip to content

Commit 5a9d1c9

Browse files
AmazingAngclaude
andcommitted
Add two-finger trackpad swipe to pan map, pinch to zoom
Disable default scroll-zoom and add custom wheel handler: - Regular two-finger swipe (no ctrlKey) → panBy (smooth panning) - Pinch gesture (ctrlKey=true from browser) → easeTo zoom This prevents the common issue of accidentally zooming when trying to scroll past the map on trackpad devices. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c3ec23c commit 5a9d1c9

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

src/components/WorldMap.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,25 @@ function WorldMapInner({
361361
dragRotate: false,
362362
});
363363

364+
// Two-finger trackpad swipe → pan; pinch (ctrlKey) → zoom
365+
// Browsers report pinch as wheel events with ctrlKey=true
366+
map.scrollZoom.disable();
367+
const canvas = map.getCanvasContainer();
368+
canvas.addEventListener("wheel", (e) => {
369+
if (e.ctrlKey || e.metaKey) {
370+
// Pinch gesture → zoom
371+
e.preventDefault();
372+
const center = map.getCenter();
373+
const zoom = map.getZoom();
374+
const delta = -e.deltaY * 0.01;
375+
map.easeTo({ zoom: zoom + delta, center, duration: 0 });
376+
} else {
377+
// Two-finger swipe → pan
378+
e.preventDefault();
379+
map.panBy([e.deltaX, e.deltaY], { duration: 0 });
380+
}
381+
}, { passive: false });
382+
364383
map.addControl(new maplibregl.NavigationControl({ showCompass: false }), "top-right");
365384

366385
// Track zoom tier changes for 2-tier clustering

0 commit comments

Comments
 (0)