CHAPTER 06
Pixel and world coordinates
World pixels and screen pixels: the coordinate system behind every marker, overlay, and mouse-to-lat-lon conversion at any zoom level.
Tiles tell you which 256×256 PNG to load. But once the tiles are on screen, you need a second coordinate system to answer questions like: where exactly does this lat/lon fall in the rendered canvas? Which lat/lon does the user's mouse point at? How do I draw a line from point A to point B in pixel space?
That's where pixel coordinates come in — a global pixel grid that covers the entire world at a given zoom level, into which both geographic coordinates and screen positions can be mapped.
Lat/Lon → World pixel coordinates
World pixel X
185,219
World pixel Y
106,866
Tile
723/417
Pixel in tile
131, 114
World pixel coordinates
The world pixel coordinate system is an extension of the tile system. At zoom z:
- The world is
256 × 2^zpixels wide and tall - Tile
(x, y)occupies the 256×256 pixel block starting at(x*256, y*256) - Pixel coordinates are continuous — a marker can sit at any pixel, not just tile boundaries
At zoom level z, the entire world is pixels wide and tall. So:
The second equation is just the Mercator y, normalized to the range [0, worldSize]. The 1/2 - part shifts the range so that the equator maps to the vertical midpoint.
From pixel back to lat/lon
Worked example
Q: What's the pixel coordinate of (0, 0) — the equator and prime meridian — at zoom 4?
Dead center, as expected.
Continue reading "Pixel and world coordinates"
You've reached the end of the free preview. Unlock all 22 paid chapters, including distance math, bearings, polygons, spatial indexing, and 3D map rendering — plus a downloadable PDF and the companion code repo.
- All 22 paid chapters with worked examples
- Downloadable PDF for offline reading
- Companion GitHub repo (JavaScript + Python)
- Free updates for life
Multiple payment options including Wise, PayPal, and bank transfer.
Related chapters
- Web Mercator and tile math — the underlying tile addressing
- How maps render — tiles, vectors, and the GPU pipeline — pixels in the GPU pipeline
- Camera and perspective math — when 2D pixels become 3D camera projection