[OpenLayers-Users] Zooming to center of a KML layer after loadingit - request for assistance

Andres Deparis andres.deparis at gmail.com
Thu Jul 7 21:15:32 EDT 2011


Hello Arnd,

Thank you it works!

As for your question: by the way, does your styleMap work for the kml layer,
if you set extractStyles to true?

I did not bother looking into it now, at first glance it does not. But, I
will surely update you when I get to that in a week or so.

Thank you again. I will update you soon.

Regards.
Andres D.P.


On Fri, Jul 8, 2011 at 1:58 AM, Arnd Wippermann <arnd.wippermann at web.de>wrote:

> **
> Hi,
>
> register "loadend" for your layer:
>
> MyKML .events.register("loadend", MyKML , function (e) {
>     map.zoomToExtent(MyKML .getDataExtent());
> });
> by the way, does your styleMap work for the kml layer, if you set
> extractStyles to true?
>
> Arnd
>
>
>  ------------------------------
> *Von:* openlayers-users-bounces at lists.osgeo.org [mailto:
> openlayers-users-bounces at lists.osgeo.org] *Im Auftrag von *Andres Deparis
> *Gesendet:* Donnerstag, 7. Juli 2011 08:31
> *An:* openlayers-users at lists.osgeo.org
> *Betreff:* [OpenLayers-Users] Zooming to center of a KML layer after
> loadingit - request for assistance
>
> Hello everyone,
>
> 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.
>
> Below is my piece of code. Thank you in advance for the advice.
>
> Andres D.P
>
> var map;
>
> function init() {
>
>
>        map = new OpenLayers.Map({
>         div: "map",
>         //projection: new OpenLayers.Projection("EPSG:900913"),
>         units: "m",
>         maxResolution: 156543.0339,
>         maxExtent: new OpenLayers.Bounds(
>                  119.715815, -0.771406, 97.637881  ,7.640186
>         )
> ,panDuration: 250    });
>
>  styleMap = new OpenLayers.StyleMap({'default':{
>                         //label : "${th}",
>                         label : "MYdog",
>                         fontColor: "${fontColor}",
>                         fontSize: "16px",
>                         labelAlign: "${labelAlign}",
>                         pointRadius: 2,
>                         labelXOffset : 0,
>                         labelYOffset : 20
>                     }});
>
>         var osm = new OpenLayers.Layer.OSM();
>         //var vlayer = new OpenLayers.Layer.Vector( "Editable" );
>         var MyKML = new OpenLayers.Layer.GML("KML", "dog.kml",
>                {
>                 projection: new OpenLayers.Projection("EPSG:4326"),
>                 //displayProjection: new
> OpenLayers.Projection("EPSG:900913"),
>
>                 format: OpenLayers.Format.KML,
>                 formatOptions: {
>                   extractStyles: true,
>                   extractAttributes: true,
>                   maxDepth: 1
>                 },
>                 styleMap: styleMap
>                });
>
>    map.addLayers([osm, MyKML]);
>    map.addControl(new OpenLayers.Control.PanZoomBar());
>    map.addControl(new OpenLayers.Control.Navigation({dragPanOptions:
> {enableKinetic: true}}));
>    map.addControl(new OpenLayers.Control.LayerSwitcher());
>
> //    map.addControl(new OpenLayers.Control.MouseToolbar());
> //    map.addControl(new OpenLayers.Control.Navigation());
> //    map.addControl(new OpenLayers.Control.LayerSwitcher());
> //    map.addControl(new OpenLayers.Control.PanZoom());
> //    map.addControl(new OpenLayers.Control.EditingToolbar();
> //    map.addControl(OpenLayers.Control.EditingToolbar(vlayer));
>
>
>     map.setCenter(new OpenLayers.LonLat(101.587411,
> 3.021547).transform(new OpenLayers.Projection ("EPSG:4326"),
> map.getProjectionObject()
> ),
> 15);
>
>
> //map.zoomToExtent( MyKML.GetExtent() );
>
> window.setInterval(raingaugeRefreshData, 10000, MyKML);
>
>
> }
>
> function raingaugeRefreshData(layer)
> {
> //setting loaded to false unloads the layer//
>
>
>                 layer.loaded = false;
>                 //setting visibility to true forces a reload of the layer//
>                 layer.setVisibility(true);
>                 //the refresh will force it to get the new KML data//
>                 layer.setUrl('MyDOG.kml?_salt='+Math.random());
>                 //- <3 from Thqr -//
>          map.zoomToExtent( MyKML.maxExtent );
>
>
>
> }
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20110708/5cc13db3/attachment-0001.html


More information about the Users mailing list