Map math appendix¶
This page collects the implementation-level equations used by map rendering.
Label collision placement¶
Each label is projected to pixel coordinates at zoom \(z\), converted to an axis-aligned bounding box, then checked against boxes already placed.
Web-Mercator pixel projection:
Bounding box (icon width \(w\), height \(h\), anchor \((a_x,a_y)\)):
AABB overlap test:
In plain terms, we convert each label to a screen rectangle and place it only if that rectangle does not overlap rectangles already placed. This avoids labels drawing on top of each other.
Fit-bounds zoom computation¶
Given current zoom \(z\), current visible span, and target bounds span:
with Mercator latitude:
Final zoom:
In plain terms, we compute how much we must zoom out so the target bounds fit both horizontally and vertically, then choose the stricter one and clamp it to allowed min/max zoom levels.
Viewport padding before fitting¶
Before fitting, bounds are expanded by one eighth of their size on each side:
In plain terms, we add a 12.5% visual margin around the content so markers and route overlays are not glued to the map edges after auto-fit.