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: "map",<br> //projection: new OpenLayers.Projection("EPSG:900913"),<br>
units: "m",<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({'default':{<br> //label : "${th}",<br> label : "MYdog",<br> fontColor: "${fontColor}",<br>
fontSize: "16px",<br> labelAlign: "${labelAlign}",<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( "Editable" );<br> var MyKML = new OpenLayers.Layer.GML("KML", "dog.kml", <br>
{<br> projection: new OpenLayers.Projection("EPSG:4326"),<br> //displayProjection: new OpenLayers.Projection("EPSG:900913"), <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 ("EPSG:4326"),<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('MyDOG.kml?_salt='+Math.random());<br> //- <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>