OpenLayers and dragging

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)

How to stop the dragging?

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:

  1. OpenLayers disable mouse wheel on zoom
  2. OpenLayers Can Be Faster!
  3. Optimizing OpenLayers. Make it smaller and faster!