【发布时间】:2019-05-06 23:23:40
【问题描述】:
我正在研究 openlayers 5.x 的 GPX 源代码示例,地址为 https://openlayers.org/en/latest/examples/gpx.html
我能够成功加载我的 GPX 文件并将其显示在地图上,但我无法获得它的范围以了解最小/最大纬度和经度以使其在地图上动态适应。
这是我的代码(与示例相同):
var GpxVector = new VectorLayer({
source: new VectorSource({
url: 'https://host.domain.com/filename.gpx',
format: new GPX(),
}),
style: function(feature) {
return GpxStyle[feature.getGeometry().getType()];
}
});
map.addLayer(GpxVector);
GPX 文件显示正确,但我无法调整地图大小以对其进行缩放。我试过了:
console.log(GpxVector.getSource().getFeatures());
没有提供解析的特征:
length: 0
__proto__: Array(0)
请注意,来源在那里,并在地图上正确显示:
console.log(GpxVector.getSource());
给予:
c {disposed_: false, pendingRemovals_: {…}, dispatching_: {…}, listeners_: {…}, revision_: 0, …}
但没有范围:
console.log(GpxVector.getSource().getExtent());
给予:
[Infinity, Infinity, -Infinity, -Infinity]
VectorLayer 也没有范围:
console.log(GpxVector.getExtent());
给予:
undefined
谁能帮助我并告诉我如何访问 GPX 文件的范围或至少它的点,以便我自己计算它?
任何帮助将不胜感激!
【问题讨论】: