Map Gestures & Interactions
Configure scroll zoom, drag, and touch interaction behavior. Each library takes its own approach, compared side by side below.
Quick recommendations
Leaflet: Ideal when you need granular toggling of individual interactions (scrollWheelZoom, dragging, doubleClickZoom) via simple boolean options.
MapLibre GL JS: The right choice when you need cooperative gesture handling (Ctrl+scroll to zoom) for embedded maps with a clean overlay message.
OpenLayers: Makes the most sense when you need full control over the interaction stack: add, remove, or replace individual interaction instances.
MapTiler SDK: Works best for the simplest cooperative gesture setup, where one option enables the Ctrl+scroll overlay automatically.
At a glance
| Leaflet | MapLibre | OpenLayers | SDK | |
|---|---|---|---|---|
| Coordinates | [lat, lng] | [lng, lat] | fromLonLat([lng, lat]) | [lng, lat] |
| Rendering | DOM + Canvas (2D) | WebGL (GPU, 60fps) | Canvas + WebGL | WebGL (GPU, 60fps) |
| Bundle size | ~40 KB gzipped | ~300 KB gzipped | ~90 KB gzipped (tree-shakeable) | ~360 KB gzipped (includes MapLibre) |
| Learning curve | Easiest (simple API, great tutorials) | Moderate (source/layer model, expressions) | Steepest (projections, OGC standards, verbose API) | Easy (MapLibre API with convenience helpers) |
| 3D support | No native 3D (2D only) | Full: terrain, fill-extrusion, globe, sky | Limited: WebGL layers, no native globe | Full (same as MapLibre) |
| Code lines | 12 | 8 | 23 | 8 |
Code snippets
Click a library to expand its code. Each snippet shows only the core logic: the scaffold handles HTML boilerplate.
Leaflet 12 lines Show code
const map = L.map('map', {
scrollWheelZoom: false,
doubleClickZoom: false,
dragging: true,
zoomControl: true,
boxZoom: false
}).setView([51.5074, -0.1278], 13);
L.tileLayer('https://api.maptiler.com/maps/streets-v4/256/{z}/{x}/{y}.png?key=YOUR_MAPTILER_KEY', {
tileSize: 256,
attribution: '© <a href="https://www.maptiler.com/">MapTiler</a> © <a href="https://www.openstreetmap.org/copyright">OpenStreetMap contributors</a>'
}).addTo(map);
map.on('click', () => map.scrollWheelZoom.enable()); MapLibre GL JS 8 lines Show code
const map = new maplibregl.Map({
container: 'map',
style: 'https://api.maptiler.com/maps/streets-v4/style.json?key=YOUR_MAPTILER_KEY',
center: [13.405, 52.52],
zoom: 11,
cooperativeGestures: true
});
map.addControl(new maplibregl.NavigationControl()); OpenLayers 23 lines Show code
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
source: new ol.source.XYZ({
url: 'https://api.maptiler.com/maps/streets-v4/256/{z}/{x}/{y}.png?key=YOUR_MAPTILER_KEY',
attributions: '© <a href="https://www.maptiler.com/copyright/">MapTiler</a>'
})
})
],
view: new ol.View({
center: ol.proj.fromLonLat([2.3522, 48.8566]),
zoom: 13
}),
interactions: ol.interaction.defaults.defaults({
doubleClickZoom: true,
dragPan: true,
mouseWheelZoom: true,
pinchZoom: true,
pinchRotate: false,
altShiftDragRotate: false
})
}); MapTiler SDK 8 lines Show code
maptilersdk.config.apiKey = 'YOUR_MAPTILER_KEY';
const map = new maptilersdk.Map({
container: 'map',
style: maptilersdk.MapStyle.STREETS,
center: [2.3522, 48.8566],
zoom: 12,
cooperativeGestures: true
}); Things to know
Implementation-specific details that matter for map gestures & interactions.
Each interaction is an independent option (scrollWheelZoom, dragging, etc.); no built-in cooperative gesture mode.
cooperativeGestures option adds a Ctrl+scroll requirement with a semi-transparent overlay message for embedded maps.
Interactions are objects in an array, and you can pass ol.interaction.defaults({ mouseWheelZoom: false }) for fine-grained control.
Cooperative gestures work identically to MapLibre; the overlay message and Ctrl+scroll behavior are inherited.
Which library to use?
Turn Leaflet map gestures on or off with L.map() options like scrollWheelZoom and dragging, and re-enable a handler later with enable().
Ideal when you need granular toggling of individual interactions (scrollWheelZoom, dragging, doubleClickZoom) via simple boolean options.
Stop an embedded MapLibre GL JS map from hijacking page scroll by setting cooperativeGestures in the maplibregl.Map constructor options.
The right choice when you need cooperative gesture handling (Ctrl+scroll to zoom) for embedded maps with a clean overlay message.
Enable or disable OpenLayers map interactions such as wheel zoom, drag pan, and pinch rotate by passing options to ol.interaction.defaults.defaults.
Makes the most sense when you need full control over the interaction stack: add, remove, or replace individual interaction instances.
Require Ctrl+scroll to zoom an embedded MapTiler SDK map by setting cooperativeGestures to true in the maptilersdk.Map constructor.
Works best for the simplest cooperative gesture setup, where one option enables the Ctrl+scroll overlay automatically.
Build maps with AI
Generate code like these examples using mapping library skills in your IDE.