是否可以从GeoJson中提取openlayers javascript映射的样式信息?
我有一个geojson文件,其结构如下:是否可以从GeoJson中提取openlayers javascript映射的样式信息?,javascript,openlayers,geojson,Javascript,Openlayers,Geojson,我有一个geojson文件,其结构如下: { "type": "FeatureCollection", "features": [{ "type": "Feature", "properties": { "marker-color": "#4620dd", "marker-size": "medium", "marker-symbol": "park", "name": "State Park" },
{
"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') })
})
})];
}
});
var vectorLayer=new ol.layer.Vector({
来源:矢量源,
样式:功能(特征、分辨率){
console.log(feature.getProperties());//是,当然:
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') })
})
})];
}
});
var vectorLayer=new ol.layer.Vector({
来源:矢量源,
样式:功能(特征、分辨率){
console.log(feature.getProperties());//是的,应该使用ol.style来设置图层样式。是的,应该使用ol.style来设置图层样式。