Is it possible to get tiles LngLat bounding box? (and center/width if possible)
I.e given any tile "id" (e.g 6/33/24
), calculate wanted coordinates. I'm so desperate to get an answer that I don't even care in what language it's written.
Context
Tile "id" has 3 parts: 6/33/24
(z/x/y
).
z
being floored zoom (0-24) and x/y
tile number from left/top origin point.
When zoom is 1, whole map is divided into 4 equal tiles (shown in graphic). Every time zoom (z
) increases, each tile is subdivided into 4 equal tiles (e.g zoom 2 = 16 tiles).
_______________________
| | |
| 1/0/0 | 1/1/0 |
| | |
|__________|___________|
| | |
| 1/0/1 | 1/1/1 |
| | |
|__________|___________|
Why?
I want to implement client-side marker cache and binding them to tiles seems to be the most reasonable solution. I know how to get tiles (loop over sourceCaches
tiles or use few transform
methods) but I have no idea how to get LngLat data from tile matrices or tile IDs.
Super basic JavaScript concept of marker cache (for context):
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;
});
}
};