gpt4 book ai didi

javascript - 使用geoxml3显示多边形kml文件

转载 作者:行者123 更新时间:2023-12-02 18:55:49 25 4
gpt4 key购买 nike

我正在使用 geoxml3 以便能够解析 kml 层的数量。现在,由于某种原因,它仅适用于点,不适用于多边形 kml 文件。以下是我正在使用的代码;

function displayKml() {
geo = new geoXML3.parser({
map: map,
zoom: false,
singleInfoWindow: true,
infoWindowOptions: { maxWidth: 100 },
processStyles: true,
markerOptions: { shadow: '' }
});
geo.parse("Resources/" + document.getElementById('<%= text2.ClientID %>').value);
}

以下是多边形 kml 文件的片段;

<?xml version="1.0" encoding="utf-8" ?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document><Folder><name>polygon_road</name>
<Schema name="polygon_road" id="polygon_road">
<SimpleField name="Name" type="string"></SimpleField>
<SimpleField name="Description" type="string"></SimpleField>
<SimpleField name="id" type="int"></SimpleField>
<SimpleField name="road_id" type="int"></SimpleField>
</Schema>
<Placemark>
<Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
<ExtendedData><SchemaData schemaUrl="#polygon_road">
<SimpleData name="id">1</SimpleData>
<SimpleData name="road_id">8</SimpleData>
</SchemaData></ExtendedData>
<Polygon><outerBoundaryIs><LinearRing><coordinates>14.517292705321212,35.901268542738997 14.517607913551563,35.901660659810574 14.517685853364705,35.901598006913375 14.517365353364706,35.901199306913377 14.517359591135264,35.901193253552186 14.517352901130216,35.901188244530104 14.508563647353409,35.895689849334943 14.508510612009246,35.895774626998687 14.517292705321212,35.901268542738997</coordinates></LinearRing></outerBoundaryIs></Polygon>
</Placemark>
<Placemark>
<Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
<ExtendedData><SchemaData schemaUrl="#polygon_road">
<SimpleData name="id">2</SimpleData>
<SimpleData name="road_id">10</SimpleData>
</SchemaData></ExtendedData>
<Polygon><outerBoundaryIs><LinearRing><coordinates>14.518412050213227,35.900771848093811 14.518465407563996,35.900687272724355 14.510931707563996,35.895934372724355 14.510878350213227,35.896018948093811 14.518412050213227,35.900771848093811</coordinates></LinearRing></outerBoundaryIs></Polygon>
</Placemark>
<Placemark>
<Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
<ExtendedData><SchemaData schemaUrl="#polygon_road">
<SimpleData name="id">3</SimpleData>
<SimpleData name="road_id">12</SimpleData>
</SchemaData></ExtendedData>
<Polygon><outerBoundaryIs><LinearRing><coordinates>14.515100381551473,35.90111915074295 14.515153218448528,35.901034249257044 14.509212818448528,35.89733734925705 14.509159981551473,35.897422250742956 14.515100381551473,35.90111915074295</coordinates></LinearRing></outerBoundaryIs></Polygon>
</Placemark>

最佳答案

不要使用 geoxml3 的 trunk 版本它相当旧并且只支持标记。两者都是polyskmz分支支持多边形、折线和标记。如果不需要 zip 压缩(kmz 文件支持),请使用 polys 分支。如果您需要 KML 中更多符合标准的支持,kmz 分支可以更好地支持记录的标准,但没有针对非 kmz 文件进行良好的测试。

(来自geoxml3 project page)

历史

trunk - (old, not currently maintained) original versionnetwork_link branch - (old, not currently maintained) development branch for network link functionality, not well testedpolys branch - development branch for polylines, polygons, current active development branch. Supports polylines, polygons, markers and groundoverlayskmz branch - development branch for kmz support, built off of the polys branch. Supports external styles, and is more standards compliant. See  issue 53  for details (http://code.google.com/p/geoxml3/issues/detail?id=53) and current status. 

您的 KML 缺少 <width> <LineStyle>的属性(property)所以多边形的边界没有宽度(所以你看不到它们)。 kmz 分支有一组更好的默认值。如果我添加宽度,您可以看到它们:

http://www.geocodezip.com/geoxml3_test/v3_geoxml3_kmltest_linktoB.html?filename=http://www.geocodezip.com/geoxml3_test/SO_IT_info_kmlA.xml

关于javascript - 使用geoxml3显示多边形kml文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15369102/

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