Skip to content

Tile pyramids and zoom levels

A map is pre-cut into fixed-size square tiles at each zoom level, four children under each parent, named by zoom, column and row. The scheme turns "show me this area" into a handful of cacheable, addressable fetches.

On this page

What it is

A tile pyramid is the same map drawn at a series of scales and cut into equal squares. At zoom 0 one tile covers the world, projected with Web Mercator so that the map is a square; latitudes beyond about 85.05 degrees are cut off to make that work. Zoom 1 has 2 by 2 tiles, zoom 2 has 4 by 4, and level n has 2^n by 2^n, which is 4^n tiles. The OpenStreetMap convention is a 256 by 256 pixel PNG per tile, served at a path of the form /zoom/x/y.png, with x counting east from the left edge and y counting south from the top. Google's Maps JavaScript API uses the same shape: a 256 pixel base tile at zoom 0, an origin at the northwest corner, and a pixel space that quadruples with each zoom level.

ZoomTiles acrossTiles in totalWhat a tile shows

0

1

1

The whole world

1

2

4

A quarter of the map, 180 by 85 degrees

2

4

16

A quarter of the map's width and height

12

4,096

16,777,216

About 0.088 degrees of longitude

16

65,536

about 4.3 billion

A few city blocks

18

262,144

about 68.7 billion

Streets; the usual deepest level for OpenStreetMap servers

22

4,194,304

about 17.6 trillion

Streets and blocks; the deepest level the Map Tiles API offers

Finding a tile from a coordinate. Project longitude and latitude into Mercator, scale the result onto a unit square with its origin at the top left, multiply by n = 2^zoom and take the floor. The integer parts are x and y; the fractional parts say where inside the tile the point lands. Run the same formula at zoom + 1 and n doubles, so the tile at (x, y) covers the same ground as the four tiles from 2x to 2x + 1 and 2y to 2y + 1 one level down. That parent-to-children rule is what makes the structure a pyramid: a coarser tile's area is the union of its four children's areas, so imagery for a level can be downsampled from the level below, or a child can be cut from its parent and scaled up when nothing sharper is stored.

pseudo
n = 2 ^ zoom
x = floor(n * (lon_deg + 180) / 360)
lat = radians(lat_deg)
y = floor(n * (1 - ln(tan(lat) + 1 / cos(lat)) / pi) / 2)
# the children of (zoom, x, y) are (zoom + 1, 2x..2x+1, 2y..2y+1)

Raster and vector tiles. A raster tile is a finished picture; the client decodes it and places it on screen. A vector tile carries the points, lines and polygons inside its square rather than pixels, and the picture is produced from that geometry when the tile is shown. The difference shows when a user zooms past the deepest level a tile set was built for, which Mapbox calls overzoom: a raster tile is stretched and turns blurry, while vector data can be drawn sharply at deeper levels, down to zoom 22 in Mapbox's tooling.

Some levels are missing in some places. Google's Map Tiles API offers zoom 0 to 22, and it provides a viewport request that returns, for rectangles overlapping the current view, the deepest zoom available there, so a client avoids asking for tiles that don't exist. The documented example is that most cities have imagery at zoom 22 but the ocean does not, since it would be featureless blue squares. A tile set is therefore a sparse pyramid: deep where there is something to see, shallow elsewhere.

When to use it

Reach for a tile pyramid when users pan and zoom over a surface far larger than any screen and most of it looks the same to all users: a street map, satellite imagery, a gigapixel photo, a large floor plan. The viewport at a given zoom covers a small, predictable number of tiles, so the client can compute the exact keys it needs and request those and nothing more, and fetch the ring just outside the view ahead of a pan.

The addressing scheme is what makes it a system design idea rather than a graphics one. A key like 14/8192/5461 names one square of the world at one scale, for all users and all time until the map data under it changes. That is the ideal shape for a CDN and for an on-device cache: long lifetimes, no per-user variation, and a version in the path when the data is republished. It also fits a blob store, since a tile is a small immutable object with a natural key.

When not to

Skip the pyramid when the image fits in one or two downloads at the largest size anyone will view it; a few scaled copies of one image, chosen by screen size, do the job with none of the key math (see Loading images). Skip it too for data that changes per user or per second, such as live vehicle positions or a friend's location. Those belong in a separate layer drawn over the tiles, the way a roadmap layer can sit on top of satellite imagery.

A tile pyramid answers "what does this area look like at this scale". It does not answer "what is near this point" or "which records fall in this box"; those are index questions, and a geohash, quadtree or R-tree is the right tool (see Geospatial indexing). A quadtree splits space into quarters much as a pyramid does, which makes the two easy to mix up, but a pyramid holds something to display and an index points at records.

And don't plan to render and store the full pyramid. Zoom 18 on its own has about 68.7 billion cells under the Web Mercator square, and the count quadruples again at each deeper level. Render deep levels on demand when a key is first asked for, keep the result, and set a per-region maximum zoom so the client stops asking where there is nothing to draw.

Compared

ApproachWhat the client receivesCostsWhen it is the right choice

Raster tile pyramid

A finished picture per z/x/y, commonly 256 px square

Tile count grows 4x per level in a full pyramid; a new style means re-rendering; blurry past the deepest level

Imagery and photos, weak clients, a fixed style; the simplest to serve and cache

Vector tile pyramid

Points, lines and polygons per tile rather than pixels

More client CPU and a renderer to ship; styling bugs land on the client

Restyling, rotation, labels in the user's language, smooth zoom between levels

One image, a few sizes

The whole picture at the nearest size

Download cost rises with image size; no partial loading

The image fits comfortably in one fetch at full size

Render the viewport per request

A custom picture for that exact view

Little is shared between users unless two viewports match exactly, so the origin does most of the work per request

Rare views, heavy per-user data, or print output where caching has little to offer

In a picture

missmissabsentsaveViewport at zoomzTile keys z/x/yDevice cacheCDN edgeTile storeRender on demand
The client turns its viewport into a short list of tile keys; a key can be answered by the device cache or a CDN edge before it reaches the store, and a tile not yet rendered is drawn on first demand and kept.

How to say it in an interview

The common mistake

Quiz

How many tiles does a Web Mercator pyramid hold at zoom level z?
A point falls in tile (x, y) at zoom z. Where does it fall at zoom z + 1?
A user zooms past the deepest level stored for a region. What happens?
Why do map tiles cache so well at a CDN compared with a per-user page?

Questions that use this

Related

Sources

  1. OpenStreetMap Wiki: Slippy map tilenames
  2. Google Maps JavaScript API: Map and tile coordinates
  3. Google Map Tiles API: 2D Tiles overview
  4. Mapbox Help glossary: overzoom
Sign in to report a mistake