mirror of
https://github.com/BigBodyCobain/Shadowbroker.git
synced 2026-12-05 00:53:37 +01:00
Merge pull request #615 from BigBodyCobain/fix/map-label-fonts
fix(map): pin text-font on label layers so CCTV and correlation overlays render
This commit is contained in:
2 files changed
+51
No files matched your search
@@ -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([]);
|
||||
});
|
||||
});
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user