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

Andreas Hocevar ahocevar at opengeo.org
Thu Jun 11 13:41:36 EDT 2009


Hi Jan,

On Thu, Jun 11, 2009 at 6:49 PM, Jan Martin<janmartin3 at googlemail.com> wrote:
> Hi Andreas,
>
> thanks for your help.
>
> I hope I changed my file right, but unfortunately its not working:
>
> http://mybestprojects.com/data/test5/test5.html

Sorry, my bad. Wrong setExtent function. Please change to

var setExtent = function() {
  dataExtent = dataExtent ? this.getDataExtent().extend(dataExtent) :
    this.getDataExtent();
  map.zoomToExtent(dataExtent);
}

> Also I have no clue how to implement Format.GPX::read
> There are no results of anybody using it  when googling for it.
> Can't be can it?

OpernLayers.Format.* classes have a read method. This can be used to
read features from data files. But no need to bother, with the above
fix your app should work.

Regards,
Andreas.

>
> Jan
>
> On Thu, Jun 11, 2009 at 6:07 PM, Andreas Hocevar <ahocevar at opengeo.org>
> wrote:
>>
>> Hi Jan,
>>
>> one more thing that came to my mind: are you aware that you are
>> working with two layers here? From what you wrote, it seems you think
>> that you have one layer lgpx. But in fact you have two, you just use
>> the same variable for both.
>>
>> You could also solve your problem with just one layer, but then you
>> would have to use Format.GPX::read to get the features from both urls.
>> You would also have to take care to style the features properly (red
>> from one url, green from the other).
>>
>> I guess the way you chose is simpler, you just have to be aware that
>> you are working with two layers.
>>
>> Regards,
>> Andreas.
>>
>> On Thu, Jun 11, 2009 at 5:55 PM, Andreas Hocevar<ahocevar at opengeo.org>
>> wrote:
>> > 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.
>>
>>
>> --
>> Andreas Hocevar
>> OpenGeo - http://opengeo.org/
>> Expert service straight from the developers.
>> _______________________________________________
>> Users mailing list
>> Users at openlayers.org
>> http://openlayers.org/mailman/listinfo/users
>
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>
>



-- 
Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.



More information about the Users mailing list