Hello everyone,<br><br>I am trying to be able to zoom or Pan (zooming first) to the center of the data from my kml file that I load periodically. But, in my case, I can load the data (which consist of one point at this moment) and then of course to be able to center to that point. I have searched and found out that perhaps my method does not work because I am zooming into the data but not waiting for the data to be fully loaded.<br>
<br>Below is my piece of code. Thank you in advance for the advice.<br><br>Andres D.P<br><br>var map;<br><br>function init() {<br>    <br><br>       map = new OpenLayers.Map({<br>        div: &quot;map&quot;,<br>        //projection: new OpenLayers.Projection(&quot;EPSG:900913&quot;),<br>
        units: &quot;m&quot;,<br>        maxResolution: 156543.0339,<br>        maxExtent: new OpenLayers.Bounds(<br>                 119.715815, -0.771406, 97.637881  ,7.640186<br>        )<br>,panDuration: 250    });<br>
<br> styleMap = new OpenLayers.StyleMap({&#39;default&#39;:{<br>                        //label : &quot;${th}&quot;,<br>                        label : &quot;MYdog&quot;,<br>                        fontColor: &quot;${fontColor}&quot;,<br>
                        fontSize: &quot;16px&quot;,<br>                        labelAlign: &quot;${labelAlign}&quot;,<br>                        pointRadius: 2,<br>                        labelXOffset : 0,<br>                        labelYOffset : 20<br>
                    }});<br><br>        var osm = new OpenLayers.Layer.OSM();<br>        //var vlayer = new OpenLayers.Layer.Vector( &quot;Editable&quot; );<br>        var MyKML = new OpenLayers.Layer.GML(&quot;KML&quot;, &quot;dog.kml&quot;, <br>
               {<br>                projection: new OpenLayers.Projection(&quot;EPSG:4326&quot;),<br>                //displayProjection: new OpenLayers.Projection(&quot;EPSG:900913&quot;), <br><br>                format: OpenLayers.Format.KML, <br>
                formatOptions: {<br>                  extractStyles: true, <br>                  extractAttributes: true,<br>                  maxDepth: 1<br>                },<br>                styleMap: styleMap<br>               });<br>
               <br>   map.addLayers([osm, MyKML]);<br>   map.addControl(new OpenLayers.Control.PanZoomBar());<br>   map.addControl(new OpenLayers.Control.Navigation({dragPanOptions: {enableKinetic: true}}));<br>   map.addControl(new OpenLayers.Control.LayerSwitcher());   <br>
   <br>//    map.addControl(new OpenLayers.Control.MouseToolbar());<br>//    map.addControl(new OpenLayers.Control.Navigation());<br>//    map.addControl(new OpenLayers.Control.LayerSwitcher());<br>//    map.addControl(new OpenLayers.Control.PanZoom());<br>
//    map.addControl(new OpenLayers.Control.EditingToolbar();<br>//    map.addControl(OpenLayers.Control.EditingToolbar(vlayer));<br>     <br><br>    map.setCenter(new OpenLayers.LonLat(101.587411,   3.021547).transform(new OpenLayers.Projection (&quot;EPSG:4326&quot;),<br>
map.getProjectionObject()<br>), <br>15); <br><br> <br>//map.zoomToExtent( MyKML.GetExtent() );<br><br>window.setInterval(raingaugeRefreshData, 10000, MyKML);<br><br><br>}<br><br>function raingaugeRefreshData(layer)<br>{<br>
//setting loaded to false unloads the layer//<br><br>                <br>                layer.loaded = false;<br>                //setting visibility to true forces a reload of the layer//<br>                layer.setVisibility(true);<br>
                //the refresh will force it to get the new KML data//<br>                layer.setUrl(&#39;MyDOG.kml?_salt=&#39;+Math.random());<br>                //- &lt;3 from Thqr -//<br>         map.zoomToExtent( MyKML.maxExtent );<br>
        <br>                         <br>                <br>}<br><br> <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>