<br><div class="gmail_quote"><div class="gmail_quote">2010/1/18 christophe triquet <span dir="ltr"><<a href="mailto:nethou@aliceadsl.fr" target="_blank">nethou@aliceadsl.fr</a>></span><div><div></div><div class="h5">
<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br><br><div class="gmail_quote">2010/1/18 Christopher Schmidt <span dir="ltr"><<a href="mailto:crschmidt@metacarta.com" target="_blank">crschmidt@metacarta.com</a>></span><div><div></div><div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div></div><div>On Mon, Jan 18, 2010 at 01:32:24PM +0100, christophe triquet wrote:<br>
> Hi,<br>
><br>
> I'm adding a GML file in my map with the object OpenLayers.Layer.GML. I'm<br>
> trying to zoom to this layer extent at map's loading. I can do this if I<br>
> know de bounding box coordinates with a postgis query.<br>
><br>
> My PHP code :<br>
><br>
> var bounds = new OpenLayers.Bounds();<br>
> bounds.extend((new<br>
> OpenLayers.LonLat(<?=$xmin?>,<?=$ymin?>)).transform(wgs84,<br>
> map.getProjectionObject()));<br>
> bounds.extend((new<br>
> OpenLayers.LonLat(<?=$xmax?>,<?=$ymax?>)).transform(wgs84,<br>
> map.getProjectionObject()));<br>
> bounds.toBBOX();<br>
> map.zoomToExtent(bounds);<br>
><br>
> But this requires a server call and I want my map to use only datas in the<br>
> GML file and not to have to connect to a database.<br>
><br>
> I have seen that GML files includes bounded box informations like :<br>
><br>
> <gml:boundedBy><br>
> <gml:Box><br>
><br>
> <gml:coord><gml:X>1.473839004763629</gml:X><gml:Y>43.43941299999661</gml:Y></gml:coord><br>
><br>
> <gml:coord><gml:X>1.647671004707115</gml:X><gml:Y>43.58098800002078</gml:Y></gml:coord><br>
> </gml:Box><br>
> </gml:boundedBy><br>
><br>
> Is it possible the get the gml extent to be able to automaticaly zoom on it<br>
> at loading ?<br>
<br>
</div></div>Formats have a 'keepData' option or something like that, which then stashes<br>
the data on the .data property of the format. You could then use standard<br>
DOM methods to parse the data.<br>
<br>
Alternatively, you could just do:<br>
<br>
map.zoomToExtent(dataLayer.getDataExtent());<br>
<br>
after the loadend event fires on the layer, which would iterate over the<br>
features and get a bounding box.<br>
<br>
Regards,<br>
<font color="#888888">--<br>
Christopher Schmidt<br>
MetaCarta<br>
</font></blockquote></div></div></div><br>Thank you everybody for your answears.<br><br>That :<div><br>
var vectorLayer = ...;<br>
vectorLayer.events.on({<br>
"loadend": function() {<br>
map.zoomToExtent(vectorLayer.
<div>getDataExtent());<br>
}<br>
});</div></div>
works if I deactivate and then reactivate my layer.<br>
<br>
What I'm trying to do is to zoom to the extent at loading time.<br><br>The map.zoomToExtent(dataLayer.getDataExtent()); gives me a javascript error "Bounds is null". <br><br>Maybe, I'm not calling this at the right time ? I have added this <br>
if (!map.getCenter()) map.zoomToExtent(dataLayer.getDataExtent());<br>at the end of typical init method called in <body onload="init()">.<br><br>Any idea of what I'm doing wrong ?<br><br>Regards,<br><font color="#888888">Christophe<br>
</font></blockquote></div></div></div><br>I think now my question is about events management.<br><br>If I put in my init function something like<br><br> dataLayer.events.on({<br> "loadend": function() {<br>
map.zoomToExtent(dataLayer.getDataExtent());<br> }<br> });<br><br>I get the zoom on layer extend (what I want) if I uncheck and then check the layer in the layer switcher.<br><br>Is there any way to trigger that event when the map loads ?<br>
<br>Thanks for your answears,<br><font color="#888888">Christophe<br>
</font></div><br>