From 4128a0ac7dab480d5cf574e70f59ee519ab64fd3 Mon Sep 17 00:00:00 2001 From: Shadowbroker <43977454+BigBodyCobain@users.noreply.github.com> Date: Tue, 6 Oct 2026 15:48:00 -0600 Subject: [PATCH] fix(basemap): default to keyless OpenFreeMap --- .../src/components/map/styles/mapStyles.ts | 44 +++++++++++-------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/frontend/src/components/map/styles/mapStyles.ts b/frontend/src/components/map/styles/mapStyles.ts index 2c0605bb..d4916429 100644 --- a/frontend/src/components/map/styles/mapStyles.ts +++ b/frontend/src/components/map/styles/mapStyles.ts @@ -1,54 +1,60 @@ /** - * MapLibre basemap styles on CARTO raster tiles. CARTO requires an API key - * (unkeyed tiles are watermarked); MaplibreViewer passes one from - * useBasemapConfig() via buildBasemapStyle(). The key is served by the - * backend at GET /api/basemap-config. + * ShadowBroker's zero-config basemap uses OpenFreeMap vector styles. + * Operators who configure CARTO_API_KEY keep the existing CARTO raster + * basemap path. This avoids CARTO's unkeyed "API KEY REQUIRED" watermark + * without taking the configured provider away from existing installs. */ export type BasemapTheme = 'dark' | 'light'; +export const OPENFREEMAP_STYLE_URLS: Record = { + dark: 'https://tiles.openfreemap.org/styles/dark', + light: 'https://tiles.openfreemap.org/styles/positron', +}; + const CARTO_SUBDOMAINS = ['a', 'b', 'c', 'd'] as const; const CARTO_RASTER_STYLE: Record = { dark: 'dark_all', light: 'light_all', }; -const GLYPHS_URL = 'https://demotiles.maplibre.org/font/{fontstack}/{range}.pbf'; -// Declared on the raster source so MapLibre's AttributionControl shows it -// even without the custom list in MaplibreViewer. Same markup as that list so -// the control de-duplicates instead of showing both. export const OSM_ATTRIBUTION_HTML = '© OpenStreetMap contributors'; export const CARTO_ATTRIBUTION_HTML = 'CARTO'; +export const OPENFREEMAP_ATTRIBUTION_HTML = + 'OpenFreeMap · OpenMapTiles'; -/** Tile URL templates for a CARTO raster style, keyed when a key is supplied. */ -export function cartoTileUrls(theme: BasemapTheme, cartoApiKey?: string | null): string[] { +/** Tile URL templates for the optional CARTO raster style. */ +export function cartoTileUrls(theme: BasemapTheme, cartoApiKey: string): string[] { const style = CARTO_RASTER_STYLE[theme]; - const key = (cartoApiKey || '').trim(); - const query = key ? `?key=${encodeURIComponent(key)}` : ''; + const key = cartoApiKey.trim(); return CARTO_SUBDOMAINS.map( - (s) => `https://${s}.basemaps.cartocdn.com/rastertiles/${style}/{z}/{x}/{y}@2x.png${query}`, + (s) => + `https://${s}.basemaps.cartocdn.com/rastertiles/${style}/{z}/{x}/{y}@2x.png?key=${encodeURIComponent(key)}`, ); } +/** + * Use OpenFreeMap by default. CARTO is retained as an opt-in compatibility + * path when an operator has already configured CARTO_API_KEY. + */ export function buildBasemapStyle(theme: BasemapTheme, cartoApiKey?: string | null) { + const key = (cartoApiKey || '').trim(); + if (!key) return OPENFREEMAP_STYLE_URLS[theme]; + const sourceId = `carto-${theme}`; return { version: 8, - glyphs: GLYPHS_URL, sources: { [sourceId]: { type: 'raster', - tiles: cartoTileUrls(theme, cartoApiKey), + tiles: cartoTileUrls(theme, key), tileSize: 256, attribution: `${OSM_ATTRIBUTION_HTML} ${CARTO_ATTRIBUTION_HTML}`, }, }, - layers: [ - { id: `${sourceId}-layer`, type: 'raster', source: sourceId, minzoom: 0, maxzoom: 22 }, - { id: 'imagery-ceiling', type: 'background', paint: { 'background-opacity': 0 } }, - ], + layers: [{ id: `${sourceId}-layer`, type: 'raster', source: sourceId, minzoom: 0, maxzoom: 22 }], }; }