Geographic Information Systems Asked by againstflow on December 5, 2020
I need to disable all map interactions, like map zoom, drag, scroll zoom, any kind of interaction.
Is there some easy way to do it?
I didn't try this code but I hope it does the work :
var Interactions=yourMap.getInteractions();
for(var interaction in Interactions){
yourMap.removeInteraction(interaction);
}
this is for OL3
Edits :
when declaring the map, set the interactions to false within its attributes :
interactions: ol.interaction.defaults({
doubleClickZoom :false,
dragAndDrop: false,
keyboardPan: false,
keyboardZoom: false,
mouseWheelZoom: false,
pointer: false,
select: false
}),
and then using the method
ol.interaction.setActive(true);
you can re-enable them again, somehow setActive(false) didn't work for me, so here is a work around if it suits your needs
Answered by Hicham Zouarhi on December 5, 2020
If you don't want any interactions, just put interactions:null into your map constructor like that :
var map = new ol.Map({
interaction:null
});
If you don't want zoom buttons and info button, just put controls: null into your map constructor again
var map = new ol.Map({
interaction: null,
control: null
});
There you go : a working fiddle for example
Answered by tmylamoule on December 5, 2020
Shamelessly copied from another answer. Do this for each interaction type (MouseWheelZoom, PinchZoom, etc.)
var dblClickInteraction;
// find DoubleClickZoom interaction
map.getInteractions().getArray().forEach(function(interaction) {
if (interaction instanceof ol.interaction.DoubleClickZoom) {
dblClickInteraction = interaction;
}
});
// remove from map
map.removeInteraction(dblClickInteraction);
Answered by user7395921 on December 5, 2020
Openlayers 5
var map = new ol.Map({
...
controls: [],
interactions: []
});
Answered by mariovials on December 5, 2020
map.getInteractions().forEach(x => x.setActive(false));
Works also with setActive(true)
to re-enable interactions.
Answered by tooobi3006 on December 5, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP