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)
This commit is contained in:
1 parent
2c27bcd6bf
commit
637f739e18
1 file changed
+6
-1
+6
-1
@@ -484,8 +484,13 @@ let nightMode = "auto";
|
|||||||
try {
|
try {
|
||||||
nightMode = localStorage.getItem("nightMode") || "auto";
|
nightMode = localStorage.getItem("nightMode") || "auto";
|
||||||
} catch {}
|
} 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 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);
|
const dark = nightMode === "on" || (nightMode === "auto" && getPosition(new Date(), lat, lng).altitude < 0);
|
||||||
document.documentElement.classList.toggle("night", dark);
|
document.documentElement.classList.toggle("night", dark);
|
||||||
nightMap.set(dark);
|
nightMap.set(dark);
|
||||||
|
|||||||
Reference in new issue
Block a user