Is there a way to auto pan the map in the direction of mouse location if it hits the extents of the window when drawing line or polygon? It seems inefficient to have to pan by clicking the pan arrow if the polygon goes outside the map window. Hope this makes sense?


You shouldn't have to click the pan arrow, you should be able to drag the map the normal way even with the draw feature control active, as in this example. Just drag the map the way you usually would when the draw control is active and you'll see it won't draw any extra nodes. Other than this,I don't think there is a default OpenLayers way to do this, as it can't really know why your mouse has left the map viewport. Imagine if, whilst drawing your polygon, you received an email you wanted to read, you mouse would leave the viewport and OpenLayers would only be able to interpret this by panning the map. By the time you came back to your map it probably would've panned itself all the way to the Antarctic.

You can (apparently) do this for when you are modifying a feature, so that if you drag a node or the entire object to the edge of the window it will move. This option is available as a property of your modifyFeature object called 'documentDrag'. However, I have never got this to work myself (although I haven't really properly tried).

  • Thanks Rob, That is some really great information for me to utilise. Good point about the auto pan. I had not thought of that...either had the users requesting it ;-). Once again Thanks! – Haydlew Nov 28 '13 at 22:02
  • There might be a way round it, but I imagine it would require a lot of custom scripting and adding your own event listeners to the map for when you reach the edge and being able to handle the window losing focus etc. and I imagine it would be a fair chunk of work. Still, if you did and it was good enough you could merge it into the OpenLayers branch or submit it as an extension – Rob Quincey Nov 29 '13 at 8:28

See the example below http://dev.openlayers.org/examples/draw-feature.html I hope you help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.