我需要获取 x/y
(其中 x 和 y 是 leaflet.js 用于查询相应 url 与 x/y/z
的坐标)坐标当前可见的图 block 。
我想在不启用 unloadInvisibleTiles
选项的情况下找到解决方案。
唯一的方法是通过 getPixelBounds()
吗?
编辑: 添加了一个示例 gist .
最佳答案
据我所知,你必须通过 getPixelBounds()
您可以使用以下代码枚举它们:xTile 和 yTile 就是您要查找的内容
// get bounds, zoom and tileSize
var bounds = map.getPixelBounds();
var zoom = map.getZoom();
var tileSize = 256;
// get NorthWest and SouthEast points
var nwTilePoint = new L.Point(Math.floor(bounds.min.x / tileSize),
Math.floor(bounds.min.y / tileSize));
var seTilePoint = new L.Point(Math.floor(bounds.max.x / tileSize),
Math.floor(bounds.max.y / tileSize));
// get max number of tiles in this zoom level
var max = map.options.crs.scale(zoom) / tileSize;
// enumerate visible tiles
for (var x = nwTilePoint.x; x <= seTilePoint.x; x++) {
for (var y = nwTilePoint.y; y <= seTilePoint.y; y++) {
var xTile = (x + max) % max;
var yTile = (y + max) % max;
console.log('tile ' + xTile + ' ' + yTile);
}
}
关于javascript - 如何获取当前可见的图 block 坐标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24895166/