Hi Jan,
On Thu, Jun 11, 2009 at 5:20 PM, Jan Martin<[email protected]> 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.
_______________________________________________
Users mailing list
[email protected]
http://openlayers.org/mailman/listinfo/users