[OpenLayers-Users] getDataExtent() only working on part of data of layer

Andreas Hocevar ahocevar at opengeo.org
Thu Jun 11 12:05:39 EDT 2009


Hi Jan,

On Thu, Jun 11, 2009 at 5:20 PM, Jan Martin<janmartin3 at googlemail.com> wrote:
> Hi all,
>
> right now getDataExtent() only considers the data added LAST (red).
> But I need the map to zoom in on ALL data in lgpx (green AND red).
>
> What's my error?

you need to take into account the dataExtent of both layers:

var dataExtent;
var setExtent = function() {
  dataExtent = dataExtent ? this.getDataExtent() :
this.getDataExtent().extend(dataExtent);
  map.zoomToExtent(dataExtent);
}
lgpx = new OpenLayers.Layer.GML
("green","separated/20090607172151.gpx",{
    projection: new  OpenLayers.Projection("EPSG:4326"),
    style: {strokeColor: "green", strokeWidth: 5, strokeOpacity: 0.8},
    format: OpenLayers.Format.GPX,});
lgpx.events.register("loadend", lgpx, setExtent);
map.addLayer(lgpx);
lgpx = new OpenLayers.Layer.GML
("red","separated/20090607110550.gpx",{
   projection: new  OpenLayers.Projection("EPSG:4326"),
    style: {strokeColor: "red", strokeWidth: 5, strokeOpacity: 0.8},
    format: OpenLayers.Format.GPX,});
lgpx.events.register("loadend", lgpx, setExtent);
map.addLayer(lgpx);

Regards,
Andreas.



More information about the Users mailing list