Contract: Production Basemap Configuration & MapLibre Behavior
Feature: 20261127-143403-openfreemap-production-tiles
Date: 2026-11-27
Related: spec.md | data-model.md | plan.md
This contract supersedes the Public Build-Time Settings and Tile-Service Policy sections of 20261014-223122-open-source-explore-maps/contracts/map-ui-and-configuration.md while preserving all UI layout, marker, group, coordinate, and keyboard accessibility contracts unchanged.
1. Public Build-Time Environment Variables
All VITE_MAP_* variables are public frontend build-time settings embedded into the static JavaScript bundle during Vite compilation.
- Never place secrets or private tokens in
VITE_MAP_*variables. - Changes require rebuilding the frontend bundle (or rebuilding the Docker image/wheel from source). No runtime configuration endpoint or HTML template injection is introduced.
- A root backend
.envfile is not automatically read by Vite unless exported into the frontend build environment or forwarded by Docker Compose build arguments.
| Variable | Default | Applicability | Validation Contract |
|---|---|---|---|
VITE_MAP_STYLE_URL | https://tiles.openfreemap.org/styles/liberty | Vector style mode (active when VITE_MAP_TILE_URL is unset/empty) | HTTPS URL (https://...) or same-origin root-relative path (/..., not //...), no whitespace, valid URL, no embedded username/password |
VITE_MAP_TILE_URL | (unset) | Selects custom raster XYZ mode when non-empty; takes precedence over VITE_MAP_STYLE_URL | HTTPS URL (https://...) or same-origin root-relative path (/..., not //...), MUST include {z}, {x}, {y}, valid URL, no embedded username/password |
VITE_MAP_ATTRIBUTION_TEXT | (unset) | Required when VITE_MAP_TILE_URL is set; ignored in vector style mode | Non-empty plain text after trim |
VITE_MAP_ATTRIBUTION_URL | (unset) | Required when VITE_MAP_TILE_URL is set; ignored in vector style mode | Valid https:// URL, no embedded username/password |
VITE_MAP_MAX_NATIVE_ZOOM | 19 | Used only when VITE_MAP_TILE_URL is set; ignored in vector style mode | Integer 0–19; MapLibre may overzoom up to map zoom 19 |
Build & Packaging Propagation Contract
The following build entrypoints MUST forward VITE_MAP_STYLE_URL alongside the four raster variables:
src/frontend/vite-env.d.ts(ImportMetaEnvtype definitions)src/hatchling/plugin.py(PUBLIC_SETTINGSwhitelist andbuild/frontend-manifest.jsoninput digest)Dockerfile(ARG VITE_MAP_STYLE_URLandENV VITE_MAP_STYLE_URL=$VITE_MAP_STYLE_URLinapplication-build)docker-compose.yaml(VITE_MAP_STYLE_URL: ${VITE_MAP_STYLE_URL:-}underx-camply.build.args)
2. Precedence Matrix
| Scenario | VITE_MAP_STYLE_URL | VITE_MAP_TILE_URL | VITE_MAP_ATTRIBUTION_* | VITE_MAP_MAX_NATIVE_ZOOM | Resulting Behavior |
|---|---|---|---|---|---|
| Zero-config default (local, Pages, GHCR, PyPI) | unset / "" | unset / "" | unset / "" | unset or "19" | Vector style: https://tiles.openfreemap.org/styles/liberty |
| Alternate OpenFreeMap or custom vector style | https://tiles.openfreemap.org/styles/bright (or /styles/custom.json) | unset / "" | unset / ignored | unset or "19" / ignored | Vector style: configured VITE_MAP_STYLE_URL |
| Invalid custom vector style | http://insecure.example/style.json or javascript:alert(1) or https://u:p@host/style.json | unset / "" | unset | unset | Throws validation error → local role="alert" in map; list search stays usable |
| Custom raster XYZ override | unset / "" | https://tiles.example.test/{z}/{x}/{y}.png | valid text + HTTPS URL | "16" (or unset → 19) | Inline raster style with tiles: [url], maxzoom: 16, safe DOM attribution link |
| Both style URL and raster URL set | https://tiles.openfreemap.org/styles/bright | /tiles/{z}/{x}/{y}.png | valid text + HTTPS URL | "4" | Raster wins: inline raster style /tiles/{z}/{x}/{y}.png with maxzoom: 4 |
| Custom raster URL missing attribution | unset or set | /tiles/{z}/{x}/{y}.png | missing text or URL | unset or "19" | Throws validation error (Custom map source requires attribution text and URL.) → local role="alert" |
| Custom raster URL with invalid zoom | unset or set | /tiles/{z}/{x}/{y}.png | valid text + HTTPS URL | "25" | Throws validation error (Map native zoom must be an integer from 0 to 19.) → local role="alert" |
3. MapLibre Style Loading, Requests, Attribution & Error Contract
Initialization
- Vector style mode (
config.kind === "style"): Passstyle: config.styleUrldirectly tonew LibreMap({ ... }). KeepminZoom: 0,maxZoom: 19,maxPitch: 0,dragRotate: false,renderWorldCopies: true,attributionControl: false,fadeDuration: 0. - Custom raster mode (
config.kind === "raster"): Build the inlineStyleSpecification(version: 8) withsources.basemap(type: "raster",tiles: [config.url],tileSize: 256,minzoom: 0,maxzoom: config.maxNativeZoom,attribution: credit.outerHTML) andlayers: [{ id: "basemap", type: "raster", source: "basemap", paint: { "raster-fade-duration": 0 } }], wherecreditis a DOM<a>element created viadocument.createElement("a")withtextContent = config.text,href = config.link,target = "_blank",rel = "noopener noreferrer".
Request Isolation (transformRequest)
Every request initiated by MapLibre (style JSON, TileJSON, vector/raster tiles, sprites, and glyph PBFs) MUST pass through:
transformRequest: (url) => ({
url,
credentials: "same-origin",
referrerPolicy: "strict-origin",
});- Cross-origin requests to OpenFreeMap or third-party hosts MUST NOT include cookies,
Authorization, orX-CSRF-Token. - No
cacheoverride (no cache-busting query params orcache: "no-store"), preserving ordinary browser HTTP caching.
Attribution Rendering
- Always attach
new AttributionControl({ compact: false })at"bottom-right". - In vector style mode, MapLibre automatically renders source attribution from the loaded style/TileJSON (for OpenFreeMap:
OpenFreeMap © OpenMapTiles Data from OpenStreetMap). No duplicatecustomAttributionis injected. - In custom raster mode, MapLibre renders
sources.basemap.attribution(the single validated operator link). - Attribution styling in
.camply-map .maplibregl-ctrl-attribMUST maintain accessible contrast in both light and dark modes and MUST NOT cause document-level horizontal overflow at 375 px or 1440 px viewports.
Failure & Recovery Semantics
- Source / tile error: When MapLibre emits
"error"with a non-empty stringevent.sourceId(e.g.,"openmaptiles"in OpenFreeMap or"basemap"in custom raster mode), addevent.sourceIdto the tracked failed-source set and display the non-blockingrole="status"warning with Retry tiles. Clicking Retry tiles hides the warning, callsmap?.refreshTiles(id)for every tracked failedsourceId, and clears the tracked set. - Style-load / fatal error: When
basemapConfig()throws,new LibreMap(...)throws,"webglcontextlost"fires, or MapLibre emits"error"without a non-emptysourceId(such as a failed remote style JSON fetch), display the localrole="alert"error message with Retry map. Clicking Retry map remounts the map instance while preserving saved camera state and without affecting list search or destination details.
4. Offline Automated Verification Contract
Browser verification (src/frontend/tooling/verify-maps.ts) and visual regression snapshots (src/frontend/tooling/run-snapshots.ts) MUST adhere to:
- Zero external map traffic: Intercept
https://tiles.openfreemap.org/**before navigation:https://tiles.openfreemap.org/styles/**→ HTTP 200application/jsonwithAccess-Control-Allow-Origin: *returning a deterministic minimal MapLibre v8 Style JSON with source"openmaptiles",tiles: ["https://tiles.openfreemap.org/fixture-tiles/{z}/{x}/{y}.png"],tileSize: 256,maxzoom: 19, and OpenFreeMap's attribution links (OpenFreeMap,© OpenMapTiles,OpenStreetMap).https://tiles.openfreemap.org/fixture-tiles/**→ HTTP 200image/pngwithAccess-Control-Allow-Origin: *returning the deterministic 256×256rgb(225, 235, 219)PNG fixture.
- Zero legacy OSM requests: Assert that zero requests are made to
https://tile.openstreetmap.org/**. - Header & referrer verification: Assert that intercepted OpenFreeMap style and tile requests carry no
authorizationorx-csrf-tokenheaders and send an origin-onlyreferer(pathname === "/"). - Dual failure recovery:
verify-maps.tsMUST verify both (a) tile failure onfixture-tiles/**(sourceId: "openmaptiles") recovering via Retry tiles, and (b) style-document failure onstyles/**recovering via Retry map. - Custom override & invalid-config verification:
verify-maps.tsMUST continue verifying customVITE_MAP_TILE_URLstatic subpath builds and invalid configuration recovery (covering both invalidVITE_MAP_STYLE_URLand invalidVITE_MAP_MAX_NATIVE_ZOOM).
5. Security, Privacy & CSP Guidance
- OpenFreeMap Terms & Privacy: OpenFreeMap (
tiles.openfreemap.org) is free and open-source (MIT software, ODbL OpenStreetMap data), permits commercial/public web use, requires attribution, and is operated as-is without a contractual SLA. External tile hosts observe client IP addresses and requested tile/style coordinates; self-hosting a style/tile server avoids that external dependency. - Content Security Policy (CSP): Deployments enforcing strict CSP must permit:
worker-src 'self' blob:(for MapLibre's bundled same-origin Vite worker)connect-srcandimg-srcfor the configured style/tile origin (defaulthttps://tiles.openfreemap.org) to load style JSON, TileJSON, vector tiles, sprites, and glyphs.