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

Bill Thoen bthoen at gisnet.com
Mon Sep 8 11:27:03 EDT 2008


Christopher Schmidt wrote:
> On Fri, Sep 05, 2008 at 01:10:53PM -0600, Bill Thoen wrote:
>   
>> Christopher Schmidt wrote:
>>     
>>> In 2.7RC1 (just released) you can use getDataExtent() for that. (We
>>> didn't add getDataExtent for vector layers until after 2.6.)
>>>
>>> Also, using 2.7RC1 would help us get more 2.7 testing :)
>>>       
I checked again and it doesn't seem to work with WFS layers at least.

If you look at http://206.168.217.244/zoomToLayerExtents.html, you'll 
see what I mean.

In this example, (using 2.7RC1) I open a base layer of the US from 
MapServer and then open an overlay layer of a pipeline network from a 
MapServer WFS. Then I set up a listener to call the function 
layerLoaded() on the loadend event (so that the layer has its features 
array populated.) Finally, in layerLoaded I call  map.zoomToExtent 
(layer.getDataExtent()), but the map doesn't zoom. The commented out 
call to zoomToLayerExtents() right next to that line actually does what 
I want (which is to zoom into the area covered by the pipeline layer.)

So is this a bug with getDataExtent() or is it working as its should and 
I'm just using it wrong?

- Bill Thoen




More information about the Users mailing list