fix: the map viewer was blank in night and amber

MapViewer handed protomaps-themes-base the WROLPi theme name as its
basemap "flavor".  That worked while the only themes were `light` and
`dark`, and broke the day night and amber arrived: protomaps looks the
flavor up in a record and dereferences the result without checking, so an
unknown name is not a fallback but

    TypeError: Cannot read properties of undefined (reading 'background')
        at nolabels_layers (base_layers.ts:18)

thrown before the first tile.  MapLibre never constructed, so /map
rendered nothing in two of the four themes.

`mapFlavor()` in themes/names.ts maps a theme to one of the two flavors we
can actually serve.  Only `light` and `dark`: the flavor is interpolated
into `/map-assets/sprites/<flavor>` too, and those are the two sprite sets
we ship, so protomaps' `black` and `grayscale` would load a style and then
find no icons.  Night and amber take `dark` and let the media filter tint
the canvas -- a filter shifts hue, so handing them `light` would give a
red or amber slab, which is the opposite of the point.

Two layers of test, because they cover different halves:

  - map-flavor.test.js checks every theme against the REAL protomaps
    (calling layers() and requiring it not to throw) and against the
    sprites directory on disk, rather than a list of valid names copied
    into the test, which is what would have passed here in the first
    place.  It fails when a fifth theme is added without a mapping.
  - map-themes.cy.js drives the actual page in all four themes and waits
    for the MapLibre canvas.  The unit test cannot see whether MapViewer
    USES the mapping, which is the half that was broken.  Verified against
    the planted regression: night and amber fail with no canvas, light and
    dark still pass.

Not a bug: the 404 on /blobs/map-overview.pmtiles in the same trace.  That
is a HEAD probe for an optional planet overview, gated on `resp.ok`, and
the blob is absent in a dev checkout.  The console line is unavoidable.

1093 jest / 61 suites, clean build.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Roland 2026-08-02 13:25:13 -06:00 • committed by lrnselfreliance
parent 938e3dee6a
commit 6b9bc4b072
4 changed files with 127 additions and 2 deletions

View file

@ -9,6 +9,7 @@ import {addMapPin, deleteMapPin, getMapFiles, getMapPins, searchMap, setMapDefau
import {MAP_VIEWER_URI} from "./Vars";
import {Button, Checkbox, Header, Icon, Panel, TextInput, Toggle} from "./ui";
import {SettingsContext, ThemeContext} from "../contexts/contexts";
import {mapFlavor} from "../themes/names";
// Terrain DEM file prefix for hillshade and contours.
const TERRAIN_PREFIX = "terrain-";
@ -611,7 +612,7 @@ export default function MapViewer() {
try {
map = new maplibregl.Map({
container: mapContainer.current,
style: buildStyle(mapSources, theme, hasTerrain, scaleUnit),
style: buildStyle(mapSources, mapFlavor(theme), hasTerrain, scaleUnit),
center: [initialLon, initialLat],
zoom: initialZoom,
attributionControl: true,
@ -757,7 +758,7 @@ export default function MapViewer() {
const center = map.getCenter();
const zoom = map.getZoom();
map.setStyle(buildStyle(activeFilesRef.current, theme, hasTerrainRef.current, scaleUnit));
map.setStyle(buildStyle(activeFilesRef.current, mapFlavor(theme), hasTerrainRef.current, scaleUnit));
map.once("style.load", () => {
map.setCenter(center);
map.setZoom(zoom);