【问题标题】:What are the functions that can use with feature.getStyle() function in Openlayers 3?Openlayers 3 中的 feature.getStyle() 函数可以使用哪些函数?
【发布时间】:2016-12-13 07:31:01
【问题描述】:

我已使用以下代码读取 KML 文件。如何获取从 kml 文件中提取的样式。我是否正确使用了 getStyle() 函数?

var parser = new ol.format.KML({extractStyles: true});  

var testfeat=parser.readFeatures(kmlAsString,{featureProjection:'EPSG:3857' });

for(i=0;i<testfeat.length;i++)
{
   console.log(testfeat[i].getStyle()); // What are the functions that use with getStyle()?
}

【问题讨论】:

    标签: kml openlayers-3


    【解决方案1】:

    OpenLayers 的ol.format.KML 读取 KML 文件中的样式定义并将它们存储在内部。将样式设置为特征时,格式对象使用样式函数执行此操作,即ol.FeatureStyleFunction,请参阅:http://openlayers.org/en/latest/apidoc/ol.html#.FeatureStyleFunction

    这里是这样做的,使用setStyle 方法:https://github.com/openlayers/ol3/blob/v3.20.0/src/ol/format/kml.js#L1852

    I 样式函数不能像普通的ol.style.Style 对象那样返回属性。它依赖于地图分辨率来动态计算可以更改的属性。

    总结:您无法使用ol.format.KML 访问从 KML 文件中读取的样式定义。

    【讨论】:

      猜你喜欢
      • 2017-11-20
      • 1970-01-01
      • 2021-08-20
      • 1970-01-01
      • 2015-06-05
      • 1970-01-01
      • 2016-08-24
      • 1970-01-01
      • 2021-10-28
      相关资源
      最近更新 更多