我有一个结构如下的 geojson 文件:
{
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"properties": {
"marker-color": "#4620dd",
"marker-size": "medium",
"marker-symbol": "park",
"name": "State Park"
},
"geometry": {
"type": "Point",
"coordinates": [-76.95266723632812,
39.07974903895123
]
}
}]
}
我可以在 openlayers map 中从此 geojson 创建矢量图层,但无法利用样式属性。我应该使用自定义样式函数来执行此操作吗?
最佳答案
是的,当然:
var vectorLayer = new ol.layer.Vector({
source: vectorSource,
style: function (feature, resolution) {
console.log(feature.getProperties()); // <== all geojson properties
return [new ol.style.Style({
image: new ol.style.Circle({
radius: 10,
fill: new ol.style.Fill({ color: feature.get('marker-color') })
})
})];
}
});
关于javascript - 是否可以从 GeoJson 中提取 openlayers javascript map 的样式信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42376516/