ADR-035: Self-Hosted Vector Map Tiles
Metadata:
- ID: ADR-035
- Status: Accepted — server implemented 2026-07-24 (see Implementation below)
- Date: 2026-07-23
- Tags: [osm, tiles, vector, mvt, map, ops, rendering, dependency, hosting, web]
- Decision Type: technology_choice
- Aligns with: [G-04, G-02, P-03]
- Roadmap tier: P1
- Doc resolution: R2
- Related: [ADR-004, ADR-020, ADR-022, ADR-023, ADR-025, ADR-027, ADR-033, ADR-034, ADR-014]
- Supersedes: []
- Superseded By: []
Context
Problem: The client renders the map from raster tiles fetched straight from
tile.openstreetmap.org (the osm_tile_url_template default in cartopolis_simulator/src/config.rs:42),
consumed by tile_loader, map_stream and the globe. Three things make that untenable for the
web target (ADR-033) and increasingly untenable generally:
- OSM's tile CDN is not a base layer for a product. Their tile usage policy expects heavy or commercial consumers to run their own infrastructure, and explicitly discourages proxying — so ADR-034's normal answer (an L2 passthrough) is off the table here.
- A browser cannot identify itself.
User-Agentis a forbidden header infetch(), soTILE_USER_AGENT— our compliance with the policy's identification requirement — does not apply on the web build. - Tiles are by far our largest byte volume, across both the map tier and the globe tier (ADR-020, ADR-025). This is where caching and locality matter most (P-03).
A fourth, smaller issue: the tile template is currently handed to the client by the sim in
ServerHelloAck. ADR-031's anonymous Viewer has no sim, so it needs the template from
configuration instead (there is a Default in resources.rs:581, but it should be explicit).
We already self-host the rest of the geo stack — Nominatim, Overpass, 3DBAG (ADR-027) — behind the garage44 Caddy, so this follows an established pattern rather than starting one.
Decision
Serve our own OSM vector tiles (Mapbox Vector Tile / MVT) from our origin, in the Shortbread schema the client already tessellates and lights. The client decodes MVT and renders the map as geometry; styling happens client-side.
Implementation (2026-07-24) — how the server was actually built. The mechanism below (planetiler → PMTiles → a
cartopolis_relayhandler) was the plan; the shipped server takes a simpler path that reaches the same end. The client's whole vector path —vector_tiles.rs,routing.rs, the styling — is written against the Shortbread schema, which is whattiles.versatiles.orgserves and what this ADR's default already pointed at. Rather than run planetiler (whose default profile is not Shortbread, and whose planet build needs far more RAM than the 22 GB VPS has), we mirror VersaTiles' prebuilt planet archive and serve it ourselves:
- Data:
https://download.versatiles.org/osm.versatiles— one 62 GB.versatilescontainer, z0–14, Shortbread. Downloaded once to/srv/versatiles/osm.versatileson the garage44.eu VPS (on/, not/data— the 62 GB doesn't fit the smaller volume). Refresh = re-download.- Serving: the Rust
versatilesserver (ghcr.io/versatiles-org/versatiles) as atilesservice in the existinggeoDocker Compose stack, exposing/tiles/osm/{z}/{x}/{y}. It already emitsAccess-Control-Allow-Origin: *and a 28-dayCache-Control, so no relay logic is needed — this replaces the "smallpmtileshandler incartopolis_relay" design.- Origin: Caddy fronts it at
tiles.cartopolis.org(its own subdomain, the overpass / nominatim / 3dbag pattern), not the same-origin/tiles/*path ADR-034 sketched. The single-origin relay of ADR-033/034 (for the wasm build) can still front this upstream later.- Client: a pure origin swap.
DEFAULT_TILE_URL_TEMPLATEmoved fromtiles.versatiles.orgtotiles.cartopolis.org— same schema, same URL shape, no decode/render change.CARTO_TILE_URLstill overrides.The rest of this ADR (why vector, coverage, client work, downstream consolidation) stands as written; only the generation-and-serving mechanism changed. Planetiler → PMTiles remains the path to a custom cartopolis-styled or non-Shortbread tileset if we ever outgrow the mirror.
The original plan — kept for the record and as the fallback for a custom tileset — was to serve at
/tiles/{z}/{x}/{y}.mvt, generated offline with planetiler and stored as PMTiles:
Why vector rather than raster
Raster was the conservative choice because it preserved the existing PNG → texture path. Vector wins on the axes that matter most for this project:
- Styling is client-side and dynamic. cartopolis has a live day/night cycle, atmosphere and weather (ADR-005, ADR-032). A raster basemap is a photograph — it cannot respond to any of it, and a night city lit by a midday basemap looks wrong. Vector geometry can be styled, lit and shaded by the systems already running.
- The map stops being wallpaper and becomes geometry, which fits a 3D world far better than a projected image: roads as ribbons, water and landuse as tessellated polygons, at real elevation.
- Overzoom removes the expensive zooms. Vector tiles stop at ~z14 and the client renders deeper levels from the same data. The raster plan's costly z15–z19 regional pyramid simply does not exist.
- Far smaller over the wire, which matters most for the wasm build.
- Pure-Rust decode (
geozero/protobuf) → wasm-safe, no C dependency (cf. theopenjpeg-syslesson in ADR-033). - The pipeline gets simpler, not harder: planetiler emits vector tiles directly, so the rasterisation step the raster plan needed disappears. This is what let this ADR move from R1 to R2 — the pipeline is no longer an open spike.
Coverage
| Tier | Zooms | Extent |
|---|---|---|
| Globe / space (ADR-025) | z0–~z6 | whole planet |
| Map / city | to ~z14, then client overzoom | regional extracts first (Netherlands, matching 3DBAG), expanding per region |
Rough order of magnitude: a country extract is single-digit GB; the full planet to z14 is tens of GB — feasible later, but regional extracts plus global low zoom is the sensible start. (Estimates to be confirmed by the implementation workstream.)
Serving
A PMTiles archive (single file, HTTP range reads) rather than millions of small files. A small
Rust handler (pmtiles crate) reads z/x/y out of the archive; this lives in cartopolis_relay
(ADR-034) as a first-class route rather than an UPSTREAMS adapter — it has no upstream, it reads
local data. Caddy fronts it at /tiles/* with long-lived Cache-Control; the native client keeps
an on-disk cache.
Client work (the substantial part)
This is a real client change, not a URL swap, and is being built in a separate workstream:
- Decode MVT (protobuf) instead of PNG.
- Tessellate polygons —
earcutris already in the client for OSM building footprints (ADR-022), so the machinery exists; lines (roads) become ribbon geometry. - Style client-side: a style definition maps MVT layers/classes to colours, widths and heights, and can respond to time of day and weather.
tile_loader/map_stream/ the globe move from "fetch image → texture" to "fetch tile → geometry", keeping the existing streaming, LOD and cache-eviction structure.
The globe tier may keep a rasterised or simplified representation at very low zoom, where per-feature geometry buys nothing — decided during implementation.
Client configuration
The tile URL template becomes configuration (ADR-014 layering) rather than something only the
sim supplies, so the anonymous Viewer (ADR-031) has a base map with no session. ServerHelloAck
may still override it, letting a deployment point clients at its own tile source.
The default is now the vector source: cartopolis_core::world::DEFAULT_TILE_URL_TEMPLATE
(https://tiles.versatiles.org/tiles/osm/{z}/{x}/{y}), shared by the sim's advertised default
(cartopolis_simulator/src/config.rs) and the client's offline/--shot fallback (tile_loader) so the two
cannot drift. This replaces the original raster tile.openstreetmap.org/{z}/{x}/{y}.png default:
with the tessellated-and-lit client path real, leaving raster as the out-of-the-box source meant
solo mode silently rendered the old pre-baked tiles (labels, dashed carto, static lighting) instead
of the vector map this ADR exists to deliver. A raster template still works — tile_source_kind
classifies by the tail after {y}, and CARTO_TILE_URL / CARTO_TILE_FORMAT override per run — it
is just no longer the default.
Downstream consolidation (noted, not decided)
MVT tiles carry buildings, roads, landuse and POIs — overlapping what we currently fetch from Overpass for building footprints (ADR-022) and data layers (ADR-023). There is a real opportunity to retire some Overpass traffic later. Not decided here: Overpass gives live, queryable, arbitrarily fresh data, while tiles are a periodic snapshot at fixed zoom, and the data layers depend on tag filtering that MVT schemas flatten away. Revisit once the vector client path is real.
Rationale
Primary Reasoning:
- Policy leaves no alternative to self-hosting. OSM discourages proxying and expects heavy users to self-host; the browser cannot send our identifying User-Agent.
- Vector suits a lit, 3D, time-varying world. Our basemap needs to respond to the day/night and weather systems; a raster image structurally cannot.
- Overzoom collapses the cost. The dominant expense in the raster plan was the high-zoom regional pyramid, which vector tiles do not need.
- It follows the existing pattern — one more self-hosted geo service behind the same Caddy (ADR-027 precedent).
- Pure-Rust decode keeps the wasm target clean, unlike the C-dependency trap ADR-033 hit.
- We control caching and locality for our highest-volume traffic (P-03).
Alternatives Considered:
| Alternative | Pros | Cons | Rejected Because |
|---|---|---|---|
Keep hitting tile.openstreetmap.org | Zero work | Against their policy at our scale; no UA from a browser | Not viable for a public web build |
| Proxy/cache OSM tiles through our relay | Little infrastructure | OSM explicitly discourages proxying; still their bandwidth | Policy, not cost |
| Self-hosted raster tiles (the earlier plan) | No client change; preserves PNG→texture path | Static appearance under a live day/night cycle; expensive high-zoom pyramid; larger payloads; needs a rasterisation step | Vector is a better fit for a lit 3D world and cheaper to store and serve |
| Third-party keyed provider (MapTiler, Stadia, …) | No ops at all | Per-tile cost; key custody in a browser; vendor dependency | Recurring cost and dependency for our highest-volume asset |
| Directory of tile files | Dead simple | Millions of inodes; slow sync/backup | PMTiles is one file with the same access pattern |
| Full planet at full depth now | Uniform | Tens of GB and long build before it's needed | Regional extracts + global low zoom is the sensible start |
Consequences
Positive:
- The web build gets a base map that is ours, compliant, and same-origin (ADR-034).
- The basemap participates in lighting, day/night and weather instead of fighting them.
- Overzoom removes the high-zoom storage pyramid; payloads shrink, which most helps wasm.
- Pure-Rust decode — no C dependency on the wasm path.
- The anonymous Viewer gets a base map with no sim session (ADR-031).
- Removes a third-party runtime dependency from the critical path.
- A future path to retiring some Overpass traffic (noted above).
Negative:
- A substantial client rewrite of the tile path — decode, tessellation, styling — replacing a
working PNG→texture pipeline (mitigation: separate workstream;
earcutrand the streaming/LOD structure are reused). - We now own map styling, which is real design work and will not resemble
tile.openstreetmap.org(mitigation: eventually desirable — a cartopolis style — but it is work that raster would not have required). - A generation pipeline to run and refresh (mitigation: planetiler is a single tool with no PostGIS/render-daemon stack; refresh cadence can be weeks).
- Storage of single-digit GB per region, growing as regions are added.
- Staleness: tiles lag OSM edits by the refresh cadence (mitigation: acceptable for a base map; Overpass-driven layers remain live).
- Attribution remains mandatory under ODbL — self-hosting changes nothing there.
- Low-zoom/globe rendering is unresolved — per-feature geometry may not suit the space tier (mitigation: decide during implementation; a simplified or rasterised globe representation is allowed).
- Until the pipeline and client path exist, the web build has no compliant base map — this is on ADR-033's Phase 1 critical path.
Related
- ADR-004: Revises its raster-tile-as-texture mechanism; tiles become vector geometry from our own origin.
- ADR-020: The map tier stops being a "stack of photos" and becomes streamed geometry; the tier split itself is unchanged.
- ADR-034: Single-origin layout; tiles are served locally at
/tiles/*, not proxied. - ADR-033: The web target that forces the issue; this is on its Phase 1 path.
- ADR-027: The precedent — a self-hosted geo dataset behind the same Caddy.
- ADR-022, ADR-023: Overlap with MVT content; possible future consolidation, not decided here.
- ADR-025: Consumes the global low-zoom set.
- ADR-014: Tile template moves into config layering.