From 637f739e18a49e45c2eef26f0f2d6ec1e5ebf040 Mon Sep 17 00:00:00 2001 From: Roman Priesol Date: Tue, 24 Nov 2026 13:21:38 +0100 Subject: [PATCH] Auto night mode: below zoom 5 keep the last real place for the sun check (zoomed out to the world the map center can sit in another time zone's night) --- public/js/map.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/public/js/map.js b/public/js/map.js index 9c468e5..c074cd8 100644 --- a/public/js/map.js +++ b/public/js/map.js @@ -484,8 +484,13 @@ let nightMode = "auto"; try { nightMode = localStorage.getItem("nightMode") || "auto"; } catch {} +// The sun is checked where the map looks; zoomed out to a continent or +// the world the center is meaningless (night on the other side of the +// globe), so below zoom 5 the last real place is kept. +let sunAt = map.getCenter(); const updateNight = () => { - const { lng, lat } = map.getCenter(); + if (map.getZoom() >= 5) sunAt = map.getCenter(); + const { lng, lat } = sunAt; const dark = nightMode === "on" || (nightMode === "auto" && getPosition(new Date(), lat, lng).altitude < 0); document.documentElement.classList.toggle("night", dark); nightMap.set(dark);