import { render } from 'preact' import { applyData, liveLoad, setStatus } from './actions' import { App } from './components/App' import { parseLoc } from './geo' import { t } from './i18n' import { isOwnHash, readHash } from './persist' import { loadSample } from './sample-data' import { DEFAULT_LOC, lastLoc, locText, radius } from './state' import type { LatLon } from './types' import './style.css' const fmt = (p: LatLon) => `${p.lat.toFixed(6)}, ${p.lon.toFixed(6)}` /** Load the location in the URL hash (shared link), if any. Returns false if there is none. */ function loadFromHash(): boolean { const h = readHash() if (!h) return false if (h.r && h.r >= 100 && h.r <= 700) radius.value = h.r locText.value = fmt(h) liveLoad(h, true) return true } render(, document.getElementById('root')!) // Show the built-in example immediately, then replace it with live data: // shared link → last visited area → default location. applyData(loadSample(), 14.968678, 50.8171633) setStatus(() => t('st_init')) if (!loadFromHash()) { const last = lastLoc.value if (last) locText.value = fmt(last) const p = last ?? parseLoc(DEFAULT_LOC) if (p) liveLoad(p, true) } window.addEventListener('hashchange', () => { if (!isOwnHash()) loadFromHash() })