使用geoxml3显示多边形kml文件

时间:2013-03-12 18:22:19

标签: javascript google-maps-api-3 xml-parsing kml geospatial

我正在使用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);
    }

followinh是多边形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>

1 个答案:

答案 0 :(得分:2)

不要使用geoxml3的主干版本它很旧并且只支持标记。 polyskmz分支都支持多边形,折线和标记。如果您不需要zip压缩(kmz文件支持),请使用polys分支。如果您需要更多符合标准的KML支持,kmz分支更好地支持所记录的标准,但未针对非kmz文件进行良好测试。

(来自geoxml3 project page

<强>记录

trunk - (old, not currently maintained) original version
network_link branch - (old, not currently maintained) development branch for network link functionality, not well tested
polys branch - development branch for polylines, polygons, current active development branch. Supports polylines, polygons, markers and groundoverlays
kmz 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>的{​​{1}}属性,因此多边形的边界没有宽度(因此您无法看到它们)。 kmz分支具有更好的默认值集。如果我添加宽度,你可以看到它们:

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