forEachTileCoord() 返回错误的 y 坐标
forEachTileCoord() returning wrong y coordinate
我正在使用此功能获取我视图中的所有坐标,以及我当前的缩放比例。我是这样做的:
...
this.map.getLayers().forEach((layer) => {
if (layer.get('name') === 'randomLayer') {
let extent = this.map.getView().calculateExtent(this.map.getSize());
let zoom = this.map.getView().getZoom();
layer.getSource().tileGrid.forEachTileCoord(extent, i, tileCoord => {
console.log(tileCoord);
});
}
});
这是在我的视图中加载图块的方式 (z/x/y),缩放比例为 12:
12/1474/2376 12/1475/2376 12/1476/2376
12/1474/2377 12/1475/2377 12/1476/2377
12/1474/2378 12/1475/2378 12/1476/2378
这是函数返回的内容:
12/1474/2377 12/1475/2377 12/1476/2377
12/1474/2378 12/1475/2378 12/1476/2378
12/1474/2379 12/1475/2379 12/1476/2379
不返回位于屏幕顶部的第一行坐标,返回甚至不在视图中的底行 (2379)。这是故意的吗?也许我以错误的方式划定了范围?
我也尝试过获取 this.map.getView().calculateExtent();
的范围,但同样的事情发生了。
作为解决方法,我可以执行以下操作:
...
layer.getSource().tileGrid.forEachTileCoord(extent, i, tileCoord => {
let z = Math.abs(tileCoord[2]) - 1;
});
但这似乎不太正确。
正如@Mike 在对我的问题的评论中提到的,我在问题末尾建议的解决方法是在 OpenLayers 版本 6 之前通常用于获取图块坐标的方法。较新的版本无需执行此操作即可获得相同的结果。
@迈克:
If you are using OpenLayers 5 or earlier and your y values are
negative that is
expected. But OpenLayers 6 uses the same
system as XYZ.
Until version 6 the workaround was the normal procedure as OpenLayers
grids were numbered upwards while XYZ source were numbered downwards.
It is expained in the upgrade notes
under "New
internal tile coordinates".
我正在使用此功能获取我视图中的所有坐标,以及我当前的缩放比例。我是这样做的:
...
this.map.getLayers().forEach((layer) => {
if (layer.get('name') === 'randomLayer') {
let extent = this.map.getView().calculateExtent(this.map.getSize());
let zoom = this.map.getView().getZoom();
layer.getSource().tileGrid.forEachTileCoord(extent, i, tileCoord => {
console.log(tileCoord);
});
}
});
这是在我的视图中加载图块的方式 (z/x/y),缩放比例为 12:
12/1474/2376 12/1475/2376 12/1476/2376
12/1474/2377 12/1475/2377 12/1476/2377
12/1474/2378 12/1475/2378 12/1476/2378
这是函数返回的内容:
12/1474/2377 12/1475/2377 12/1476/2377
12/1474/2378 12/1475/2378 12/1476/2378
12/1474/2379 12/1475/2379 12/1476/2379
不返回位于屏幕顶部的第一行坐标,返回甚至不在视图中的底行 (2379)。这是故意的吗?也许我以错误的方式划定了范围?
我也尝试过获取 this.map.getView().calculateExtent();
的范围,但同样的事情发生了。
作为解决方法,我可以执行以下操作:
...
layer.getSource().tileGrid.forEachTileCoord(extent, i, tileCoord => {
let z = Math.abs(tileCoord[2]) - 1;
});
但这似乎不太正确。
正如@Mike 在对我的问题的评论中提到的,我在问题末尾建议的解决方法是在 OpenLayers 版本 6 之前通常用于获取图块坐标的方法。较新的版本无需执行此操作即可获得相同的结果。
@迈克:
If you are using OpenLayers 5 or earlier and your y values are negative that is expected. But OpenLayers 6 uses the same system as XYZ. Until version 6 the workaround was the normal procedure as OpenLayers grids were numbered upwards while XYZ source were numbered downwards. It is expained in the upgrade notes under "New internal tile coordinates".