Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenLayers: disable zooming on double-click

OpenLayers, by default, zooms in when a user double clicks a map.

What is the best way to disable this behavior?

like image 921
Ovesh Avatar asked Sep 19 '10 21:09

Ovesh


2 Answers

The zoom on double click feature is apparently a functionality in the OpenLayers.Control.Navigation control. See the OpenLayers Reference for more information.

A small and very tired example:

var Navigation = new OpenLayers.Control.Navigation({
    defaultDblClick: function(event) { return; }
});

I remember that the Navigation control is automatically added to the map if no controls are set during the initialization of the map. So you might have to add the Navigation control your self.

Hope it helps =)

like image 156
Chau Avatar answered Sep 21 '22 13:09

Chau


OpenLayers 3 Documentation Link.

Static way:

var map = new ol.Map({
    interactions: ol.interaction.defaults({ doubleClickZoom: false }),
    ...
});

Dynamic way:

var interactions = map.getInteractions();
for (var i = 0; i < interactions.getLength(); i++) {
    var interaction = interactions.item(i);                          
    if (interaction instanceof ol.interaction.DoubleClickZoom) {
        map.removeInteraction(interaction);
        break;
    }
}
like image 29
VAV Avatar answered Sep 20 '22 13:09

VAV