web developing
14 Jul
If working with OpenLayers you may know how the map by default is with dragging enabled. Even when in the API is said that setCenter() method is taking a forth parameter the boolean dragging it’s actually not working.
setCenter: function(lonlat, zoom, dragging, forceZoomChange)
As described there:
lonlat {OpenLayers.LonLat}
zoom {Integer}
dragging {Boolean} Specifies whether or not to trigger movestart/end events
forceZoomChange {Boolean} Specifies whether or not to trigger zoom change events (needed on baseLayer change)
It’s simple as stopping the mouse wheel as I writed before. Just add this chunk of code:
for (var i = 0; i< map.controls.length; i++) {
if (map.controls[i].displayClass ==
"olControlNavigation") {
map.controls[i].deactivate();
}
}
That works fine and stops the dragging, actually if you’d like to start dragging you must change the deactiveate() part of that code with activate(), which sounds normal.
Related posts:
3 Responses for "OpenLayers disable dragging"
This post has been really helpfull. From this I can also see what other map behavior I can disable. thanks
In order to make an static map with no controls or posibility to move or zoom the map I’ve noticed that some controls need to be disabled but others need to be removed. The code I use to avoid problems is the following:
map = new OpenLayers.Map(‘map’);
var numcontrol=map.controls.length;
for (var i = 0; i< numcontrol; i++) {
map.controls[0].deactivate();
map.removeControl(map.controls[0]);
}
Thanks Juan Carlos!
That’s exactly what I was looking for…
Leave a reply