OpenLayers disable dragging

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!
This entry was posted in web development. Bookmark the permalink.

5 Responses to OpenLayers disable dragging

  1. Juan Carlos says:

    This post has been really helpfull. From this I can also see what other map behavior I can disable. thanks

  2. Juan Carlos says:

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

  3. MartinO says:

    Thanks Juan Carlos!
    That’s exactly what I was looking for…

  4. John says:

    Hello i have problem :(
    when i use map.setCenter and var bounds = new OpenLayers.Bounds in own map, overview map not work…i try add maximized: true to options in overview map…working better but no perfect, what am i doing? I looking for google but no results was good.

  5. Abhijit says:

    Thanks a lot, that worked for me.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">