0

我通过 geoxml3 解析一个 kml 文件,其中地标具有扩展数据字段。使用 kmz 分支中的 geoxml.js (尝试在此处遵循解决方案:Load kml extendeddata into variable with Geoxml3),我仍然发现 geoXmlDoc.gpolylines[0].title 有效,但 geoXmlDoc.gpolylines[0].vars.val未定义。地标格式供参考:

<Placemark>
  <name>Left to Right</name>
  <description><![CDATA[One Way: True<br>Crossing: false<br>Closure: True]]></description>
  <styleUrl>#line-000000-1200</styleUrl>
  <ExtendedData>
    <Data name="One Way">
      <value>True</value>
    </Data>
    <Data name="Crossing">
      <value>0</value>
    </Data>
    <Data name="Closure">
      <value>True</value>
    </Data>
  </ExtendedData>
  <LineString>
    <tessellate>1</tessellate>
    <coordinates>
      115.8350241,-31.928985,0
      115.8409465,-31.9267996,0
      115.8470404,-31.9297863,0
      115.8533061,-31.9272367,0
    </coordinates>
  </LineString>
</Placemark>
4

1 回答 1

1

我设法通过在 geoxml3 的 polyoptions 变量中添加最后一行(在第 1255 行)来做到这一点。

var polyOptions = geoXML3.combineOptions(parserOptions.polylineOptions, {
  map:           parserOptions.map,
  path:          path,
  strokeColor:   kmlStrokeColor.color,
  strokeWeight:  placemark.style.line.width,
  strokeOpacity: kmlStrokeColor.opacity,
  title:         placemark.name,
  visible:       placemark.visibility,
  polyDesc:      placemark.description,
  eData:         placemark.vars.val
});

然后我可以使用 geoXmlDoc.gpolylines[x].eData['Closure'] 访问该变量,其中“Closure”是我的扩展数据字段的名称。

于 2018-12-20T07:29:51.413 回答