Night map palette instead of inverting it: dark blue-gray ground, roads a step lighter, muted ochre motorways, light-gray labels on dark halos, switched live with setPaintProperty (NightMap); raster overlays dimmed, own track/point colors kept; the UI panels keep the invert filter for now
CI / check (push) Successful in 18s
CI / deploy (push) Successful in 17s

This commit is contained in:
randy committed 2026-11-23 16:23:35 +01:00
1 parent 80d0039148
commit 31b27a0852
4 files changed
+204 -11

No files matched your search

+7 -3
View File
@@ -23,7 +23,7 @@ import { getPosition } from "/vendor/suncalc/suncalc.js";
import { notifySidePanelOpen, onlyOneSidePanelOpen, setupSidePanelModes } from "/js/panels.js";
import { isLoggedIn } from "/js/auth.js";
import { DebugControl } from "/js/debug.js";
import { patchOnlineStyle } from "/js/map_themes.js";
import { patchOnlineStyle, NightMap } from "/js/map_themes.js";
import { offerSharedFiles } from "/js/share_import.js";
import HomeButton from "/vendor/npmap-home-button/home-button.esm.js";
import OverviewMap from "/vendor/npmap-overview/overview.esm.js";
@@ -326,9 +326,10 @@ class RotationLockControl {
}
}
const initialStyle = onlineStyle();
const map = new MaplibreMap({
container: "map",
style: onlineStyle(),
style: initialStyle,
center: CENTER,
zoom: ZOOM,
// MapLibre's built-in Hash control: keeps #map=zoom/lat/lon in the URL in
@@ -471,6 +472,8 @@ setInterval(updateSun, 60000);
// topbar button cycles the three, remembered per device.
const NIGHT_MODES = { auto: ["◐", "Night mode: automatic (after sunset)"], on: ["☾", "Night mode: on"], off: ["☀", "Night mode: off"] };
const nightButton = document.querySelector(".topbar__night");
const nightMap = new NightMap(map);
nightMap.base(initialStyle);
let nightMode = "auto";
try {
nightMode = localStorage.getItem("nightMode") || "auto";
@@ -479,6 +482,7 @@ const updateNight = () => {
const { lng, lat } = map.getCenter();
const dark = nightMode === "on" || (nightMode === "auto" && getPosition(new Date(), lat, lng).altitude < 0);
document.documentElement.classList.toggle("night", dark);
nightMap.set(dark);
[nightButton.textContent, nightButton.title] = NIGHT_MODES[nightMode] || NIGHT_MODES.auto;
};
nightButton.addEventListener("click", () => {
@@ -540,7 +544,7 @@ map.addControl(mapLayersButton, "top-left");
function applyStyle(name) {
layerToggle.setActive(name);
map.setStyle(name === "offline" ? offlineStyle() : onlineStyle());
map.setStyle(nightMap.base(name === "offline" ? offlineStyle() : onlineStyle()));
}
// If a local PMTiles file is present, prefer it as the default style — its