Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable zoom with Openlayers

i'm using OpenLayers to display custom OSM maps on my website.

I've some points to respect: the map have to be fix (meaning that we can't drag it or zoom it).

I have a problem with the zoom, i can't manage to disable zoom with the mouse. Does anyone has a tip?

map = new OpenLayers.Map('map');
map.events.remove("move");
map.events.remove("movestart");
map.events.remove("moveend");
map.events.remove("zoomend");
map.events.remove("mouseover");
map.events.remove("mouseout");
map.events.remove("mousemove");
map.events.remove("zoomstart");
var nav = new OpenLayers.Control.Navigation({
  defaultDblClick: function(event) { return ; }
});
map[index].addControl(nav);

Also, if someone has a tip to remove all Navigation events easier than that, it would be greatly appreciated.

like image 916
GeoffreyB Avatar asked Sep 11 '12 09:09

GeoffreyB


3 Answers

For OpenLayers3 the interaction array also needs to be empty.

var map = new ol.Map({
  controls: [],
  interactions: []
});
like image 147
ThomasK Avatar answered Sep 22 '22 10:09

ThomasK


Simplifying approach of Mahdi results in

var i, l, c = map.getControlsBy( "zoomWheelEnabled", true );
for ( i = 0, l = c.length; i < l; i++ ) {
    c[i].disableZoomWheel();
}

This way disabling zoom on mouse wheel doesn't require to customize options on constructing map e.g. by creating map without any control (though this was somewhat requested by Lght). In addition re-enabling zoom works equivalently.

In addition, by searching controls matching enabled property zoomWheelEnabled rather than class name it's supporting custom controls derived from OpenLayers.Control.Navigation.

like image 39
Thomas Urban Avatar answered Sep 21 '22 10:09

Thomas Urban


Disable the default controls on your map by passing an empty array:

var map = new OpenLayers.Map('map', { controls: [] });
like image 21
tonio Avatar answered Sep 21 '22 10:09

tonio