Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

map.zoomToExtent();

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

map.zoomToExtent(layer_name.getDataExtent());

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

2 Answers 2

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 at 18:59

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

 
discard

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.