我有一个带有简单 GeoJSON 文件层(几个城镇)的地图,每个城镇都有一个“bbox”属性。它是一个点或一条线串。 GeoJSON 文件如下所示:
{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"name":"Rome","bbox":"12.486137, 41.891775, 12.487089, 41.891481"},"geometry":{"type":"Point","coordinates":[12.486137,41.891775]}}]}
当我使用通常的方式添加 GeoJSON 文件作为矢量图层时,一切都很好。但是如何从文件的“bbox”属性添加几何图形作为不同的图层?我应该添加一些括号和逗号吗?
我尝试了类似的方法,但它没有添加任何东西:
const styleBBox = new Style({
fill: new Fill(),
stroke: new Stroke({
color: '#000',
width: 1,
})
});
const BBox = new VectorLayer({
source: new VectorSource(),
style: function (feature) {
const coordinates = feature.get('bbox');
styleBBox.getGeometry().getCoordinates(coordinates);
return styleBBox;
},
});