mapbox-gl-jsmapbox-glopenmaptiles

How to get X and Y indexes of the current tile in Mapbox GL JS?


I'm using Mapbox GL JS to display a map using my own tile-server (which just serves openmaptiles pbf files in a Z/X/Y directory structure).

The loading of tiles is done automatically, based on the current center coordinates.

I want to pre-load the surrounding tiles for an offline solution. I know how to get the current zoom-level with map.getZoom()

How can I get the X and Y indexes of the current tile URL ?


Solution

  • I suggest framing the problem in terms of geographic coordinates: