Skill: serve-vector-tiles
Invoked by: mapping-visualization-engineer (primary). Routes the source schema/index questions to geospatial-data-engineer.
When to invoke: "how do I serve N features?"; "my map is slow / blank"; "vector tiles or GeoJSON?"; standing up any tile-serving layer.
Output: the format decision (GeoJSON vs MVT, by size/zoom) + a tile-server recipe + the MapLibre source/layer style to consume it, in EPSG:3857.
Procedure
- Make the format decision first. Count features and consider zoom interactivity:
- ≲ a few hundred static features, no per-zoom simplification → ship GeoJSON directly to MapLibre (simple, no server).
- thousands → millions, or zoom-dependent, or restyleable → vector tiles (MVT) from a tile server.
- true imagery / heavy cartography → raster tiles (XYZ/WMTS).
- Pick the tile server. PostGIS-backed dynamic tiles → pg_tileserv (zero-config, table-driven) or Martin (fast, Rust, config-driven); pre-generated tiles → Tegola or an MBTiles file served by a static tile host.
- Guarantee the projection. Web tiles are EPSG:3857. The server runs
ST_AsMVT(ST_AsMVTGeom(ST_Transform(geom, 3857), tile_bbox)) — reproject from the source SRID and clip to the tile. A mismatch = a blank or mis-placed map.
- Simplify per zoom.
ST_SimplifyPreserveTopology or tile-level ST_AsMVTGeom clipping keeps tiles small; don't ship z18 detail at z3.
- Wire the MapLibre source + layer. Add a
vector source pointing at the {z}/{x}/{y} tile URL, then a layer naming the source-layer, with zoom-dependent paint.
Worked example
User: "I have 400k parcels in PostGIS and a MapLibre map that hangs. How do I serve them?"
- 400k features → vector tiles, not GeoJSON. Use pg_tileserv over the indexed source table; reproject to 3857 in the tile query.
// MapLibre style fragment — consume the vector-tile source
{
"sources": {
"parcels": {
"type": "vector",
"tiles": ["https://tiles.example.com/public.parcel/{z}/{x}/{y}.pbf"],
"minzoom": 0, "maxzoom": 16
}
},
"layers": [
{
"id": "parcel-fill",
"type": "fill",
"source": "parcels",
"source-layer": "public.parcel",
"paint": {
"fill-opacity": ["interpolate", ["linear"], ["zoom"], 10, 0, 13, 0.4]
}
}
]
}
The pg_tileserv source query (run by the server) must ST_Transform(geom, 3857) and rely on the table's GiST index for the bbox filter — route that schema/index work to ../../agents/geospatial-data-engineer.md.
Guardrails
1---2name: serve-vector-tiles3description: "Serve geospatial data to a web map — decide GeoJSON vs vector tiles (MVT) by feature count and zoom, stand up a tile server (pg_tileserv / Martin / Tegola or MBTiles), and wire the MapLibre source + layer to consume it. Reach for this when a map is slow, you have many features, or you need a tile-serving architecture. Used by `mapping-visualization-engineer` (primary)."4metadata:5 source: https://skillmd.com/skills/mcorbett51090/serve-vector-tiles6---78# Skill: serve-vector-tiles910> **Invoked by:** `mapping-visualization-engineer` (primary). Routes the source schema/index questions to `geospatial-data-engineer`.11>12> **When to invoke:** "how do I serve N features?"; "my map is slow / blank"; "vector tiles or GeoJSON?"; standing up any tile-serving layer.13>14> **Output:** the format decision (GeoJSON vs MVT, by size/zoom) + a tile-server recipe + the MapLibre source/layer style to consume it, in EPSG:3857.1516## Procedure17181. **Make the format decision first.** Count features and consider zoom interactivity:19 - **≲ a few hundred static features, no per-zoom simplification** → ship **GeoJSON** directly to MapLibre (simple, no server).20 - **thousands → millions, or zoom-dependent, or restyleable** → **vector tiles (MVT)** from a tile server.21 - **true imagery / heavy cartography** → **raster tiles** (XYZ/WMTS).222. **Pick the tile server.** PostGIS-backed dynamic tiles → **pg_tileserv** (zero-config, table-driven) or **Martin** (fast, Rust, config-driven); pre-generated tiles → **Tegola** or an **MBTiles** file served by a static tile host.233. **Guarantee the projection.** Web tiles are **EPSG:3857**. The server runs `ST_AsMVT(ST_AsMVTGeom(ST_Transform(geom, 3857), tile_bbox))` — reproject from the source SRID and clip to the tile. A mismatch = a blank or mis-placed map.244. **Simplify per zoom.** `ST_SimplifyPreserveTopology` or tile-level `ST_AsMVTGeom` clipping keeps tiles small; don't ship z18 detail at z3.255. **Wire the MapLibre source + layer.** Add a `vector` source pointing at the `{z}/{x}/{y}` tile URL, then a layer naming the `source-layer`, with zoom-dependent paint.2627## Worked example2829> User: "I have 400k parcels in PostGIS and a MapLibre map that hangs. How do I serve them?"3031- 400k features → **vector tiles**, not GeoJSON. Use pg_tileserv over the indexed source table; reproject to 3857 in the tile query.3233```json34// MapLibre style fragment — consume the vector-tile source35{36 "sources": {37 "parcels": {38 "type": "vector",39 "tiles": ["https://tiles.example.com/public.parcel/{z}/{x}/{y}.pbf"],40 "minzoom": 0, "maxzoom": 1641 }42 },43 "layers": [44 {45 "id": "parcel-fill",46 "type": "fill",47 "source": "parcels",48 "source-layer": "public.parcel",49 "paint": {50 "fill-opacity": ["interpolate", ["linear"], ["zoom"], 10, 0, 13, 0.4]51 }52 }53 ]54}55```5657The pg_tileserv source query (run by the server) must `ST_Transform(geom, 3857)` and rely on the table's GiST index for the bbox filter — route that schema/index work to [`../../agents/geospatial-data-engineer.md`](../../agents/geospatial-data-engineer.md).5859## Guardrails60- Never ship a multi-megabyte GeoJSON to the browser when feature count says vector tiles — that is the #1 slow-map cause.61- Tiles are 3857: a source in 4326 must be `ST_Transform`ed in the tile query, or the map is blank/mis-placed.62- A `source-layer` name mismatch produces an empty layer with no error — check it first when a styled layer doesn't render. See [`../../best-practices/vector-tiles-over-geojson-at-scale.md`](../../best-practices/vector-tiles-over-geojson-at-scale.md) and [`../../templates/tile-serving-architecture.md`](../../templates/tile-serving-architecture.md).