diff options
Diffstat (limited to 'viewer/js/hover.js')
| -rw-r--r-- | viewer/js/hover.js | 16 |
1 files changed, 16 insertions, 0 deletions
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(' · '); +} |
