On Friday, October 29, 2010, Daniel Weaver <[email protected]> wrote:
>
>
> I'm trying to get the bounds of a vector
> layer I have using the getDataExtent function of OpenLayers.Layer.Vector.
> However, when I use the function, it returns a null value. Is
> this a bug in 2.10? I know previous versions had a bug, but I thought
> it might be fixed by now.
>
>
> Below are the relevant portions of
> my code :
>
>
> var landunits = new OpenLayers.Layer.Vector("Land
> Units", {
>
>
> styleMap: myStyles,
>
>
> filter: new OpenLayers.Filter({
>
>
> type:
> OpenLayers.Filter.Comparison.NOT_EQUAL_TO,
>
>
> property:
> "lat",
>
>
> value:
> 0
>
>
> }),
>
>
> strategies: [new OpenLayers.Strategy.BBOX()],
>
>
> protocol: new OpenLayers.Protocol.WFS({
>
>
> url: "http://igsaceeswsmwime:8080/geoserver/wfs",
>
>
> featureType: "lupoints",
>
>
> featureNS: "http://igsaceeswsmwime:8080/geoserver/monitoring",
>
>
> })
>
>
>
>
>
> });
>
>
> //Then I try to retrieve the bounds
> for this layer
>
> map.addLayers([landunits]);
>
> var bounds = landunits.getDataExtent();
>
> map.zoomToExtent(bounds);
>
> -------------------------------------------------
>
>
> However, this does not work and firebug
> tells me that bounds variable is null.
>
>
> any suggestions?
The data is loaded asynchronously, so you need to wait for it to be
there. Before you add the layer to the map do:
landunits.events.on({
loadend: function() {
map.zoomToExtent(landunits.getDataExtent());
}
});
Hope it helps.
--
Eric Lemoine
Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex
Tel : 00 33 4 79 44 44 96
Mail : [email protected]
http://www.camptocamp.com
_______________________________________________
Users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/openlayers-users