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);