Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm creating a web map of a university campus.

I have the map functioning, but I don't want to be able to pan off of the basemap, into whitespace.

Do you know of a function that will auto-pan the extent back to the basemap?

share|improve this question
A later question has a better answer (and jsFiddle)… – Amr Nov 25 '14 at 21:19
up vote 10 down vote accepted

This sample shows one method to monitor the extent and keep the user from panning beyond the established limits.

share|improve this answer
Nice find; bookmarked for when I'll eventually need it too. – Herb Oct 1 '10 at 14:11
Thanks. I ended up using that. – Tanner Oct 1 '10 at 22:52

I don't think there's a function to do it for you; you'll have to handle the onPan(extent, delta) event from Map, and see if the extent passed in from that event handler that is beyond your desired extents. If it is, you can forcefully set the map extents back. It might lack elegance, though - I haven't tried to see if the effect is a shaky map that's fighting the user.

share|improve this answer
I got it working using mcooper's answer, but yes, it does lack elegance. The map is shaky sometimes, but probably just needs some tweaking – Tanner Oct 1 '10 at 22:54

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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