Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.65 KB | None | 0 0
  1. var wms = new OpenLayers.Layer.WMS(
  2. "OpenLayers WMS",
  3. "http://vmap0.tiles.osgeo.org/wms/vmap0",
  4. { layers: 'basic' }
  5. );
  6.  
  7. var kml_string = '<?xml version="1.0" encoding="utf-8"?> <kml xmlns="http://www.opengis.net/kml/2.2"> <Document> <Style id="boundaryLineColor1"> <LineStyle> <color>ff000000</color> <width>3</width> </LineStyle> <PolyStyle> <fill>false</fill> </PolyStyle> </Style> <Folder> <name>Soybean Yield</name> <Placemark> <name>Soybean Yield (1)</name> <styleUrl>#boundaryLineColor1</styleUrl> <Polygon> <outerBoundaryIs> <LinearRing> <coordinates>-91.3342663759154,32.5034766500927 -91.3342667084831,32.5034586155548 -91.3342986325171,32.5028817921232 -91.3347528643046,32.5013364566058 -91.3353490833926,32.5013263087953 -91.3371799720313,32.501314445573 -91.338116698321,32.5013087851122 -91.3386487408102,32.501315812754 -91.3386663742212,32.5015144742388 -91.3387262951512,32.5028862267216 -91.3387406121766,32.5032652339614 -91.3387805784262,32.5045645667511 -91.3389131380096,32.5089317435004 -91.3389218164796,32.5096173380048 -91.3389859320576,32.5153906443518 -91.3389832778257,32.5155349207259 -91.3388110064899,32.5156408789761 -91.337874131254,32.5156465397406 -91.3359365262234,32.5156569954422 -91.334957081528,32.5156620711925 -91.3346590909512,32.515658125708 -91.3345962338078,32.5156031766372 -91.3345799386691,32.5153323771848 -91.3345104393058,32.5133291373803 -91.3344968056745,32.5129140617432 -91.3342663759154,32.5034766500927</coordinates> </LinearRing> </outerBoundaryIs> </Polygon> </Placemark> </Folder> </Document> </kml>'
  8. var kmlParser = new OpenLayers.Format.KML({
  9. extractStyles: true,
  10. extractAttributes: true
  11. }); // Initialize with options if necessary
  12. var feature_list = kmlParser.read(kml_string);
  13. var sundialsTest = new OpenLayers.Layer.Vector("Test");
  14. sundialsTest.addFeatures(feature_list);
  15. this.application.map.map.addLayers([wms, sundialsTest]);
  16.  
  17. map.addLayer(sundialsTest);
  18.  
  19. map.addLayers([sundialsTest]);
  20.  
  21. console.log(this.application.map.map);
  22.  
  23. var map = null;
  24. var apiKey = "(...)"; // your Bing API key
  25. function init() {
  26. map = new OpenLayers.Map("map");
  27. map.addControl(new OpenLayers.Control.LayerSwitcher());
  28. var road = new OpenLayers.Layer.Bing({
  29. name: "Road",
  30. key: apiKey,
  31. type: "Road"
  32. });
  33. map.addLayers([road]);
  34. var kml_string = '<?xml version="1.0" encoding="utf-8"?> <kml xmlns="http://www.opengis.net/kml/2.2"> <Document> <Style id="boundaryLineColor1"> <LineStyle> <color>ff000000</color> <width>3</width> </LineStyle> <PolyStyle> <fill>false</fill> </PolyStyle> </Style> <Folder> <name>Soybean Yield</name> <Placemark> <name>Soybean Yield (1)</name> <styleUrl>#boundaryLineColor1</styleUrl> <Polygon> <outerBoundaryIs> <LinearRing> <coordinates>-91.3342663759154,32.5034766500927 -91.3342667084831,32.5034586155548 -91.3342986325171,32.5028817921232 -91.3347528643046,32.5013364566058 -91.3353490833926,32.5013263087953 -91.3371799720313,32.501314445573 -91.338116698321,32.5013087851122 -91.3386487408102,32.501315812754 -91.3386663742212,32.5015144742388 -91.3387262951512,32.5028862267216 -91.3387406121766,32.5032652339614 -91.3387805784262,32.5045645667511 -91.3389131380096,32.5089317435004 -91.3389218164796,32.5096173380048 -91.3389859320576,32.5153906443518 -91.3389832778257,32.5155349207259 -91.3388110064899,32.5156408789761 -91.337874131254,32.5156465397406 -91.3359365262234,32.5156569954422 -91.334957081528,32.5156620711925 -91.3346590909512,32.515658125708 -91.3345962338078,32.5156031766372 -91.3345799386691,32.5153323771848 -91.3345104393058,32.5133291373803 -91.3344968056745,32.5129140617432 -91.3342663759154,32.5034766500927</coordinates> </LinearRing> </outerBoundaryIs> </Polygon> </Placemark> </Folder> </Document> </kml>'
  35. var kmlParser = new OpenLayers.Format.KML({
  36. extractStyles: true,
  37. extractAttributes: true,
  38. internalProjection: new OpenLayers.Projection("EPSG:3857"),
  39. externalProjection: new OpenLayers.Projection("EPSG:4326")
  40. });
  41. var feature_list = kmlParser.read(kml_string);
  42. var sundialsTest = new OpenLayers.Layer.Vector("Test");
  43. sundialsTest.addFeatures(feature_list);
  44. map.addLayer(sundialsTest);
  45. map.zoomToExtent(sundialsTest.getDataExtent());
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement