Configure Map Gestures with MapTiler SDK
MapTiler SDKRequire Ctrl+scroll to zoom an embedded MapTiler SDK map by setting cooperativeGestures to true in the maptilersdk.Map constructor.
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
}); How to require Ctrl + scroll to zoom with MapTiler SDK
Setting cooperativeGestures: true in the constructor prevents accidental map interaction when scrolling a page. Users must hold Ctrl (or Cmd on Mac) while scrolling to zoom, and use two fingers on touch devices to pan.
An overlay message appears automatically when the user tries to interact without the modifier key. This is the same behavior as Google Maps.
Key APIs
| API | Description | Docs |
|---|---|---|
cooperativeGestures |
Constructor option to require modifier keys | docs.maptiler.com/sdk-js/api/ |
FAQ
Can I customize the overlay message?
MapTiler SDK uses a built-in message. To customize it, you can override the CSS for the cooperative gesture overlay element.
Does this affect programmatic zoom?
No. Methods like map.zoomTo() and map.flyTo() work normally regardless of this setting.
Common mistakes
- Enabling cooperative gestures on full-page maps where users expect direct interaction
- Confusing
cooperativeGestureswithscrollZoom: false. Cooperative gestures still allow zoom with modifier keys, whilescrollZoom: falsedisables it entirely
Build maps using MapTiler SDK with AI
Generate code like this configure map gestures with maptiler sdk example using the MapTiler SDK skill in your IDE.
Related examples
- Initialize a Map with MapTiler SDK
- See how to do this in Leaflet, MapLibre GL JS, or OpenLayers