Sun & moon chart: click the topbar's sun readout
A horizon-style chart drawn from the vendored suncalc, so fully offline: real sun and moon altitude over the 24 h around solar noon, sunrise/ sunset lines, dawn/noon/dusk on the time axis, the moon in its current phase, plus moonrise/set, phase and current sun/moon position below. Polar day/night now shows as a label instead of hiding the readout.
This commit is contained in:
1 parent
cf483d183c
commit
ca2e67599b
4 files changed
+240
-3
No files matched your search
+20
-1
@@ -17,7 +17,7 @@ import { LocateControl } from "/js/locate.js";
|
||||
import { SearchControl } from "/js/search.js";
|
||||
import { OfflineDataControl } from "/js/offline_data.js";
|
||||
import { LAYERS_ICON, WAYPOINT_ICON, SUNRISE_ICON, SUNSET_ICON, PENDING_ICON } from "/js/icons.js";
|
||||
import { formatCoords, formatSunInfo } from "/js/sun.js";
|
||||
import { formatCoords, formatSunInfo, sunChartHtml } from "/js/sun.js";
|
||||
import { notifySidePanelOpen, onlyOneSidePanelOpen } from "/js/panels.js";
|
||||
import { isLoggedIn } from "/js/auth.js";
|
||||
import { DebugControl } from "/js/debug.js";
|
||||
@@ -518,11 +518,17 @@ coordsLabel.addEventListener("click", async () => {
|
||||
// plus a periodic tick so the "Xh Ym to sunset" countdown keeps counting
|
||||
// down even while the map sits still.
|
||||
const sunLabel = document.querySelector(".topbar__sun");
|
||||
const sunChart = document.querySelector(".sun-chart");
|
||||
const updateSun = () => {
|
||||
const { lng, lat } = map.getCenter();
|
||||
if (!sunChart.hidden) sunChart.innerHTML = sunChartHtml(lat, lng);
|
||||
const info = formatSunInfo(lat, lng);
|
||||
sunLabel.hidden = info === null;
|
||||
if (!info) return;
|
||||
if (info.polar) {
|
||||
sunLabel.innerHTML = `<span class="topbar__group"><span class="topbar__icon">${SUNRISE_ICON}</span><span>${info.polar}</span></span>`;
|
||||
return;
|
||||
}
|
||||
|
||||
const countdownGroup = info.countdown
|
||||
? `<span class="topbar__group"><span class="topbar__icon">${PENDING_ICON}</span><span>${info.countdown}</span></span>`
|
||||
@@ -532,6 +538,19 @@ const updateSun = () => {
|
||||
`<span class="topbar__group"><span class="topbar__icon">${SUNSET_ICON}</span><span>${info.sunset}</span></span>` +
|
||||
countdownGroup;
|
||||
};
|
||||
// Click opens the horizon-style sun & moon chart (sun.js), kept in sync by
|
||||
// the same moveend/minute tick as the label itself.
|
||||
sunLabel.addEventListener("click", (event) => {
|
||||
event.stopPropagation();
|
||||
sunChart.hidden = !sunChart.hidden;
|
||||
updateSun();
|
||||
});
|
||||
document.addEventListener("click", (event) => {
|
||||
if (!sunChart.contains(event.target)) sunChart.hidden = true;
|
||||
});
|
||||
document.addEventListener("keydown", (event) => {
|
||||
if (event.key === "Escape") sunChart.hidden = true;
|
||||
});
|
||||
updateSun();
|
||||
map.on("moveend", updateSun);
|
||||
setInterval(updateSun, 60000);
|
||||
|
||||
Reference in new issue
Block a user