It is possible to change if a map is interactive or not after creating a map?
In the mapbox-gl-js documentation it is only possible to flag the map as interactive or non interactive when creating the map (option.interactive). But for some reasons I need to change it on the fly and toggle map interactiveness. Something like:
map.setInteractive(true);
or:
map.setInteractive(false);
Thanks for your support.
It is possible to change if a map is interactive or not after creating a map?
In the mapbox-gl-js documentation it is only possible to flag the map as interactive or non interactive when creating the map (option.interactive). But for some reasons I need to change it on the fly and toggle map interactiveness. Something like:
map.setInteractive(true);
or:
map.setInteractive(false);
Thanks for your support.
Share Improve this question asked Aug 4, 2016 at 12:57 Jordi TostJordi Tost 1091 silver badge9 bronze badges 1- There's an example demonstrating how to enable or disable map interactions here: mapbox./mapbox-gl-js/example/toggle-interaction-handlers – tristen Commented Aug 4, 2016 at 13:21
2 Answers
Reset to default 7This is how I do it, by disabling each of the map handlers:
(currently working on mapbox-gl-js/v0.45.0
)
var map = new mapboxgl.Map({
container: 'map', // container id
style: 'mapbox://styles/mapbox/streets-v9', // stylesheet location
center: [-74.50, 40], // starting position [lng, lat]
zoom: 9 // starting zoom
});
// disable map interaction so users can't pan, zoom, etc
map.boxZoom.disable();
map.scrollZoom.disable();
map.dragPan.disable();
map.dragRotate.disable();
map.keyboard.disable();
map.doubleClickZoom.disable();
map.touchZoomRotate.disable();
Handlers are documented here: https://www.mapbox./mapbox-gl-js/api/#Handlers
Mapbox GL JS does not currently have a dynamic setter for changing the interactivity of the map. This would be relatively simple to implement, so if you'd like to cut a ticket, or preferably submit a PR, on the github repository we would definitely consider adding this feature.
In the meantime, you can enable / disable all the interaction handlers individually to achieve the same effect dynamically after the map has been created.