show kml from variable instead of url

المشرف العام

Administrator
طاقم الإدارة
I am trying to add a layer from KML variable instead of url due to the current circumstances that force me to. I am using openlayer 2.13.1, chrome, VS and .net.

i have read the following link and follow them but still unable to show the result.

In OpenLayers can I replace a kml's URL for OpenLayers.Protocol.HTTP with the actual text of the kml?

How to add KML data but from variable - not from url?

OpenLayers 2.12 + KML from String + Change markers'icons

Below is my code:

var wms = new OpenLayers.Layer.WMS( "OpenLayers WMS", "http://vmap0.tiles.osgeo.org/wms/vmap0", { layers: 'basic' } );var kml_string = ' ff000000 3 false Soybean Yield Soybean Yield (1) #boundaryLineColor1 -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 'var kmlParser = new OpenLayers.Format.KML({ extractStyles: true, extractAttributes: true}); // Initialize with options if necessaryvar feature_list = kmlParser.read(kml_string);var sundialsTest = new OpenLayers.Layer.Vector("Test");sundialsTest.addFeatures(feature_list);this.application.map.map.addLayers([wms, sundialsTest]);Can someone please help? I am pretty new to OpenLayers. Thanks.



أكثر...
 
أعلى