<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=us-ascii" http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 8.00.6001.19088"></HEAD>
<BODY>
<DIV dir=ltr align=left><FONT color=#0000ff size=2 face=Arial><SPAN
class=174055317-07072011>Hi,</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT color=#0000ff size=2 face=Arial><SPAN
class=174055317-07072011></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT color=#0000ff size=2 face=Arial><SPAN
class=174055317-07072011>register "loadend" for your layer:</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT color=#0000ff size=2 face=Arial><SPAN
class=174055317-07072011></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT color=#0000ff size=2 face=Arial>MyKML
.events.register("loadend", MyKML , function (e) {<BR>
map.zoomToExtent(MyKML .getDataExtent());<BR>});<BR></FONT></DIV>
<DIV><SPAN class=174055317-07072011></SPAN><FONT color=#0000ff size=2
face=Arial><SPAN class=174055317-07072011>by the way, does your styleMap work
for the kml layer, if you set extractStyles to true?</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff size=2 face=Arial><SPAN
class=174055317-07072011></SPAN></FONT> </DIV>
<DIV><FONT face=Arial><FONT color=#0000ff><FONT
size=2>Arnd</FONT></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN
class=174055317-07072011></SPAN></FONT></FONT></FONT><BR> </DIV>
<DIV dir=ltr lang=de class=OutlookMessageHeader align=left>
<HR tabIndex=-1>
<FONT size=2 face=Tahoma><B>Von:</B> openlayers-users-bounces@lists.osgeo.org
[mailto:openlayers-users-bounces@lists.osgeo.org] <B>Im Auftrag von </B>Andres
Deparis<BR><B>Gesendet:</B> Donnerstag, 7. Juli 2011 08:31<BR><B>An:</B>
openlayers-users@lists.osgeo.org<BR><B>Betreff:</B> [OpenLayers-Users] Zooming
to center of a KML layer after loadingit - request for
assistance<BR></FONT><BR></DIV>
<DIV></DIV>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></BODY></HTML>