我有一个像这样结构的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地图中从此geojson创建矢量图层,但无法使用样式属性。我应该使用自定义样式函数来执行此操作吗?
答案 0 :(得分:0)
是的,当然可以:
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') })
})
})];
}
});