Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | 25x 25x 25x 6x 5x 7x | // The basemap under every Leaflet map in fe-core: CARTO's raster tiles —
// Positron in light mode, Dark Matter in dark.
//
// CARTO requires a key, and answers a request without one with an "API KEY
// REQUIRED" watermark rather than an error, so a missing key looks like a
// broken map. Its terms also forbid proxying or caching tiles server-side, so
// unlike site icons (svc-core services/favicons.py) the browser fetches tiles
// from CARTO directly: the key is public by construction. Lock it to the
// app's domains in CARTO's dashboard, which checks the Referer.
//
// The key is `VITE_CARTO_API_KEY`, baked in at build time — see
// docs/guides/frontend-components.md (Maps).
export type BasemapTheme = "light" | "dark";
/** Each theme's style, as the path segment of a tile URL. */
export const BASEMAP_STYLES: Readonly<Record<BasemapTheme, string>> = {
light: "light_all",
dark: "dark_all",
};
/** OpenStreetMap and CARTO both require this credit wherever the tiles go —
* an exported PDF included. */
export const BASEMAP_ATTRIBUTION =
'© <a href="https://www.openstreetmap.org/copyright" target="_blank" rel="noreferrer">OpenStreetMap</a> contributors © <a href="https://carto.com/attributions" target="_blank" rel="noreferrer">CARTO</a>';
export const BASEMAP_MAX_ZOOM = 19;
/** The deployment's CARTO key, or null when none is configured. */
export function basemapKey(): string | null {
return (import.meta.env.VITE_CARTO_API_KEY ?? "").trim() || null;
}
/** A Leaflet tile URL template for one theme, carrying the key.
*
* The form CARTO documents for keyed raster tiles: the apex host under
* `rastertiles/`, rather than the `{s}.basemaps.cartocdn.com/<style>/`
* URLs that predate keys. `{r}` asks for `@2x` tiles on high-DPI screens,
* which this endpoint serves. */
export function basemapUrl(theme: BasemapTheme, key: string): string {
return (
`https://basemaps.cartocdn.com/rastertiles/${BASEMAP_STYLES[theme]}/{z}/{x}/{y}{r}.png` +
`?key=${encodeURIComponent(key)}`
);
}
/** The same tile in the light style, key and all. Both styles come from one
* tile server, so relighting a dark map is a URL swap. */
export function lightTileSrc(src: string): string {
return src.replace(`/${BASEMAP_STYLES.dark}/`, `/${BASEMAP_STYLES.light}/`);
}
|