Skip to main content

Module projection

Module projection 

Source
Expand description

Web Mercator projection — the one every slippy-map tile source uses.

At zoom level z the world is 2^z × 2^z tiles, each 256 × 256 pixels by convention. lon ∈ (-180, 180] maps linearly to x ∈ [0, 2^z); lat ∈ (-85.0511, 85.0511) maps non-linearly to y ∈ [0, 2^z) via the Mercator formula. We work in tile-space floating-point coordinates (e.g. tile_x = 4.7) and convert to / from integer tile indices + pixel offsets at the boundary.

References: https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames

Constants§

MAX_LATITUDE
Maximum latitude representable in Web Mercator. Beyond this the projection blows up to infinity (the math is atanh(sin(lat))).
TILE_SIZE_DEFAULT
Tile edge length in pixels. Every common slippy-map source uses 256. Vector / retina sources may emit 512; we keep that as a per-source option (Tile::size in the Slint model) rather than a global const.

Functions§

lonlat_to_tile
Convert a geographic coordinate + zoom to fractional tile-space.
tile_to_lonlat
Inverse of lonlat_to_tile.