From 3443c1c65e9f1753e1e656b35d08416c1fa298f2 Mon Sep 17 00:00:00 2001 From: godosa Date: Wed, 7 Oct 2026 00:14:38 +0200 Subject: worldmap-viewer: initial public history --- viewer/js/hover.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 viewer/js/hover.js (limited to 'viewer/js/hover.js') diff --git a/viewer/js/hover.js b/viewer/js/hover.js new file mode 100644 index 0000000..5fab5e5 --- /dev/null +++ b/viewer/js/hover.js @@ -0,0 +1,16 @@ +// hover.js — status-bar text for the cell under the resting pointer (pure) +import { distanceKm } from './geo.js'; + +export const canReuse = (cell, p, detail) => // same cell for sure: no need to ask the server again + !detail && !!cell?.center && distanceKm(p, { lat: cell.center[0], lon: cell.center[1] }) < cell.inner_km; +const int = v => Math.round(v).toLocaleString('en-US'); + +export function hoverText(cell, detail = false) { // detail: procedural tiles are showing, so show their height + const f = Object.fromEntries(cell.fields.map(x => [x.key, x])); + const z = ((detail && f.z_detail_m) || f.z_surface_m)?.value ?? 0; + if (f.ocean?.value) return `sea, ${int(Math.max(0, -z))} m deep`; + const parts = [`${int(z)} m`]; + if (f.lake?.value) parts.push('lake'); + if (f.holdridge?.text) parts.push(f.holdridge.text); + return parts.join(' · '); +} -- cgit