[GIS] Disable doubleclick zooming in OpenLayers 3

javascriptopenlayerszoom

I've searched for it on the entire web and finally I found on artamstrong.com how to disable a single feature like "mouseWheelZoom".

Here is how doubleclick zooming in OpenLayers 3 can be disabled:

var map = new ol.Map({
    controls : ol.control.defaults()
                .extend([ new ol.control.FullScreen() ]),
    interactions : ol.interaction.defaults({doubleClickZoom :false}),
    target : 'map',
    layers : [ new ol.layer.Tile({
            title : 'OpenStreetMaps',
            preload : Infinity,
            source : new ol.source.OSM(),
            visible : true
    }) ],
    view : new ol.View({
            center : ol.proj.transform([ 9.41, 48.82 ], 'EPSG:4326','EPSG:3857'),
            zoom : 12
    })
});

It's really that simple, just tell ol3 to set "doubleClickZoom" on false:

interactions : ol.interaction.defaults({doubleClickZoom :false})

Best Answer

If you want to disable doubleClickZoom after map initialization, here is the way:

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);

You can also remove or add interaction such as PinchZoom, KeyboardZoom, etc,. with the same way.

Related Question