简体   繁体   中英

OL3: extracting 'extended data' from KML

i have created a KML file with some custom attributes such as 'id' and 'room_id'.

these attributes exist in the 'extended data' part of the KML file, here is the file:

<?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>

i am trying to access these attributes using OL3 but can't figure it out. here is the code i use to access the standard KML properties 'name' and 'description':

vector.getSource().forEachFeature(function (feature) {

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

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

});

how do i access the 'extended data' properties of a KML file with OL3?

thanks!

It's easy as:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM