0

How to replace myParser.parse('path/to/data.kml') into variable that contain kml file like this. https://github.com/geocodezip/geoxml3

var myParser = new geoXML3.parser({map: map});
myParser.parse('/path/to/data.kml');

Like this:

  var result = "<?xml version="1.0" encoding="UTF-8"?> ... </kml>'"
  var myParser = new geoXML3.parser({map: map});
  myParser.parse(result);
Cœur
  • 37,241
  • 25
  • 195
  • 267
Yamoshi Wolverine
  • 401
  • 1
  • 5
  • 12

1 Answers1

1

geoXML3 library contains parseKmlString function to parse KML from a string.

Example

function initMap() {
    var map = new google.maps.Map(document.getElementById('map'), {
      zoom: 16,
      center: {lat: 31.40065516914794, lng: -98.30505371484378}
    });
  
    
    var parser = new geoXML3.parser({map: map});
    parser.parseKmlString('<kml xmlns="http://www.opengis.net/kml/2.2"><Document><Placemark><name><![CDATA[]]>Polygon</name><description><![CDATA[]]></description><Polygon><extrude>1</extrude><altitudeMode>relativeToGround</altitudeMode><outerBoundaryIs><LinearRing><coordinates>-93.46008301171878,31.329035778926478,0 -98.30505371484378,31.40065516914794,0 -97.37121582421878,30.106233605369603,0 -92.65808105859378,30.14749530904506,0</coordinates></LinearRing></outerBoundaryIs> </Polygon></Placemark></Document></kml>'); 
  }


  google.maps.event.addDomListener(window, 'load', initMap);
#map {
        height: 140px;
      }
<script src="https://maps.googleapis.com/maps/api/js"></script>
<script src="https://rawgit.com/geocodezip/geoxml3/master/polys/geoxml3.js"></script>
<div id="map"></div>
Vadim Gremyachev
  • 57,952
  • 20
  • 129
  • 193
  • sir @vadim gremyachev, sir can i ask you one last time regarding to your answer here in stackoverflow https://stackoverflow.com/questions/34886358/how-to-render-maps-within-ng-hide-divs-using-ngmap-without-getting-a-gray-rectan.. what if i want to use display:none? is it possible? – Yamoshi Wolverine Aug 31 '17 at 06:15
  • Hello @Paulo, unfortunately the hiding the map with `display:none` does not work properly, instead i would suggest to use `visibility: hidden` – Vadim Gremyachev Aug 31 '17 at 11:34
  • sir @Vadim can i ask you again? should i download this header that needs in geoxml? and add to my project. or leave it as is?. – Yamoshi Wolverine Sep 04 '17 at 05:07
  • is it ok to download this header to my project? or will i have a problem in the future if i download this? and use this this forever.? sorry my english is bad. – Yamoshi Wolverine Sep 04 '17 at 07:45
  • I would suggest to keep a reference to Google Maps library via 'https://maps.googleapis.com/maps/api/js' , downloading it could be problematic since it has a dependency to additional packages behind the scene – Vadim Gremyachev Sep 04 '17 at 07:56