Skip to main content

Module map_math

Module map_math 

Source
Expand description

Web Mercator projection + slippy tile math.

Tiles follow the OSM/Google/Bing convention: tile (0,0) at zoom 0 covers the whole world. At zoom z, the world is a 2^z x 2^z grid of 256x256 tiles.

Structs§

LatLng
TileId
Viewport

Constants§

MAX_ZOOM
MIN_ZOOM
TILE_SIZE

Functions§

fit_bounds
Compute the bounding box of a set of pins, then return a (center, zoom) that fits all pins with a small padding margin. Returns a default map center + MIN_ZOOM if pins is empty.
lat_to_tile_y
Latitude to fractional tile Y at zoom z (Web Mercator). Clamps lat to [-85.0511, 85.0511] — the Mercator cutoff.
latlng_to_viewport_pixel
Project a LatLng to a pixel (x, y) within the viewport. Origin (0,0) is the top-left of the viewport.
lng_to_tile_x
Longitude to fractional tile X at zoom z.
tile_x_to_lng
tile_y_to_lat
viewport_center_tile
Given a viewport, return the (tile_x, tile_y) at the viewport’s center in fractional tile coordinates.
viewport_pixel_to_latlng
Inverse: a viewport pixel -> LatLng.
visible_tiles
Return every tile that intersects the viewport.