2010/1/18 christophe triquet <[email protected]>
> > 2010/1/18 Christopher Schmidt <[email protected]> > > 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 > I think now my question is about events management. If I put in my init function something like dataLayer.events.on({ "loadend": function() { map.zoomToExtent(dataLayer.getDataExtent()); } }); I get the zoom on layer extend (what I want) if I uncheck and then check the layer in the layer switcher. Is there any way to trigger that event when the map loads ? Thanks for your answears, Christophe
_______________________________________________ Users mailing list [email protected] http://openlayers.org/mailman/listinfo/users
