diff --git a/client/src/components/Map/VectorBasemap.tsx b/client/src/components/Map/VectorBasemap.tsx index ace778346..7fa237f8b 100644 --- a/client/src/components/Map/VectorBasemap.tsx +++ b/client/src/components/Map/VectorBasemap.tsx @@ -47,7 +47,8 @@ async function loadLayerFactory() { import('./engines/maplibre'), import('@maplibre/maplibre-gl-leaflet'), ]) - guardTransitionEnd(bridge.MaplibreGL.prototype as unknown as GlLayerInternals) + // Optional: a test that mocks the bridge hands over the factory alone. + if (bridge.MaplibreGL) guardTransitionEnd(bridge.MaplibreGL.prototype as unknown as GlLayerInternals) return bridge.maplibreGL } @@ -236,7 +237,7 @@ export function restyleBasemap(layer: BasemapLayer | null | undefined, style: st * is no (#2288). Asking is also what keeps the maplibre chunk off the wire for a * browser that could never have used it. */ -export function VectorBasemap({ style }: { style: string }) { +export function VectorBasemap({ style, hideLabels = false }: { style: string; hideLabels?: boolean }) { const map = useMap() const layerRef = useRef(null) const styleRef = useRef(style) @@ -271,6 +272,8 @@ export function VectorBasemap({ style }: { style: string }) { return } layerRef.current = layer + // Fixed per map (a small route map wants no place names), so it never rebuilds the layer. + if (hideLabels) hideLabelLayers(layer) // A style that never loads (its server, or the iOS app's offline protocol // failing) would leave the map white under its markers: raster instead. onStyleFailure(layer, () => { @@ -286,7 +289,7 @@ export function VectorBasemap({ style }: { style: string }) { detachBasemapLayer(layerRef.current) layerRef.current = null } - }, [map, glUsable]) + }, [map, glUsable, hideLabels]) useEffect(() => { restyleBasemap(layerRef.current, style) diff --git a/client/src/components/Planner/flightLive/FlightMiniMap.tsx b/client/src/components/Planner/flightLive/FlightMiniMap.tsx index 607386226..34d8ee38a 100644 --- a/client/src/components/Planner/flightLive/FlightMiniMap.tsx +++ b/client/src/components/Planner/flightLive/FlightMiniMap.tsx @@ -69,50 +69,6 @@ function FitRoute({ route, inset, onReady }: { route: LatLng[]; inset: number; o return null; } -/** The slice of a MapLibre map this file touches. */ -interface GlMap { - getStyle(): { layers?: { id: string; type: string }[] } | undefined; - setLayoutProperty(id: string, key: string, value: string): void; - on(event: string, fn: () => void): void; - off(event: string, fn: () => void): void; -} - -/** - * Hides the basemap's place names. Under a faded route at world scale they are - * clutter ("Italy" beside a Frankfurt dot), and the two airport codes on the - * route say all there is. The GL map only exists once its layer attached, so - * this waits for it, and hides again on each restyle (dark mode). - */ -function HideLabels() { - const map = useMap(); - useEffect(() => { - let gl: GlMap | null = null; - const hide = () => { - for (const layer of gl?.getStyle()?.layers ?? []) { - if (layer.type === 'symbol') gl?.setLayoutProperty(layer.id, 'visibility', 'none'); - } - }; - const find = () => { - if (gl) return; - map.eachLayer((layer) => { - const found = (layer as unknown as { getMaplibreMap?: () => GlMap }).getMaplibreMap?.(); - if (found && !gl) { - gl = found; - gl.on('styledata', hide); - hide(); - } - }); - }; - find(); - map.on('layeradd', find); - return () => { - map.off('layeradd', find); - gl?.off('styledata', hide); - }; - }, [map]); - return null; -} - /** One end of the route: a ring with the airport code under it. */ function RouteEnd({ at, code }: { at: LatLng; code: string }) { return ( @@ -146,7 +102,7 @@ interface FlightMiniMapProps { * The flight on a real map, small and quiet: the great circle between the two * airports, solid where it is flown and dotted where it is left, the aircraft * on the line as far as the feed last saw it, turned along the route. Nothing on it reacts to a - * touch, it is a picture. The edges fade into the surface on all four sides + * touch, it is a picture, without place names. The edges fade into the surface on all four sides * (flightMiniMap.css), and the map fades in once it is framed, so it never * shows a jump from the world view to the route. Colours come in as the custom * properties --fm-flown, --fm-ahead, --fm-end, --fm-plane and --fm-code. @@ -206,8 +162,7 @@ export default function FlightMiniMap({ trackResize={false} className="h-full w-full bg-transparent" > - - + [p.lat, p.lng])} diff --git a/client/src/utils/flightRoute.test.ts b/client/src/utils/flightRoute.test.ts index 126848311..0e84f90e8 100644 --- a/client/src/utils/flightRoute.test.ts +++ b/client/src/utils/flightRoute.test.ts @@ -34,7 +34,7 @@ describe('flightRoute', () => { it('FE-UTIL-FLIGHTROUTE-004: cuts the route where the aircraft is, clamped to its ends', () => { const route = greatCircle(FRA, YYZ, 10); const half = splitRoute(route, 0.5); - expect(half.flown.at(-1)).toEqual(half.at); + expect(half.flown[half.flown.length - 1]).toEqual(half.at); expect(half.ahead[0]).toEqual(half.at); expect(half.flown.length + half.ahead.length).toBe(route.length + 2); expect(splitRoute(route, -1).at).toEqual(route[0]);