OL3:从KML提取“扩展数据" [英] OL3: extracting 'extended data' from KML

查看:95
本文介绍了OL3:从KML提取“扩展数据"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了带有某些自定义属性(例如"id"和"room_id")的KML文件.

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

这些属性存在于KML文件的扩展数据"部分中,这里是文件:

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>

我正在尝试使用OL3访问这些属性,但无法弄清楚.这是我用来访问标准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);

});

如何使用OL3访问KML文件的扩展数据"属性?

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

谢谢!

推荐答案

很简单:

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

这篇关于OL3:从KML提取“扩展数据"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆