我需要获取x/y
(其中x和y是leaflet.js用于查询x/y/z
瓷砖对应URL的坐标)当前可见瓷砖的坐标。
我想找到一个不启用unloadInvisibleTiles
选项的解决方案。
做到这一点的唯一方法是通过getPixelBounds()
吗?
编辑:添加了示例要点。
据我所知,你必须经历 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);
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句