Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

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

In Openlayers I can zoom to the bounding box of all layers like this:


I can also zoom to the bounding box of a single layer:


Is there an easy way of zooming to the extent of all layers except the base layer? In other words showing the extent of all overlays.

share|improve this question
up vote 6 down vote accepted
  1. for-loop over all of your layers
    1. Skip the base layer [per your requirement]
    2. Use bounds.extend(...) to build the all-encompassing bounds object API
  2. Zoom to the resulting bounds API
share|improve this answer
I think this won't work, because extends() only works if it is called on a smaller bounds than the one it is passed as argument. – pakman Jul 24 '14 at 18:59
How could i achieve same using OpenLayer API 3.x – imdadhusen Mar 12 '15 at 6:07
@imdadhusen why wouldn't you just look up the documentation? same method. same object. different namespace. – Vadim Mar 13 '15 at 15:07

what about fixing a map.restrictedExtent and call map.zoomToExtent(map.restrictedExtent) ?

share|improve this answer
That would just move the problem... How would I find out the bounding box of the overlays in order to create the restrictedExtent? – Mr_Chimp Feb 18 '11 at 14:30
have you try with ZoomToMaxExtent() - but it would probably zoom to base layer extent if larger? if it doesn't work you have to retrieve extent for each ovelays layers and keep the biggest one to fix restrictedExtent. – simo Feb 18 '11 at 14:43
I tried ZoomToMaxExtend() and it zooms to the base layer. I mentioned this in my question but on rereading it isn't obvious. Keeping the biggest bounding box wouldn't necessarily work - i.e. if two layers don't overlap. I guess I'll have to combine the bounding boxes of each layer somehow and then get the bounding box of the resulting object... – Mr_Chimp Feb 18 '11 at 14:56
That's it! Which is not that difficult ... But I agree with you, it's surprising such a method doesn't exist yet (or we missed something ;-)..) – simo Feb 18 '11 at 15:06
Well hopefully we've missed something! I'll leave the question open for now...just in case! – Mr_Chimp Feb 18 '11 at 15:12

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.