Javascript 如何获取当前可见的瓷砖坐标?

Javascript 如何获取当前可见的瓷砖坐标?,javascript,maps,leaflet,Javascript,Maps,Leaflet,我需要获取当前可见分幅的x/y(其中x和y是ployate.js用来查询与分幅的x/y/z对应的url的坐标) 我想找到一个不启用unloadInvisibleTiles选项的解决方案 唯一的方法是通过getPixelBounds() 编辑: 添加了一个示例。据我所知,您必须通过getPixelBounds() 您可以使用以下代码枚举它们:xTile和yTile是您要查找的 // get bounds, zoom and tileSize var bounds = map.get

我需要获取当前可见分幅的
x/y
(其中x和y是ployate.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);
    }
}
//获取边界、缩放和平铺
var bounds=map.getPixelBounds();
var zoom=map.getZoom();
var tileSize=256;
//获取西北点和东南点
var nwTilePoint=新的L.Point(数学地板(bounds.min.x/tileSize),
数学地板(bounds.min.y/tileSize));
var seTilePoint=新的L.点(数学地板(bounds.max.x/tileSize),
数学地板(边界最大y/tileSize));
//获取此缩放级别中的最大平铺数
var max=地图选项crs比例(缩放)/瓷砖大小;
//枚举可见分幅

对于(var x=nwTilePoint.x;x)非常好的代码!谢谢!但是有一种情况。将其设为Math.abs(x%max)和Math.abs(y%max),否则有时会出现负的平铺坐标。实际上,在墨卡托投影中,x和y总是正的:是的,您是对的,但getPixelBounds()如果在地图开始重复时向左滚动地图,则返回负x。方法
getPixelBounds
似乎不在上一版本中(
version:“0.37.0”
)…因此此答案已被弃用。有什么解决方法吗?包括什么?传单的当前版本为1.0.3,该方法仍然存在:。