gpt4 book ai didi

javascript - GeoXML3 访问 KML 属性数据

转载 作者:行者123 更新时间:2023-12-03 04:54:02 27 4
gpt4 key购买 nike

我的 KML 文件具有以下格式:

<Placemark>
<Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
<ExtendedData><SchemaData schemaUrl="#seb">
<SimpleData name="PR0">CORS</SimpleData>
<SimpleData name="PR1">BRB</SimpleData>
<SimpleData name="PR2">F15</SimpleData>
</SchemaData></ExtendedData>
<MultiGeometry><Polygon><altitudeMode>clampToGround</altitudeMode><outerBoundaryIs><LinearRing><altitudeMode>clampToGround</altitudeMode><coordinates>71.0035714700001,38.4757616580001 71.0567352510001,38.398144523 71.1035044220001,38.422803406000138.4764993150001 71.0035714700001,38.4757616580001</coordinates></LinearRing></outerBoundaryIs></Polygon></MultiGeometry>

我希望能够从 kml 访问扩展数据字段,我将使用它来进一步处理和索引多边形以供以后使用和搜索。

正如这篇文章所述,可以从 placemark.vars.val 访问变量,但由于 vars 未定义,我无法获取该变量。

Load kml extendeddata into variable with Geoxml3

最佳答案

目前geoxml3的kmz分支处理ExtendedData采用 KML Reference 中定义的格式

如果您将 KML 修改为该格式( <Data> 而不是 <SimpleData><value> 围绕值的标签),它将按原样工作。

<Placemark>
<Style>
<LineStyle><color>ff0000ff</color><width>2</width></LineStyle>
<PolyStyle><fill>0</fill></PolyStyle>
<BalloonStyle>
<text>
<![CDATA[$[name]<br>PR0: $[PR0]<br>PR1: $[PR1]<br>PR2: $[PR2]]]>
</text>
</BalloonStyle>
</Style>
<ExtendedData>
<SchemaData schemaUrl="#seb">
<Data name="PR0">
<value>CORS</value>
</Data>
<Data name="PR1">
<value>BRB</value>
</Data>
<Data name="PR2">
<value>F15</value>
</Data></SchemaData>
</ExtendedData>
<MultiGeometry>
<Polygon>
<altitudeMode>clampToGround</altitudeMode>
<outerBoundaryIs><LinearRing>
<altitudeMode>clampToGround</altitudeMode>
<coordinates>71.0035714700001,38.4757616580001 71.0567352510001,38.398144523 71.1035044220001,38.422803406000138.4764993150001 71.0035714700001,38.4757616580001
</coordinates>
</LinearRing></outerBoundaryIs>
</Polygon>
</MultiGeometry>
</Placemark>

proof of concept fiddle

另一个选项是修改 geoxml3支持<SimpleData>以您的格式标记(它是开源的)。

代码片段:

var geocoder;
var map;

function initialize() {
var map = new google.maps.Map(
document.getElementById("map_canvas"), {
center: new google.maps.LatLng(37.4419, -122.1419),
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var geoXml = new geoXML3.parser({
map: map,
singleInfoWindow: true
});
geoXml.parseKmlString(kmlStr);
}
google.maps.event.addDomListener(window, "load", initialize);
var kmlStr = '<Placemark><Style><LineStyle><color>ff0000ff</color><width>2</width></LineStyle><PolyStyle><fill>0</fill></PolyStyle><BalloonStyle><text><![CDATA[$[name]<br>PR0: $[PR0]<br>PR1: $[PR1]<br>PR2: $[PR2]]]></text></BalloonStyle></Style><ExtendedData><SchemaData schemaUrl="#seb"><Data name="PR0"><value>CORS</value></Data><Data name="PR1"><value>BRB</value></Data><Data name="PR2"><value>F15</value></Data></SchemaData></ExtendedData><MultiGeometry><Polygon><altitudeMode>clampToGround</altitudeMode><outerBoundaryIs><LinearRing><altitudeMode>clampToGround</altitudeMode><coordinates>71.0035714700001,38.4757616580001 71.0567352510001,38.398144523 71.1035044220001,38.422803406000138.4764993150001 71.0035714700001,38.4757616580001</coordinates></LinearRing></outerBoundaryIs></Polygon></MultiGeometry></Placemark>';
html,
body,
#map_canvas {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}
<script src="https://maps.googleapis.com/maps/api/js"></script>
<script src="https://cdn.rawgit.com/geocodezip/geoxml3/master/kmz/geoxml3.js"></script>
<div id="map_canvas"></div>

关于javascript - GeoXML3 访问 KML 属性数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42516114/

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