[OpenLayers-Users] getDataExtent() only working on part of data
of layer
Andreas Hocevar
ahocevar at opengeo.org
Fri Jun 12 06:41:48 EDT 2009
Hi Jan,
please post to the list instead of sending a mail to a developer directly.
I gave you a wrong setExtent function. The correct function should look
like this:
var setExtent = function() {
if(dataExtent) {
dataExtent.extend(this.getDataExtent());
} else {
dataExtent = this.getDataExtent();
}
map.zoomToExtent(dataExtent);
};
What was wrong? OpenLayers.Bounds::extend does not return the new
extent, it modifies the Bounds object it was used on. My bad, sorry for
the confusion.
Regards,
Andreas.
Jan Martin wrote:
> Hi Andreas,
>
> seems this isn't as easy as I thought.
>
> Still not working.
>
> Please find the whole folder containing all files as a .zip.
>
> Jan
>
> On Thu, Jun 11, 2009 at 7:41 PM, Andreas Hocevar <ahocevar at opengeo.org
> <mailto:ahocevar at opengeo.org>> wrote:
>
> Hi Jan,
>
> On Thu, Jun 11, 2009 at 6:49 PM, Jan
> Martin<janmartin3 at googlemail.com <mailto: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 <mailto: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 <mailto:ahocevar at opengeo.org>>
> >> wrote:
> >> > Hi Jan,
> >> >
> >> > On Thu, Jun 11, 2009 at 5:20 PM, Jan
> Martin<janmartin3 at googlemail.com <mailto: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 <mailto:Users at openlayers.org>
> >> http://openlayers.org/mailman/listinfo/users
> >
> >
> > _______________________________________________
> > Users mailing list
> > Users at openlayers.org <mailto:Users at openlayers.org>
> > http://openlayers.org/mailman/listinfo/users
> >
> >
>
>
>
> --
> Andreas Hocevar
> OpenGeo - http://opengeo.org/
> Expert service straight from the developers.
>
>
--
Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.
More information about the Users
mailing list