POI in OpenLayer 3

2019-08-18 02:27发布

If load points from KML file to vetor layer

var layerPOI = new ol.layer.Vector({
  source: new ol.source.KML({
    projection: projection,
    url: 'data/KML/mydata.kml'
  })
})

How can I do a complete listing of all loaded points (POIs) and loaded properties (from data/KML/mydata.kml)? I think, for example, into the table - in map view (display layer) I can is already

Thank you very much for answer

2条回答
The star\"
2楼-- · 2019-08-18 02:54

ol.source.KML has a method getFeatures() which gives you all features in your KML. Then you can use getProperties() or get() on the feature to read the properties.

查看更多
地球回转人心会变
3楼-- · 2019-08-18 02:57

(Partial) solution:

allPOIs = layerPOI.getSource().getFeatures();
// or if define a source separatly
// allPOIs = sourcePOI.getFeatures(); 
onePOI = allPOIs[0]; // first element in Array
propertiesOfOnePOI = onePOI.getKeys();

propertiesOfOnePOI.forEach(function (elementName, elementIndex){
    console.log( "element index: " + elementIndex + " | element name: " + elementName + " | element value: " + onePOI.get(elementName) );
}); 

But the element GEOMTERY returns Object. I try to getting additional information about point yet but I can not - Also more tags from KML file - For example, point style - how to determine the displayed icon?

Please still help ;)

查看更多
登录 后发表回答