gpt4 book ai didi

javascript - 如何将(kml的路径)替换为变量?我正在使用 geoxml3

转载 作者:行者123 更新时间:2023-12-03 03:34:00 25 4
gpt4 key购买 nike

如何将 myParser.parse('path/to/data.kml') 替换为包含这样的 kml 文件的变量。 https://github.com/geocodezip/geoxml3

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

像这样:

  var result = "<?xml version="1.0" encoding="UTF-8"?> ... </kml>'"
var myParser = new geoXML3.parser({map: map});
myParser.parse(result);

最佳答案

geoXML3 library包含parseKmlString function从字符串中解析 KML。

示例

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>

关于javascript - 如何将(kml的路径)替换为变量?我正在使用 geoxml3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45951638/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com