[OpenLayers-Users] Zoom to a Layer's Extent

Bill Thoen bthoen at gisnet.com
Fri Sep 5 13:12:28 EDT 2008


That would zoom out to the entire map. I just want to automatically zoom 
out to the extents of a layer and center on it. I shouldn't have called 
it 'baseLayer' because it's not a Base Layer; it's an Overlay Layer. 
Imagine a Base Layer of North America, and then you load a WFS layer of 
say, state boundaries of Colorado, Utah, New Mexico and Arizona called 
myStates, and now I want to set the zoom so that the myStates layer 
fills the view.

If I set a listener for loadend and the function called checks to make 
sure that there are features loaded, then why does 
myStates.getDataExtent() return null? Shouldn't this function return the 
bounds of the features now loaded into this layer?  Or are the bounds 
not updated when a WFS layer is loaded?

Eric Lemoine wrote:
> How about map.zoomToMaxExtent()? Eric
>
> 2008/9/5, Bill Thoen <bthoen at gisnet.com>:
>   
>> All I know is that I have some vectors in a layer somewhere on the map,
>> but I don't know where their center is or how far out I need to zoom to
>> them all at the maximum zoom scale.  I need a bounding box for an entire
>> layer, if that's possible because these layers are not the same (these
>> are pipeline networks for different companies).
>>
>> Eric Lemoine wrote:
>>     
>>> Hi. Why don't you use map.setCenter to zoom to a specific zoom level? Eric
>>>
>>> 2008/9/3, Bill Thoen <bthoen at gisnet.com>:
>>>
>>>       
>>>> I want to zoom a map to the extent of a layer (called baseLayer) but
>>>> when I try:
>>>> map.zoomToExtent(baseLayer.getDataExtent());
>>>> the baseLayer.getDataExtent() function returns null. When I don't
>>>> include this line everything works fine (the layer appears normally,
>>>> only without the zoom that I want.) What am I missing here?
>>>>         




More information about the Users mailing list