如何获取瓦片的LngLat边界框?(如果可能,还要包括中心/宽度)
例如,给定任何一个瓦片“id”(例如6/33/24
),计算所需的坐标。我非常渴望得到答案,因此不在意答案是用哪种语言编写的。
上下文
瓦片“id”有3个部分:6/33/24
(z/x/y
)。
z
表示缩放级别(0-24),x/y
表示从左上角原点开始的瓦片编号。
当缩放级别为1时,整个地图被分为4个相等的瓦片(如图所示)。每次缩放(z
增加),每个瓦片都会分成4个相等的瓦片(例如,缩放级别为2时=16个瓦片)。
_______________________
| | |
| 1/0/0 | 1/1/0 |
| | |
|__________|___________|
| | |
| 1/0/1 | 1/1/1 |
| | |
|__________|___________|
为什么?
我想实现客户端标记缓存,并将它们绑定到瓦片似乎是最合理的解决方案。我知道如何获取瓦片(循环遍历sourceCaches
中的瓦片或使用几个transform
方法),但我不知道如何从瓦片矩阵或瓦片ID中获取LngLat数据。
超级基本的JavaScript概念(供参考):
const markerCache = {
cache: {},
getMarkersForTile: function(key) { // tiles have unique keys
if (this.cache[key]) {
return Promise.resolve(this.cache[key]);
}
// ??? what should be in "getTileBounds"?
const bounds = getTileBounds(key);
return fetchMarkersForTile(bounds).then(markers => {
this.cache[key] = markers;
return markers;
});
}
};