On the map as on the artboard: section titles as small caps on white (no gray bands), compact rows with a bold name, the on/off as the eye at the row's end (● on, ○ off) instead of a checkbox at its start; the map as one row with an Online | Offline switch, a Theme row (the topbar's night cycle), the legend as a row. The map's buttons in the artboard's three cards (zoom; compass, north lock, 3D, my position; measure, note, home). Topbar: the offline state as a pill (Offline ready / Online only), Drive filled. Status bar: the ground's height under the cursor once the mouse rests
This commit is contained in:
1 parent
d559f76b4a
commit
fc8564fe3b
3 files changed
+258
-14
No files matched your search
+36
-1
@@ -30,6 +30,7 @@ import HomeButton from "/vendor/npmap-home-button/home-button.esm.js";
|
||||
import OverviewMap from "/vendor/npmap-overview/overview.esm.js";
|
||||
import * as maplibregl from "/vendor/maplibre-gl/maplibre-gl.mjs";
|
||||
import { setupDriving } from "/js/driving.js";
|
||||
import { elevationAt } from "/js/dem.js";
|
||||
|
||||
const CENTER = [17.1077, 48.1486];
|
||||
const ZOOM = 13;
|
||||
@@ -286,11 +287,39 @@ map.addControl(new MeasureControl(), "top-right");
|
||||
// upload/new-folder buttons.
|
||||
if (isLoggedIn()) map.addControl(new NotesControl(), "top-right");
|
||||
map.addControl(new HomeButton({ bounds: SLOVAKIA_BOUNDS }), "top-right");
|
||||
// ...as the artboard's three cards: zoom; the view (compass, north lock, 3D,
|
||||
// my position); the tools (measure, note, home). Each control keeps its own
|
||||
// container (their popovers hang off it), the card only groups them.
|
||||
{
|
||||
const corner = map.getContainer().querySelector(".maplibregl-ctrl-top-right");
|
||||
const [nav, ...rest] = corner.children;
|
||||
const card = (...controls) => {
|
||||
const div = document.createElement("div");
|
||||
div.className = "maplibregl-ctrl map-card";
|
||||
div.append(...controls);
|
||||
corner.appendChild(div);
|
||||
return div;
|
||||
};
|
||||
const view = card(...rest.slice(0, 3));
|
||||
view.prepend(nav.querySelector(".maplibregl-ctrl-compass"));
|
||||
card(...rest.slice(3));
|
||||
}
|
||||
|
||||
// The status bar: the map's center (click to copy), the point under the
|
||||
// mouse, the zoom level, the scale.
|
||||
const cursorLabel = document.querySelector(".statusbar__cursor");
|
||||
map.on("mousemove", ({ lngLat }) => (cursorLabel.textContent = `Cursor ${formatCoords(lngLat.lat, lngLat.lng)}`));
|
||||
let terrainOffline = false; // set once /api/terrain-tiles answers (below)
|
||||
let elevationTimer = null;
|
||||
map.on("mousemove", ({ lngLat }) => {
|
||||
const at = `Cursor ${formatCoords(lngLat.lat, lngLat.lng)}`;
|
||||
cursorLabel.textContent = at;
|
||||
// the ground's height there, once the mouse rests a moment
|
||||
clearTimeout(elevationTimer);
|
||||
elevationTimer = setTimeout(async () => {
|
||||
const metres = await elevationAt(lngLat.lng, lngLat.lat, terrainOffline).catch(() => null);
|
||||
if (metres != null && cursorLabel.textContent === at) cursorLabel.textContent = `${at} · ${Math.round(metres)} m`;
|
||||
}, 150);
|
||||
});
|
||||
map.getCanvasContainer().addEventListener("mouseleave", () => (cursorLabel.textContent = ""));
|
||||
const zoomLabel = document.querySelector(".statusbar__zoom");
|
||||
const updateZoom = () => (zoomLabel.textContent = `Zoom ${map.getZoom().toFixed(1)}`);
|
||||
@@ -392,6 +421,9 @@ const NIGHT_MODES = {
|
||||
off: ["☀", "Night mode: off"],
|
||||
};
|
||||
const nightButton = document.querySelector(".topbar__night");
|
||||
// On the map's Theme row: the same cycle as the topbar's button
|
||||
const themeButton = document.querySelector(".onthemap-theme");
|
||||
themeButton.addEventListener("click", () => nightButton.click());
|
||||
const nightMap = new NightMap(map);
|
||||
// The base style's texture patterns (grass, scrub, military hatch) and the
|
||||
// peak triangle are drawn at runtime rather than shipped in a sprite
|
||||
@@ -431,6 +463,7 @@ const updateNight = () => {
|
||||
else delete document.documentElement.dataset.palette;
|
||||
nightMap.set(dark);
|
||||
[nightButton.textContent, nightButton.title] = NIGHT_MODES[nightMode] || NIGHT_MODES.auto;
|
||||
themeButton.textContent = `${{ auto: "Auto", on: "Night", dusk: "Dusk", off: "Day" }[nightMode] || "Auto"} ›`;
|
||||
};
|
||||
nightButton.addEventListener("click", () => {
|
||||
const modes = Object.keys(NIGHT_MODES);
|
||||
@@ -509,6 +542,7 @@ ready.push(fetch("/api/offline-tiles")
|
||||
offlineStatus.hidden = false;
|
||||
offlineStatus.classList.toggle("topbar__offline-status--ready", available);
|
||||
offlineStatus.title = available ? "Offline map data ready" : "No offline map data on this server";
|
||||
offlineStatus.textContent = available ? "Offline ready" : "Online only";
|
||||
})
|
||||
.catch(() => {
|
||||
// Backend check failed; keep the online style and leave the switch as
|
||||
@@ -519,6 +553,7 @@ ready.push(fetch("/api/offline-tiles")
|
||||
ready.push(fetch("/api/terrain-tiles")
|
||||
.then((response) => response.json())
|
||||
.then(({ available }) => {
|
||||
terrainOffline = available;
|
||||
overlaysControl.setHillshadeOfflineAvailable(available);
|
||||
overlaysControl.setShadowOfflineAvailable(available);
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user