【发布时间】:2019-03-22 19:30:43
【问题描述】:
我正在使用带有 Javascript 的 OpenLayers,并在地图上显示集群特征。我想根据其属性值之一更改群集内功能的图标。
var style1 = new ol.style.Icon(/** @type {olx.style.IconOptions} */ ({
anchor: [0.5, 66],anchorXUnits: 'fraction',anchorYUnits: 'pixels',
opacity: 0.85,src: 'https://img.icons8.com/flat_round/64/000000/home.png',scale: 0.3
}));
var style2 = new ol.style.Icon(/** @type {olx.style.IconOptions} */ ({
anchor: [0.5, 66],anchorXUnits: 'fraction',anchorYUnits: 'pixels',
opacity: 0.85,src: 'https://img.icons8.com/color/48/000000/summer.png',scale: 0.3
}));
function myStyleFunction(feature) {
let props = feature.getProperties();
if (props.id>50) {
console.log(props.id);
return new ol.style.Style({image: style1,stroke: new ol.style.Stroke({ color:"#fff", width:1 }) });
} else {
console.log(props.id);
return new ol.style.Style({image: style2,stroke: new ol.style.Stroke({ color:"#fff", width:1 }) });
}
};
在上面的代码中,我想访问集群中某个功能的属性“id”,并根据“id”值设置其图标。但是,我无法获取功能属性。
这是codepen。我会感谢任何人的帮助。
【问题讨论】:
标签: json mapping openlayers openlayers-3