是否可以从 GeoJson 中提取 openlayers javascript 地图的样式信息?

Is it possible to extract style information from GeoJson for an openlayers javascript map?

我有一个结构如下的 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 创建矢量图层,但无法使用样式属性。我应该使用自定义样式函数来执行此操作吗?

是的,当然:

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') })
      })
    })];
  }
});

https://jsfiddle.net/jonataswalker/uvopawmg/