[GIS] Disabling map drag and zoom in OpenLayers 3

openlayersopenlayers-2

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?

Best Answer

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

Related Question