OL3:从 KML 中提取 'extended data'

OL3: extracting 'extended data' from KML

我创建了一个包含一些自定义属性的 KML 文件,例如 'id' 和 'room_id'。

这些属性存在于 KML 文件的 'extended data' 部分,这里是文件:

<?xml version="1.0" encoding="utf-8" ?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document id="root_doc">
<Schema name="map" id="map">
    <SimpleField name="id" type="int"></SimpleField>
    <SimpleField name="room_id" type="string"></SimpleField>
</Schema>
<Folder><name>map</name>
  <Placemark>
    <name>room1</name>
    <Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
    <ExtendedData><SchemaData schemaUrl="#map">
        <SimpleData name="id">2</SimpleData>
        <SimpleData name="room_id">1</SimpleData>
    </SchemaData></ExtendedData>
      <Polygon><altitudeMode>relativeToGround</altitudeMode><outerBoundaryIs><LinearRing><altitudeMode>relativeToGround</altitudeMode> <coordinates>-0.000010931306469,0.000006764422322 -0.000004193941839,0.000006764422322 -0.000004166884149,0.00000037880765 -0.000010985421848,0.00000043292302 -0.000010931306469,0.000006764422322</coordinates></LinearRing></outerBoundaryIs></Polygon>
  </Placemark>
</Folder>
</Document></kml>

我正在尝试使用 OL3 访问这些属性,但无法弄清楚。这是我用来访问标准 KML 属性 'name' 和 'description':

的代码
vector.getSource().forEachFeature(function (feature) {

     var desc = feature.getProperties()['description'];
     console.log(desc);

     var name = feature.getProperties()['name'];
     console.log(name);

});

如何使用 OL3 访问 KML 文件的 'extended data' 属性?

谢谢!

很简单:

 var properties = feature.getProperties();
 console.log(properties['id']);
 console.log(properties['room_id']);