javascript - 如何获取当前可见的图 block 坐标?

标签 javascript maps leaflet

我需要获取 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/

相关文章:

web-applications - 在 Blackberry 10 上从浏览器打开 native map 应用程序

javascript - Leaflet图层控件不显示图层

javascript - D3 - 删除填充以使图形填充页面

javascript - 在 span 中将按钮视为链接

r - 等值线世界地图

ios - 使用 MapKit 计算 3 个或更多地址之间的距离

javascript - 在 React 中调用 onClick 函数

javascript - 将 React 组件转换为 Typescript?

javascript - 传单:检测标记何时超出视野

javascript - 如何更新 Leaflet 弹出窗口中的内容?