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/vents.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 viewer/js/vents.js (limited to 'viewer/js/vents.js') diff --git a/viewer/js/vents.js b/viewer/js/vents.js new file mode 100644 index 0000000..34eedfc --- /dev/null +++ b/viewer/js/vents.js @@ -0,0 +1,25 @@ +// vents.js — hydrothermal vents as map markers (pure): clusters on a lat/lon grid sized to ≈ px screen pixels +import { R_KM } from './geo.js'; + +const FLOW = ['weak flow', 'steady flow', 'strong flow']; + +export const zoomBucket = kmPerPx => Math.floor(Math.log(kmPerPx) / Math.log(1.5)); + +export function clusterVents(vents, kmPerPx, px = 40) { + const deg = Math.max(1e-6, (kmPerPx * px * 180) / (Math.PI * R_KM)); + const cells = new Map(); + for (const v of vents) { + const key = `${Math.floor(v.lat / deg)}:${Math.floor(v.lon / deg)}`; + const c = cells.get(key); + if (c) { + c.lat += v.lat; + c.lon += v.lon; + c.n++; + } else cells.set(key, { lat: v.lat, lon: v.lon, n: 1, v }); + } + return [...cells.values()].map(c => (c.n === 1 ? c : { lat: c.lat / c.n, lon: c.lon / c.n, n: c.n, v: null })); +} + +export function ventText(v, types, minerals) { + return `${types[v.type] ?? 'vent'} · ${Math.round(v.temp_c)} °C · ${minerals[v.mineral] ?? '?'} · ${FLOW[v.flow] ?? ''}`; +} -- cgit