【发布时间】:2020-07-03 11:36:13
【问题描述】:
我对 openlayer geojson 有疑问。我正在尝试在地图中显示数据,但我没有尝试任何方法。
我需要更改哪些内容才能在地图上显示数据?
代码:
var map = new Map({
controls: defaultControls().extend([
new FullScreen()
]),
interactions: defaultInteractions().extend([
new DragRotateAndZoom()
]),
target: 'map',
view: new View({
center: [32.2128100772116, -7.92209407500733],
zoom: 5
}),
});
var vectorSource = new VectorSource({
features: (new GeoJSON()).readFeatures(this.geojsonObject)
});
var vectorLayer = new VectorLayer({
source: vectorSource,
visible: true
});
this.map.addLayer(vectorLayer);
geoJson 数据:
geojsonObject = {
'type': 'Feature',
'geometry': {
'type': 'MultiPolygon',
'coordinates': [
[[
[
33.3984375,
37.16031654673677
],
[
-11.25,
27.68352808378776
],
[
14.765625,
-10.833305983642491
],
[
48.515625,
5.61598581915534
],
[
58.00781249999999,
28.92163128242129
],
[
48.515625,
37.43997405227057
],
[
33.3984375,
37.16031654673677
]
]]
]
}
};
【问题讨论】:
-
在视图选项中指定
projection: 'EPSG:4326',(除非您需要不同的投影,在这种情况下您必须转换中心和特征几何)
标签: javascript openlayers openlayers-3 openlayers-6 angular-openlayers