Broad Map Layer ID Matching
"/home/yossef/notes/git/projects/maplibra/risks/Broad Map Layer ID Matching.md"
path: maplibra/risks/Broad Map Layer ID Matching.md
- **fileName**: Broad Map Layer ID Matching
- **Created on**: 2026-06-16 00:48:42
Broad Map Layer ID Matching
Migrated from: obs_vault
Parent: ./Theme Risk Index.md
Severity: high.
Summary
applyThemeToMap() themes and hides layers by checking whether layer IDs contain substrings like water, road, transportation, or building. This can affect app-owned or future custom layers that were not meant to be treated as basemap layers.
Code Evidence
theme.js: lines 200-226 iterate every style layer and useincludes()checks.theme.js: lines 223-225 hide every layer whose ID containsbuilding.src/app/map-setup.js: lines 78-81 callapplyThemeToMap()on everystyle.load.src/ui/ThemeController.js: lines 97-111 can callapplyThemeToMap()on theme update.src/layers/base/core.js: app-ownedbuilding-shellis a layer ID containingbuilding.
Trigger Conditions
- A theme change after app-owned layers are present.
- A style reload after
building-shellor other app layers were added. - A custom basemap or MVF layer with ID containing
building,road,water, ortransportation.
Likely Symptoms
building-shelldisappears because it gets layout visibilitynone.- App-owned layers are recolored as if they were basemap layers.
- Future custom layers behave differently only because their IDs happen to include a substring.
- Theme bugs appear only with certain basemap/style layer names.
Why It Matters
Layer ownership is not encoded in the check. A theme function should not mutate every layer whose ID happens to match a word. This is especially risky because the building shell is a core indoor affordance and visibility managers intentionally treat it as a special layer.
Current Tests
- No direct tests for
applyThemeToMap()were found. tests/theme-host-mode.test.jscovers host style resolution only.tests/visibility-manager.test.jscovers annotation marker visibility, not shell visibility after theming.
Missing Tests
applyThemeToMap does not hide app building-shell layer.applyThemeToMap only touches known basemap layers.theme toggle after addBuildingShell preserves shell visibility.custom non-basemap building-like layer is not hidden unless allowlisted.
How To Make Better
- Replace substring matching with an explicit allowlist for known basemap layer IDs.
- Exclude app-owned layer IDs such as
building-shell,doors,labels, route layers, and MVF style layers. - Prefer source-based checks, e.g. only mutate layers from known basemap sources.
- Keep basemap theming separate from indoor-layer theming; indoor layers should be owned by
LayerManager.reapplyThemeColors(). - Add regression tests using a mock style with
building-shell,building-3d,road-minor, and a customindoor-road-label.
Debug Steps
- Inspect
map.getStyle().layersbefore and after a theme change. - Check whether
building-shelllayout visibility changes tonone. - Confirm whether the affected layer source is a basemap source or an app source.
- Compare the result with
LayerManagervisibility state.
See Also
-
continue:[[]]
before:[[]]