[OpenLayers-Users] [solved] Re: zoom to generated kml

Eike Kreikenbaum kreikenbaum at gmx.de
Sun Feb 13 16:46:14 EST 2011


Hi everybody

maybe you remember my questions from 27.1.2011 and the one later. i had to  
zoom to a external kml-file using the geoadmin-api.
after many problems i solved the problem in the following way:



<script type="text/javascript">
  function init() {
  OpenLayers.ProxyHost = "/ogcproxy?url=";

  var map = new GeoAdmin.API();
  map.createMap({
  div: "mymap",
     zoom: 5
  });


  //KML EINLADEN
  var kml_punkt = new OpenLayers.Layer.GML("Punkte", "pktx.kml",
  {
  format: OpenLayers.Format.KML,
  formatOptions: {
  extractStyles: true,
  extractAttributes: true
  }

  });

  //KML EINLADEN
  var kml_poly = new OpenLayers.Layer.GML("Poly", "poly.kml",
  {
  format: OpenLayers.Format.KML,
  formatOptions: {
  extractStyles: true,
  extractAttributes: true
  }

  });

  //MUSS BEI VEKTORLAYERN GESETZ WERDEN SONST WERDEN DIE DATEN NICHT  
ANGEZEIGT
  kml_punkt.projection = new OpenLayers.Projection("EPSG:4326");
  kml_poly.projection = new OpenLayers.Projection("EPSG:4326");

  //EVENT DAMIT NACH DEN EINLADEN EINER KML DER EXTENT AUTOMATISCH GESETZT  
WIRD
  map.map.addLayer(kml_punkt);
  kml_punkt.events.register("loadend", this, my_setExtent);


  //FUNKTION UM AUF DEN EXTENT EINER KML ZU ZOOMEN
  function my_setExtent() {
  map.map.zoomToExtent(kml_punkt.getDataExtent());
  };

  // polygons:
  var kmlLayer_poly = map.createKmlLayer('poly.kml',true);
  map.createTooltip(kmlLayer_poly);

  // points:
  var kmlLayer_poly = map.createKmlLayer('pktx.kml',true);
  map.createTooltip(kmlLayer_poly);

  }
</script>

now, the kml pktx.kml is clickalbe and the extend is zoomed to this layer.
it doesn't work on IE that far and the poly.kml is not clickable now, but  
that will is to be solved another time.
i just wanted to show the solution and show you , that i tried it on my  
own (in parts) :)

have nice day

eike





  Am 27.01.2011, 22:16 Uhr, schrieb Eike Kreikenbaum <kreikenbaum at gmx.de>:

> Hi everybody
>
> I use the swiss geoadmin api based on openlayers.
> using this api, i'd like to zoom to an kml file, that i include. this  
> file is generated dynamycalliy by php from a database. it is displayed  
> and everything is working, except the zoom.
> i can display the content, but i am not able to zoom automatically on  
> the contained features. from several www-articles, i got the  
> "map.zoomToExtent" posted below. i doesnt work, any help outside my room?
>
> This is the script:
>
> <script type="text/javascript">
> //Create a global api variable to simplify debugging - wozu braucht es  
> das??
> var api;
>
> //init funktion zum start der karte
> function init() {
>
> //toolbar anlegen
> var toolbar = new Ext.Toolbar({});
>
> //GeoAdmin API instanz starten
> api = new GeoAdmin.API();
>
> //GeoExt kartenausschnitt im div "mymap" platzieren
> api.createMapPanel({
> renderTo: "mymap",
> // begrenzung der bounding box
> maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,  
> 20037508.34),
>
> height: 500
> / toolbar im map panel
> ,tbar: toolbar,
> zoom: 1
> });
>
> // zoom auf kml
>
> //api.map.setCenter(new OpenLayers.LonLat(5, 5), 1);
>
> function kmlLoaded(){
> api.map.zoomToExtent(vectorLayer.getDataExtent())};
>
> vectorLayer = new OpenLayers.Layer.GML("KML", "pktx.kml",
> {
> format: OpenLayers.Format.KML,
> eventListeners: {'loadend': kmlLoaded }});
> api.map.addLayer(vectorLayer);
>
>
> // vor/zurück Buttons -> div "mynav"
> api.createNavigationHistory({
> renderTo: "mynav"
> });
>
>
>
> //Hintergrundlayer / Orthofoto
> //var baseLayerTool = api.createBaseLayerTool({label:  
> "Orthophoto",slider: {width: 80},combo: { width: 100}});
> //toolbar.add(baseLayerTool);
> //toolbar.doLayout();
> //toolbar.add('');
> //toolbar.doLayout();
>
> // Suche CH
> //Add a tool to search for Swissnames, Zip code, Cities and Cantons
> // var swissSearchCombo = api.createSwissSearchCombo({width: 140});
> // toolbar.add(swissSearchCombo);
> // toolbar.doLayout();
>
>
> // Landesgrenze
> //api.map.addLayerByName('ch.swisstopo.gg25-land-flaeche.fill');
>
> // KML layer in der Karte
>
> var kmlLayer = api.createKmlLayer('pktx.kml',true);
> var kmlLayer = api.createKmlLayer('grenzen.kml',false);
>
> var kmlLayer = api.createKmlLayer('poly.kml',false);
>
> //tooltip bei klick
> api.createTooltip({});
>
>
> }
> </script>
>
> many thanks for any helpfull comments
>
> Eike
>
>
>
> --
>
>


-- 

Eike Kreikenbaum
Rolandstrasse 3
8004 Zürich

0041 (0)77 428 31 60
-------------- next part --------------
Skipped content of type multipart/related


More information about the Users mailing list