diff --git a/frontend/src/__tests__/map/mapLabelFonts.test.ts b/frontend/src/__tests__/map/mapLabelFonts.test.ts new file mode 100644 index 00000000..2b4081b5 --- /dev/null +++ b/frontend/src/__tests__/map/mapLabelFonts.test.ts @@ -0,0 +1,44 @@ +/** + * Regression: every overlay label layer must pin an explicit `text-font`. + * + * Without one, MapLibre falls back to "Open Sans Regular,Arial Unicode MS Regular", + * which the keyless OpenFreeMap glyph endpoint does not serve (HTTP 404). The failed + * glyph request errors every tile of the layer's source, so the whole source stops + * rendering — e.g. the CCTV cluster count took the CCTV circles down with it. + */ +import { describe, expect, it } from 'vitest'; +import * as fs from 'fs'; +import * as path from 'path'; + +const VIEWER = path.resolve(__dirname, '../../components/MaplibreViewer.tsx'); + +function layoutBlocks(source: string): { line: number; body: string }[] { + const blocks: { line: number; body: string }[] = []; + const marker = 'layout={{'; + let start = source.indexOf(marker); + while (start !== -1) { + let depth = 2; + let i = start + marker.length; + while (depth > 0 && i < source.length) { + if (source[i] === '{') depth += 1; + else if (source[i] === '}') depth -= 1; + i += 1; + } + blocks.push({ + line: source.slice(0, start).split('\n').length, + body: source.slice(start + marker.length, i), + }); + start = source.indexOf(marker, i); + } + return blocks; +} + +describe('MaplibreViewer label layers', () => { + it('pin a text-font on every layout that renders text', () => { + const source = fs.readFileSync(VIEWER, 'utf-8'); + const missing = layoutBlocks(source) + .filter((b) => b.body.includes("'text-field'") && !b.body.includes("'text-font'")) + .map((b) => `MaplibreViewer.tsx:${b.line}`); + expect(missing).toEqual([]); + }); +}); diff --git a/frontend/src/components/MaplibreViewer.tsx b/frontend/src/components/MaplibreViewer.tsx index e525676d..caddebec 100644 --- a/frontend/src/components/MaplibreViewer.tsx +++ b/frontend/src/components/MaplibreViewer.tsx @@ -2289,6 +2289,7 @@ const MaplibreViewer = ({ id="gps-jamming-label" type="symbol" layout={{ + 'text-font': ['Noto Sans Bold'], 'text-field': [ 'concat', 'GPS JAM ', @@ -2386,6 +2387,7 @@ const MaplibreViewer = ({ filter={['==', ['get', 'corr_type'], 'rf_anomaly']} minzoom={3} layout={{ + 'text-font': ['Noto Sans Bold'], 'text-field': ['concat', 'RF ANOMALY\n', ['get', 'drivers']], 'text-size': ['interpolate', ['linear'], ['zoom'], 3, 7, 5, 9, 8, 11], 'text-allow-overlap': false, @@ -2426,6 +2428,7 @@ const MaplibreViewer = ({ filter={['==', ['get', 'corr_type'], 'military_buildup']} minzoom={3} layout={{ + 'text-font': ['Noto Sans Bold'], 'text-field': ['concat', 'MIL BUILDUP\n', ['get', 'drivers']], 'text-size': ['interpolate', ['linear'], ['zoom'], 3, 7, 5, 9, 8, 11], 'text-allow-overlap': false, @@ -2465,6 +2468,7 @@ const MaplibreViewer = ({ filter={['==', ['get', 'corr_type'], 'infra_cascade']} minzoom={3} layout={{ + 'text-font': ['Noto Sans Bold'], 'text-field': ['concat', 'INFRA CASCADE\n', ['get', 'drivers']], 'text-size': ['interpolate', ['linear'], ['zoom'], 3, 7, 5, 9, 8, 11], 'text-allow-overlap': false, @@ -2505,6 +2509,7 @@ const MaplibreViewer = ({ filter={['==', ['get', 'corr_type'], 'contradiction']} minzoom={2} layout={{ + 'text-font': ['Noto Sans Bold'], 'text-field': ['concat', '? CONTRADICTION\n', ['get', 'context'], ' · ', ['get', 'drivers']], 'text-size': ['interpolate', ['linear'], ['zoom'], 2, 7, 5, 9, 8, 11], 'text-allow-overlap': false, @@ -2557,6 +2562,7 @@ const MaplibreViewer = ({ filter={['==', ['get', 'corr_type'], 'analysis_zone']} minzoom={2} layout={{ + 'text-font': ['Noto Sans Bold'], 'text-field': ['concat', ['get', 'zone_title'], '\n', ['get', 'drivers']], 'text-size': ['interpolate', ['linear'], ['zoom'], 2, 7, 5, 9, 8, 11], 'text-allow-overlap': false, @@ -2599,6 +2605,7 @@ const MaplibreViewer = ({ type="symbol" filter={['has', 'point_count']} layout={{ + 'text-font': ['Noto Sans Bold'], 'text-field': '{point_count_abbreviated}', 'text-size': 12, 'text-allow-overlap': true,