【发布时间】:2021-11-10 17:03:51
【问题描述】:
我开始使用矢量图层来在 OpenLayers 中呈现 SQL 空间数据。渲染this 示例时(请参阅Json),一切正常。见以下代码:
//creates source to get json data from
let vSource = new VectorSource({
url: '/assets/germany.json',
format: new GeoJSON()
});
//set focus of the camera on this source
vSource.on('addfeature', () => {
this.map.getView().fit(vSource.getExtent());
console.log(this.map.getView().getCenter());
});
//add source to layer and afterwards load it into map
let vLayer = new VectorLayer({
source: vSource,
visible: true
});
//layer styling
vLayer.setStyle(new Style({
stroke: new Stroke({
color: '#FF5733',
width: 8
})
}));
this.map.addLayer(vLayer);
地图实例化如下:
this.map = new Map({
view: new View({
center: [10, 10],
zoom: 3,
}),
layers: [],
target: 'ol-map'
});
但是当我想渲染this json 文件时,我面对的是一张空白地图。焦点不会设置,甚至不会出现错误。我假设这一切都与边界有关? 如果有“默认”之类的东西,如何渲染作为我们外部默认边界的多边形坐标?
例如:
[12058.4521484375, 5345.98388671875],
[11408.95703125, 5345.98388671875]
通读API我可以推断extent选项可能是解决这个问题的关键?
最好的问候
OpenLayers 的新手
【问题讨论】:
-
y 坐标在 -90 到 +90 之间,x 坐标值在 -180 到 +180 之外可能表明您的多边形处于一个包裹的世界中。您需要
wrapX: false作为矢量源构造函数的选项才能看到它。如果 y 坐标超出该范围,则您有一个使用自定义投影的非标准 geojson。 -
所以
wrapX将是 json 数据的解决方案,其中只有 x 坐标超出边界(尝试并工作,谢谢!),但我该如何解决自定义投影?是否可以创建具有自定义坐标系的 VectorLayer(例如:minY:-inf、minX:-inf、maxY:+inf、maxX:+inf)? -
使用自定义投影坐标的 GeoJSON 应该包含一个 crs 条目,如 openlayers.org/en/latest/examples/modify-test.html 但有时它们不包含,您只需做出最佳猜测。
-
哦,好吧,我的 json 数据不是这样:/。你知道
Is there a possiblity to create a VectorLayer which has a custom coordinate system(for example: minY: -inf, minX:-inf, maxY:+inf, maxX:+inf)?的答案吗 -
这是可能的,例如,可能存在一个极投影,其中对极在所有方向上都是无限的。
标签: javascript openlayers geojson spatial