----- Forwarded message from christophe triquet <net...@aliceadsl.fr> -----
From: christophe triquet <net...@aliceadsl.fr> To: Christopher Schmidt <crschm...@metacarta.com> Date: Mon, 18 Jan 2010 22:54:46 +0100 Subject: Re: [OpenLayers-Users] Zoom on GML extent 2010/1/18 Christopher Schmidt <crschm...@metacarta.com> > On Mon, Jan 18, 2010 at 01:32:24PM +0100, christophe triquet wrote: > > Hi, > > > > I'm adding a GML file in my map with the object OpenLayers.Layer.GML. I'm > > trying to zoom to this layer extent at map's loading. I can do this if I > > know de bounding box coordinates with a postgis query. > > > > My PHP code : > > > > var bounds = new OpenLayers.Bounds(); > > bounds.extend((new > > OpenLayers.LonLat(<?=$xmin?>,<?=$ymin?>)).transform(wgs84, > > map.getProjectionObject())); > > bounds.extend((new > > OpenLayers.LonLat(<?=$xmax?>,<?=$ymax?>)).transform(wgs84, > > map.getProjectionObject())); > > bounds.toBBOX(); > > map.zoomToExtent(bounds); > > > > But this requires a server call and I want my map to use only datas in > the > > GML file and not to have to connect to a database. > > > > I have seen that GML files includes bounded box informations like : > > > > <gml:boundedBy> > > <gml:Box> > > > > > <gml:coord><gml:X>1.473839004763629</gml:X><gml:Y>43.43941299999661</gml:Y></gml:coord> > > > > > <gml:coord><gml:X>1.647671004707115</gml:X><gml:Y>43.58098800002078</gml:Y></gml:coord> > > </gml:Box> > > </gml:boundedBy> > > > > Is it possible the get the gml extent to be able to automaticaly zoom on > it > > at loading ? > > Formats have a 'keepData' option or something like that, which then stashes > the data on the .data property of the format. You could then use standard > DOM methods to parse the data. > > Alternatively, you could just do: > > map.zoomToExtent(dataLayer.getDataExtent()); > > after the loadend event fires on the layer, which would iterate over the > features and get a bounding box. > > Regards, > -- > Christopher Schmidt > MetaCarta > Thank you everybody for your answears. That : var vectorLayer = ...; vectorLayer.events.on({ "loadend": function() { map.zoomToExtent(vectorLayer. getDataExtent()); } }); works if I deactivate and then reactivate my layer. What I'm trying to do is to zoom to the extent at loading time. The map.zoomToExtent(dataLayer.getDataExtent()); gives me a javascript error "Bounds is null". Maybe, I'm not calling this at the right time ? I have added this if (!map.getCenter()) map.zoomToExtent(dataLayer.getDataExtent()); at the end of typical init method called in <body onload="init()">. Any idea of what I'm doing wrong ? Regards, Christophe ----- End forwarded message ----- -- Christopher Schmidt MetaCarta _______________________________________________ Users mailing list Users@openlayers.org http://openlayers.org/mailman/listinfo/users