Theme Change
"/home/yossef/notes/git/projects/maplibra/flows/Theme Change.md"
path: maplibra/flows/Theme Change.md
- **fileName**: Theme Change
- **Created on**: 2026-06-16 00:48:42
Theme Change
Purpose: How the app switches between light and dark themes without recreating map layers.
Related: ../Home.md, ../Architecture.md, ../modules/Layer Management.md, ../modules/UI Components.md, ../modules/Path Renderer.md
Theme Architecture
Themes are defined in theme.js with:
mapStyle— Mapbox style URL or JSON objectcolors— Color map for all layer types (walls, floors, labels, background, etc.)
Theme Change Flow
- User toggles theme (or Android dispatches
theme-changed) ThemeController.handleThemeToggle()→script.jshandleThemeChange()map.setStyle(themeConfig.mapStyle, { diff: false })- Wait for
style.loadevent applyThemeToMap()— update background, building shell, labelsLayerManager.reapplyThemeColors()— update all style layers- Background color
- Building shell extrusion color
- Label text and halo colors
- Dynamic style layers (fill-extrusion with selected/hover states)
LayerManager.addBuildingShell(floors)— rebuild building shellfloorDataManager.loadAndRenderFloor(currentFloorId)— re-render current floorPathRenderer.setTheme()— update route line colorsPathfindingController.renderer.updateFilters()— update route filters
Key Design
- In-place color updates — theme swaps do not recreate sources or layers
LayerManager.styleLayerIdstracks which layers need color updatesfill-extrusion-colorusescaseexpressions withfeature-statefor selected/hover- Mapbox style is fully replaced (
diff: false) because the basemap may be completely different
Important Files
theme.js— Theme definitions and color mapssrc/ui/ThemeController.js— Toggle button and event handlingsrc/layer-manager.js—setTheme(),reapplyThemeColors()script.js—handleThemeChange()orchestration
How It Connects
-
ThemeControlleris created lazily inscript.jsafter map init -
Theme change triggers a full style reload but preserves app state
-
LayerManagerre-applies colors to all existing layers -
FloorDataManagerre-renders the current floor with new colors -
PathRendererupdates route line colors -
Android WebView gets updated basemap style via
window.__INGUIDE_BASEMAP_STYLE__continue:[[]]
before:[[]]