CONCEPT Cited by 1 source
Vector tiles¶
Definition¶
A vector tile is a bundle of vector geometry (points,
lines, polygons) covering a single cell of a zoomed map
grid, serialised as a compact binary blob — commonly the
Mapbox Vector Tile (MVT) format encoded as Protocol
Buffers (.pbf). Each tile is identified by a
(z, x, y) triple: z is the zoom level (doubling the
number of tiles per side at every step), x and y are
the column and row of the tile within the zoomed grid.
Vector tiles are the dominant client-rendering alternative
to raster tiles (pre-rendered PNGs). The geometry is
sent raw; the client (e.g. Leaflet's
VectorGrid) draws and styles it. This decouples data
from presentation — one tile can be restyled
client-side (colour, thickness, labels) without another
server round-trip.
Why they replaced raster tiles at scale¶
- Tile-grid loading is bounded by viewport. Only the tiles visible on screen are fetched; panning loads new tiles, old tiles fall out of cache. This is what makes a "browser map fast and responsive" over large datasets — "adding extra layers with e.g. over 100,000 polygons on top of it would slow down map navigation a lot. Splitting the data into a grid of tiles and loading only the ones of the area you are currently looking at on your screen is what makes a browser map fast and responsive." (Source: sources/2021-12-01-zalando-maps-with-postgresql-and-postgis.)
- Zoom-dependent geometry generalisation is a first-class concern. At small zoom levels, rivers, streets and polygons should be coarser and styled differently; some features should drop out entirely for readability. With vector tiles this is a per-tile server-side decision (or a client-side filter over the bundled attributes); with raster tiles it requires a full pre-rendered tile set per zoom.
- Multiple thematic attributes ship with the geometry. "The vector tile format must not consist solely of the geometry. Multiple thematic attributes can be included making it possible to change the style on the fly without sending another request to the database." (Source: same.)
Database-side tile production¶
systems/postgis exposes an API designed for vector tiles:
ST_TileEnvelope(z, x, y)— get the Web-Mercator envelope of a tile.ST_AsMVTGeom(geom, envelope)— clip/reproject a geometry into MVT tile coordinate space.ST_AsMVT(row_set, layer_name)— encode a row set as an MVT PBF.
With these, a thin HTTP server like systems/pg-tileserv is enough to turn a spatial database into a tile server — the pattern patterns/database-as-tile-server-middleware-replacement canonicalises.
SQL-function tile layers: dynamic derived tiles¶
A tile doesn't have to come from a table — it can come
from a PL/SQL function taking the (z, x, y) tile
coordinates as input. This opens up dynamic tile
computation: the function can build a hex grid over the
tile envelope, spatially join it against another
dataset, aggregate per cell, and encode the result as
MVT — returning a heatmap that adapts to zoom level
because the hex size scales with the tile envelope size.
"Because this is all based on database queries triggered from user interactions with the map, such a heatmap can be dynamic and change while zooming in and out. As the vector tile grid gets smaller on a larger scale the heatmap becomes more fine-grained." (Source: sources/2021-12-01-zalando-maps-with-postgresql-and-postgis.)
Caveats with the naïve aggregation: a hex-to-polygon any-intersection join double-counts along boundaries; a more precise implementation joins the hex grid against centroid-derived points so each source polygon lands in exactly one hex.
Wire shape¶
- URL template:
{base}/{layer}/{z}/{x}/{y}.pbf - Body: Protocol Buffer blob (MVT encoding)
- Client library: Leaflet's
VectorGrid(or MapLibre GL, Mapbox GL, OpenLayers, etc.)
Seen in¶
- sources/2021-12-01-zalando-maps-with-postgresql-and-postgis
— canonical first instance. Zalando's Postgres Operator
team shows both a table-layer tile (NUTS
administrative-boundary polygons served from a
geo.boundaries_europetable) and a function-layer tile (a dynamicpopulation_hexagons(z, x, y, step)PL/SQL function overST_HexagonGrid+ Eurostat 1 km² grid), with the zoom-dependent hex-size formula(ST_XMax − ST_XMin) / pow(2, step)as the heatmap granularity knob. Connects to the broader architectural pattern patterns/database-as-tile-server-middleware-replacement: PostGIS replaces what used to be a bespoke tile-pipeline middleware service.
Related¶
- systems/postgis — the tile-producing database extension.
- systems/pg-tileserv — the HTTP shim serving tiles over the wire.
- systems/leaflet — the client library rendering tiles.
- systems/openstreetmap — the typical basemap tile source.
- patterns/database-as-tile-server-middleware-replacement — the architectural pattern vector tiles enable.