使用 Leaflet 在 Z 缩放级别获取 XY 平铺坐标

Get XY Tile Coordinate at Z Zoom Level with Leaflet

我已经想出如何通过使用 createTile 函数扩展 Leaflet 来获取 XYZ 坐标。

但我想知道的是如何访问 XY 磁贴 name/coordinate 以获得围绕我的 GPS 坐标的固定 Z 缩放级别,即使我没有放大。

为什么?我正在开发 P2P/decentralized 版本的 Uber,XY 坐标是一个很好的 common/shared 位置索引,供用户 lookup/subscribe/query 参考。例如,X 英里半径内的每个人都将知道相同的 XY 坐标名称,并将其用作确定性键来找到彼此。

这个项目将"Convert lon, lat to screen pixel x, y from 0, 0 origin, at a certain zoom level."https://github.com/mapbox/sphericalmercator

更新:

function lng2tile(lon,z) { return (Math.floor((lon+180)/360*Math.pow(2,z))) }
function lat2tile(lat,z)  { return (Math.floor((1-Math.log(Math.tan(lat*Math.PI/180) + 1/Math.cos(lat*Math.PI/180))/Math.PI)/2 *Math.pow(2,z))) }

或者试试这个:

var row = Math.floor((location.lng + 180) / (360 / Math.pow(2, zoomLevel)));
var col = Math.floor((90 + (location.lat * -1)) / (180 / Math.pow(2, (zoomLevel - 1))));