Files
gods-eye-view/src/data/bhoteKoshiLocator.js
T
manjunath22466 7312280817 fix(earthquakes): address review follow-ups on click arbitration
A drifting touch tap or a cockpit-mode tap on a fire, quake or vessel card
beside an aircraft did nothing: the cards deferred to the aircraft, whose
click handler ignores such taps. Pick owners can now declare the clicks
they ignore (registerPickOwner(..., { declinesClick })); flights and
military decline a drag or a cockpit tap and CCTV declines any click that
is not clean, so a card over them keeps that tap.

Also from review:
- the selected quake's contour rings sit on the ground the disc is draped
  on, re-read through the heights service while they paint;
- a label's fly-to frames the whole disc for large quakes;
- a quake that ages out of the feed clears its selection as evicted;
- id-less quakes are named by their content, not their row;
- the Bhote Koshi trigger-record callout opens its source on a click, as
  its keyboard action does, and yields like the other cards;
- the card's place line is cut to 48 characters, its link hint shows only
  with an opener, and its accessible name carries depth, place and time; a
  link-less card's click and keyboard action fly to the quake;
- camera trace comparison scales its tolerance with the value and wraps
  heading and roll.
2026-11-18 19:19:41 +05:30

1348 lines
43 KiB
JavaScript

import {
clearOverlaySource,
hitTestWorldOverlay,
setOverlayEntries,
} from '../overlays/worldOverlay.js';
import { inputFor } from '../input/dispatcher.js';
import { isActedOnByOtherLayer, resolvePickId } from './pickRegistry.js';
import { isTrackingSelectionGesture } from './trackingClickGesture.js';
import { governorRequestRender } from '../renderGovernor.js';
import { drawOf, findCamera } from '../render/rendererOf.js';
import { hexColor } from '../render/color.js';
import { fromDegrees } from '../geo/ellipsoid.js';
import { toRadians } from '../geo/vector.js';
import { lengthFraction } from '../geo/polyline.js';
import {
BHOTE_KOSHI_LOCATOR_CREDIT,
registerDynamicCredit,
showOsmCredit,
hideOsmCredit,
} from './dataCredits.js';
import { BHOTE_KOSHI_FLOOD_PATH } from './bhoteKoshiFloodPath.js';
import { INCIDENT_OVERVIEW_PLACES } from './bhoteKoshiIncidentPlaces.js';
import { t, msg, getLocale, isolate } from '../i18n/index.js';
const BHOTE_KOSHI_LOCATOR_LAYER_ID = 'bhote-koshi-locator';
export const BHOTE_KOSHI_LOCATOR_OVERLAY_SOURCE_ID =
'bhote-koshi-locator-callout';
export const NEPAL_CONTEXT_PRESENTATION = 'nepal-context';
export const BHOTE_KOSHI_REGIONAL_PRESENTATION = 'bhote-koshi-regional';
export const BHOTE_KOSHI_CITY_CONTEXT_PRESENTATION = 'bhote-koshi-city-context';
export const BHOTE_KOSHI_INCIDENT_PLACES_PRESENTATION =
'bhote-koshi-incident-places';
export const BHOTE_KOSHI_FLOOD_PATH_PRESENTATION = 'bhote-koshi-flood-path';
export const BHOTE_KOSHI_PATH_OVERVIEW_PRESENTATION =
'bhote-koshi-path-overview';
export const BHOTE_KOSHI_TRIGGER_RECORD_PRESENTATION =
'bhote-koshi-trigger-record';
const LEGACY_PATH_BORDER_PRESENTATION = 'bhote-koshi-path-border';
const BORDER_DRAW_DURATION_MS = 2400;
const BORDER_START_DELAY_MS = 700;
const INCIDENT_CALLOUT_GAP_MS = 200;
const CALLOUT_REVEAL_DURATION_MS = 1200;
const CALLOUT_PULSE_DURATION_MS = 1800;
const CALLOUT_RING_MIN_SIZE_PX = 16;
const CALLOUT_RING_SIZE_RANGE_PX = 14;
const CITY_CALLOUT_START_DELAY_MS = 350;
const CITY_CALLOUT_STAGGER_MS = 220;
const CITY_CALLOUT_REVEAL_MS = 500;
const PLACE_CALLOUT_START_DELAY_MS = 350;
const PLACE_CALLOUT_STAGGER_MS = 650;
const PLACE_CALLOUT_REVEAL_MS = 520;
const FLOOD_PATH_START_DELAY_MS = 250;
const FLOOD_PATH_DRAW_DURATION_MS = 4000;
const TRIGGER_APPROACH_ARM_MS = 500;
const TRIGGER_APPROACH_DURATION_SEC = 4.6;
const TRIGGER_ORBIT_DURATION_SEC = 2.8;
const TRIGGER_SOURCE_URL =
'https://earthquake.usgs.gov/earthquakes/eventpage/us7000tbwb/executive';
// Descriptive pin titles translate at display (same entries as the event
// panel); place names stay Latin, anything else shows as authored.
const PLACE_TITLE_TEXT = new Map(
[
msg('Collapse viewpoint'),
msg('Dammed lake'),
msg('Second landslide'),
msg('Border gate'),
msg('Dandagaun viewpoint'),
msg('Bidur bridge'),
msg('Devighat bridge'),
].map((text) => [text.toUpperCase(), text]),
);
function placeTitle(title) {
const text = PLACE_TITLE_TEXT.get(title);
// Isolated: the card draws left to right after its "11 · " counter, so in
// Arabic a translated title with a Latin place name («نقطة الإطلالة في
// DANDAGAUN») must keep its own right-to-left order.
return text ? isolate(t(text).toLocaleUpperCase(getLocale())) : title;
}
const INCIDENT = Object.freeze({
lat: 28.3632333,
lon: 85.4423639,
heightM: 5200,
title: msg('BHOTE KOSHI FLOOD INCIDENT'),
subtitle: msg('NEPAL · 26 AUG 2026'),
});
const TRIGGER_RECORD = Object.freeze({
lat: 28.271,
lon: 85.515,
heightM: 4200,
title: msg('USGS INITIAL REPORT'),
details: Object.freeze([
msg('26 AUG 2026 · 08:37 NPT'),
msg('28.2710° N · 85.5150° E'),
msg('INITIAL M4.4 · RECLASSIFIED M5.2 LANDSLIDE'),
msg('USGS EVENT us7000tbwb · OPEN SOURCE'),
]),
});
const TRIGGER_APPROACH_CAMERA = Object.freeze({
lat: 28.368,
lon: 85.473,
alt: 10526,
heading: 156,
pitch: -44,
roll: 0,
});
const TRIGGER_ORBIT_CAMERA = Object.freeze({
lat: 28.3769,
lon: 85.4923,
alt: 10526,
heading: 168,
pitch: -44,
roll: 0,
});
const NEPAL = Object.freeze({
lat: 28.3949,
lon: 84.124,
heightM: 6800,
// i18n-ignore: country name, shown as is
title: 'NEPAL',
});
const NEARBY_CITIES = Object.freeze([
Object.freeze({
id: 'kathmandu',
// i18n-ignore: city name
title: 'KATHMANDU',
lat: 27.7017,
lon: 85.3206,
heightM: 3600,
placement: 'left',
}),
Object.freeze({
id: 'bhaktapur',
// i18n-ignore: city name
title: 'BHAKTAPUR',
lat: 27.673,
lon: 85.43,
heightM: 3400,
placement: 'right',
}),
Object.freeze({
id: 'dhulikhel',
// i18n-ignore: city name
title: 'DHULIKHEL',
lat: 27.6221,
lon: 85.5428,
heightM: 3600,
placement: 'right-lower',
}),
]);
const BORDER_ACCENT = '#20e7f2';
const INCIDENT_ACCENT = '#ffad55';
// Each layer's draw sets have ids of their own.
let layerSerial = 0;
const DEFAULT_OVERLAY_HOST = Object.freeze({
setEntries: setOverlayEntries,
clearSource: clearOverlaySource,
});
// Applications supply their boundary resolver; the layer has no server-route dependency.
const DEFAULT_BOUNDARY_RESOLVER = async () => null;
function abortError() {
return new DOMException(
'Bhote Koshi locator activation cancelled',
'AbortError',
);
}
function normalizePresentation(value) {
if (value === NEPAL_CONTEXT_PRESENTATION) return NEPAL_CONTEXT_PRESENTATION;
if (value === BHOTE_KOSHI_CITY_CONTEXT_PRESENTATION) {
return BHOTE_KOSHI_CITY_CONTEXT_PRESENTATION;
}
if (value === BHOTE_KOSHI_INCIDENT_PLACES_PRESENTATION) {
return BHOTE_KOSHI_INCIDENT_PLACES_PRESENTATION;
}
if (value === BHOTE_KOSHI_FLOOD_PATH_PRESENTATION) {
return BHOTE_KOSHI_FLOOD_PATH_PRESENTATION;
}
if (
value === BHOTE_KOSHI_PATH_OVERVIEW_PRESENTATION ||
value === LEGACY_PATH_BORDER_PRESENTATION
) {
return BHOTE_KOSHI_PATH_OVERVIEW_PRESENTATION;
}
if (value === BHOTE_KOSHI_TRIGGER_RECORD_PRESENTATION) {
return BHOTE_KOSHI_TRIGGER_RECORD_PRESENTATION;
}
return BHOTE_KOSHI_REGIONAL_PRESENTATION;
}
function presentationUsesBoundary(value) {
return (
value === BHOTE_KOSHI_REGIONAL_PRESENTATION ||
value === BHOTE_KOSHI_CITY_CONTEXT_PRESENTATION
);
}
function smoothstep(from, to, value) {
if (to <= from) return value >= to ? 1 : 0;
const amount = Math.max(0, Math.min(1, (value - from) / (to - from)));
return amount * amount * (3 - 2 * amount);
}
/** Resolve the persistent text callout's dot, leader, and card entrance. */
export function anchoredCalloutPresentation(elapsedMs) {
const progress = Math.max(
0,
Math.min(1, Number(elapsedMs) / CALLOUT_REVEAL_DURATION_MS || 0),
);
const contentAlpha = smoothstep(0.34, 1, progress);
return {
alpha: smoothstep(0, 0.18, progress),
leaderProgress: smoothstep(0.1, 0.52, progress),
contentAlpha,
scale: 0.96 + contentAlpha * 0.04,
};
}
/**
* How much of a line's length is drawn when it is revealed vertex by
* vertex: `progress` of its vertices (the head between two of them), as a
* fraction of its length, for the draw port's `revealFraction`.
* @param {Array<{x: number, y: number, z: number}>} positions
* @param {number} progress 0..1
*/
export function revealLengthFraction(positions, progress) {
if (!Array.isArray(positions) || positions.length < 2) return 0;
const clamped = Math.max(0, Math.min(1, Number(progress) || 0));
if (clamped >= 1) return 1;
if (clamped <= 0) return 0;
const scaled = clamped * (positions.length - 1);
const index = Math.floor(scaled);
return lengthFraction(positions, index, scaled - index);
}
/** Close a region ring without duplicating an already-closed final vertex. */
export function closeRegionRing(ring) {
if (!Array.isArray(ring) || ring.length < 3) return [];
const normalized = ring
.map((point) => [Number(point?.[0]), Number(point?.[1])])
.filter(([lon, lat]) => Number.isFinite(lon) && Number.isFinite(lat));
if (normalized.length < 3) return [];
const [firstLon, firstLat] = normalized[0];
const [lastLon, lastLat] = normalized[normalized.length - 1];
if (firstLon !== lastLon || firstLat !== lastLat)
normalized.push([firstLon, firstLat]);
return normalized;
}
/** Return the largest exterior ring from a Polygon or MultiPolygon GeoJSON. */
export function largestGeoJsonRing(geojson) {
const polygons =
geojson?.type === 'Polygon'
? [geojson.coordinates]
: geojson?.type === 'MultiPolygon'
? geojson.coordinates
: [];
const rings = polygons
.map((polygon) => polygon?.[0])
.filter((ring) => Array.isArray(ring) && ring.length >= 3);
return rings.sort((a, b) => b.length - a.length)[0] || [];
}
/**
* Lightweight scene overlay for the multi-shot Nepal incident setup. It uses
* the local OpenStreetMap boundary proxy and deliberately avoids the full
* reconstruction layer's imagery, panel, playback, and camera ownership.
*/
export function createBhoteKoshiLocatorLayer({
boundaryResolver = DEFAULT_BOUNDARY_RESOLVER,
overlayHost = DEFAULT_OVERLAY_HOST,
requestRender = governorRequestRender,
now = () => performance.now(),
scheduleFrame = (callback) => requestAnimationFrame(callback),
cancelFrame = (handle) => cancelAnimationFrame(handle),
scheduleDelay = (callback, delayMs) => setTimeout(callback, delayMs),
cancelDelay = (handle) => clearTimeout(handle),
input = inputFor,
hitTest = hitTestWorldOverlay,
} = {}) {
let _viewer = null;
// The globe click that opens an actionable callout of ours on top.
let _removeClick = null;
const _serial = ++layerSerial;
// Whether the layer draws: from enable until it is let go.
let _drawing = false;
let _sets = null;
// What the presentation draws, each item worked out for the time now:
// pulsing halos, lines revealed as they grow, and the country fill, drawn
// once it is due.
let _halos = [];
let _lines = [];
let _fill = null;
let _fillShown = false;
// Each line's reveal and show as last drawn.
const _drawnLines = new Map();
// Each halo's look as last drawn.
const _drawnHalos = new Map();
let _enabled = false;
let _boundaryReady = false;
let _boundaryResolved = false;
let _boundaryRing = null;
let _generation = 0;
let _presentation = BHOTE_KOSHI_REGIONAL_PRESENTATION;
let _calloutPulseFrame = null;
let _triggerApproachTimer = null;
let _removeTriggerMoveStart = null;
let _removeTriggerMoveEnd = null;
let _triggerApproachInFlight = false;
let _triggerApproachAttempt = null;
let _triggerCalloutStartedAt = Number.POSITIVE_INFINITY;
let _approachEnabled = false;
let _overlayEntries = [];
let _placeRevealMoving = false;
let _placeRevealSettledAt = Number.POSITIVE_INFINITY;
function queueOverlayEntry(entry) {
_overlayEntries.push(entry);
}
function publishOverlayEntries({ moving = false } = {}) {
overlayHost.setEntries(
BHOTE_KOSHI_LOCATOR_OVERLAY_SOURCE_ID,
_overlayEntries,
{
cohortLimit: Math.max(1, _overlayEntries.length),
collisionCapacity: Math.max(1, _overlayEntries.length),
moving,
},
);
}
function clearTriggerApproach({ preserveCallout = false } = {}) {
// Revoke ownership before cancelFlight can synchronously deliver callbacks.
_triggerApproachAttempt = null;
if (_triggerApproachTimer !== null) cancelDelay(_triggerApproachTimer);
_triggerApproachTimer = null;
_removeTriggerMoveStart?.();
_removeTriggerMoveEnd?.();
_removeTriggerMoveStart = null;
_removeTriggerMoveEnd = null;
const wasInFlight = _triggerApproachInFlight;
_triggerApproachInFlight = false;
if (wasInFlight) findCamera(_viewer)?.cancelFlight();
if (!preserveCallout) _triggerCalloutStartedAt = Number.POSITIVE_INFINITY;
}
function stopAnimations() {
if (_calloutPulseFrame !== null) cancelFrame(_calloutPulseFrame);
_calloutPulseFrame = null;
_placeRevealMoving = false;
_placeRevealSettledAt = Number.POSITIVE_INFINITY;
clearTriggerApproach();
}
function removeDrawn() {
stopAnimations();
overlayHost.clearSource(BHOTE_KOSHI_LOCATOR_OVERLAY_SOURCE_ID);
if (_sets) for (const set of Object.values(_sets)) set.dispose();
_sets = null;
_drawing = false;
resetDrawn();
}
function resetDrawn() {
_halos = [];
_lines = [];
_fill = null;
_fillShown = false;
_drawnLines.clear();
_drawnHalos.clear();
}
/** The layer's draw sets, made on first use: fill under lines under halos. */
function drawSets() {
if (_sets) return _sets;
const draw = drawOf(_viewer);
const prefix = `${BHOTE_KOSHI_LOCATOR_LAYER_ID}:${_serial}`;
// Presentation only: clicks go through to what is under them.
_sets = {
fill: draw.shapes({ id: `${prefix}:fill`, pickable: false }),
lines: draw.lines({ id: `${prefix}:lines`, pickable: false }),
halos: draw.points({ id: `${prefix}:halos`, pickable: false }),
};
return _sets;
}
/** Draw the presentation as it now stands, in place of what was drawn. */
function commitDrawn() {
const sets = drawSets();
_drawnLines.clear();
_fillShown = Boolean(_fill?.visible());
sets.fill.set(_fillShown ? [_fill.item] : []);
sets.lines.set(
_lines.map((line) => {
const item = line();
_drawnLines.set(item.id, lineKey(item));
return item;
}),
);
_drawnHalos.clear();
sets.halos.set(
_halos.map((halo) => {
const item = halo();
_drawnHalos.set(item.id, haloKey(item));
return item;
}),
);
}
const haloKey = (item) =>
`${item.pixelSize}:${item.color}:${item.outlineColor}:${item.show}`;
const lineKey = (item) => `${item.revealFraction}:${item.show !== false}`;
/**
* Bring what is drawn to the time now: halos pulse, lines that grew or
* showed are changed in place, and the fill shows once it is due.
*/
function syncDrawn() {
if (!_drawing || !_sets) return;
if (!_fillShown && _fill?.visible()) {
_fillShown = true;
_sets.fill.set([_fill.item]);
}
const changed = [];
for (const line of _lines) {
const item = line();
const key = lineKey(item);
if (_drawnLines.get(item.id) === key) continue;
_drawnLines.set(item.id, key);
changed.push(item);
}
if (changed.length) _sets.lines.upsert(changed);
const pulsed = [];
for (const halo of _halos) {
const item = halo();
const key = haloKey(item);
if (_drawnHalos.get(item.id) === key) continue;
_drawnHalos.set(item.id, key);
pulsed.push(item);
}
if (pulsed.length) _sets.halos.upsert(pulsed);
}
/**
* A pulsing halo point: `progress()` (0..1) sizes it and fades its fill
* and ring (`fillAlpha`, `ringAlpha`), shown while `visible()`.
*/
function addHalo({
id,
subject,
color,
visible,
progress,
fillAlpha,
ringAlpha,
scaleByDistance,
}) {
const pos = { lon: subject.lon, lat: subject.lat, height: subject.heightM };
_halos.push(() => {
const p = progress();
return {
id,
pos,
pixelSize: CALLOUT_RING_MIN_SIZE_PX + CALLOUT_RING_SIZE_RANGE_PX * p,
color: hexColor(color, fillAlpha(p)),
outlineColor: hexColor(color, ringAlpha(p)),
outlineWidth: 2,
disableDepthTest: Number.POSITIVE_INFINITY,
scaleByDistance,
show: visible(),
};
});
}
/**
* A draped line revealed vertex by vertex as `progress()` runs 0..1,
* shown while `visible()`.
*/
function addRevealedLine({
id,
positions,
widthPx,
color,
progress,
visible,
}) {
_lines.push(() => ({
id,
positions,
widthPx,
mode: 'draped',
clampTo: 'both',
style: { kind: 'solid', color },
revealFraction: revealLengthFraction(positions, progress()),
show: visible(),
}));
}
function addCallout(
subject,
color,
{
labelPlacement = 'right',
sequenceStartedAt = now(),
visibleAfterMs = 0,
showAnchor = true,
} = {},
) {
const position = fromDegrees(subject.lon, subject.lat, subject.heightM);
const visibleAt = sequenceStartedAt + visibleAfterMs;
const isVisible = () => now() >= visibleAt;
const pulseProgress = () => {
const elapsed = Math.max(0, now() - visibleAt);
return (elapsed % CALLOUT_PULSE_DURATION_MS) / CALLOUT_PULSE_DURATION_MS;
};
if (showAnchor) {
addHalo({
id: `${subject === INCIDENT ? 'bhote-koshi-incident' : 'nepal-context'}-halo`,
subject,
color,
visible: isVisible,
progress: pulseProgress,
fillAlpha: (p) => (isVisible() ? 0.14 * (1 - p) : 0),
ringAlpha: (p) => (isVisible() ? 0.08 + 0.72 * (1 - p) : 0),
scaleByDistance: {
near: 250000,
nearValue: 0.8,
far: 25000000,
farValue: 1.35,
},
});
}
const presentation = () => anchoredCalloutPresentation(now() - visibleAt);
if (subject === INCIDENT) {
queueOverlayEntry({
id: 'bhote-koshi-incident-callout',
position,
variant: 'card',
paintLane: 'thumbnail',
title: t(subject.title),
details: [t(subject.subtitle)],
accent: INCIDENT_ACCENT,
sourceAlpha: () => presentation().alpha,
presentationScale: () => presentation().scale,
leaderProgress: () => presentation().leaderProgress,
contentAlpha: () => presentation().contentAlpha,
anchorDot: true,
leaderStyle: 'elbow',
priority: 1_000_000,
protected: true,
active: true,
collisionGroup: 'ambient-card',
zIndex: 60,
minDistance: 0,
maxDistance: 5_000_000,
distanceFadeStartRatio: 0.9,
distanceScale: {
near: 1200,
nearValue: 1,
far: 4_000_000,
farValue: 0.78,
},
edgeFade: 'none',
horizonCull: true,
terrainOcclusion: false,
gapPx: 36,
leaderOffsetPx: 4,
placement: 'right',
});
} else {
const labelOnLeft = labelPlacement === 'left';
queueOverlayEntry({
id: 'nepal-context-callout',
position,
variant: 'label',
paintLane: 'ambient-label',
title: subject.title,
details: subject.subtitle ? [subject.subtitle] : [],
accent: BORDER_ACCENT,
sourceAlpha: () => presentation().alpha,
presentationScale: () => presentation().scale,
leaderProgress: () => presentation().leaderProgress,
contentAlpha: () => presentation().contentAlpha,
anchorDot: showAnchor,
leaderStyle: 'elbow',
priority: 900_000,
protected: true,
active: true,
collisionGroup: 'nepal-locator-label',
zIndex: 48,
minDistance: 0,
maxDistance: 25_000_000,
distanceFadeStartRatio: 0.9,
distanceScale: {
near: 250000,
nearValue: 1.05,
far: 25000000,
farValue: 0.72,
},
edgeFade: 'none',
horizonCull: true,
terrainOcclusion: false,
gapPx: 18,
placement: labelOnLeft ? 'left' : 'right',
});
}
}
function startCalloutAnimation() {
const generation = _generation;
const pulseFrame = () => {
if (!_enabled || generation !== _generation) return;
if (_placeRevealMoving && now() >= _placeRevealSettledAt) {
_placeRevealMoving = false;
_placeRevealSettledAt = Number.POSITIVE_INFINITY;
publishOverlayEntries();
}
syncDrawn();
requestRender('bhote-koshi-locator-callout-pulse');
_calloutPulseFrame = scheduleFrame(pulseFrame);
};
_calloutPulseFrame = scheduleFrame(pulseFrame);
}
function addIncidentCallout(sequenceStartedAt, visibleAfterMs = 0) {
addCallout(INCIDENT, INCIDENT_ACCENT, {
sequenceStartedAt,
visibleAfterMs,
});
}
function addTriggerRecordCallout() {
const position = fromDegrees(
TRIGGER_RECORD.lon,
TRIGGER_RECORD.lat,
TRIGGER_RECORD.heightM,
);
const isVisible = () => now() >= _triggerCalloutStartedAt;
const presentation = () =>
anchoredCalloutPresentation(now() - _triggerCalloutStartedAt);
const pulseProgress = () => {
if (!isVisible()) return 0;
return (
((now() - _triggerCalloutStartedAt) % CALLOUT_PULSE_DURATION_MS) /
CALLOUT_PULSE_DURATION_MS
);
};
addHalo({
id: 'bhote-koshi-trigger-record-halo',
subject: TRIGGER_RECORD,
color: INCIDENT_ACCENT,
visible: isVisible,
progress: pulseProgress,
fillAlpha: (p) => 0.16 * (1 - p),
ringAlpha: (p) => (isVisible() ? 0.08 + 0.78 * (1 - p) : 0),
scaleByDistance: {
near: 3000,
nearValue: 1,
far: 250000,
farValue: 0.82,
},
});
queueOverlayEntry({
id: 'bhote-koshi-trigger-record-callout',
position,
variant: 'card',
paintLane: 'thumbnail',
title: t(TRIGGER_RECORD.title),
details: TRIGGER_RECORD.details.map((line) => t(line)),
accent: INCIDENT_ACCENT,
sourceAlpha: () => presentation().alpha,
presentationScale: () => presentation().scale,
leaderProgress: () => presentation().leaderProgress,
contentAlpha: () => presentation().contentAlpha,
anchorDot: true,
leaderStyle: 'elbow',
priority: 1_000_000,
protected: true,
active: true,
interactive: true,
accessibilityLabel: t(
'Open the USGS initial report for the 26 August 2026 Nepal landslide',
),
activate: () => {
const opened = window.open(
TRIGGER_SOURCE_URL,
'_blank',
'noopener,noreferrer',
);
if (opened) opened.opener = null;
},
collisionGroup: 'ambient-card',
zIndex: 60,
minDistance: 0,
maxDistance: 1_000_000,
distanceFadeStartRatio: 0.92,
distanceScale: { near: 1200, nearValue: 1, far: 800000, farValue: 0.82 },
edgeFade: 'none',
horizonCull: true,
terrainOcclusion: false,
gapPx: 34,
leaderOffsetPx: 4,
placement: 'left',
});
}
function startTriggerApproach(attempt) {
if (
!_enabled ||
_presentation !== BHOTE_KOSHI_TRIGGER_RECORD_PRESENTATION ||
_triggerApproachAttempt !== attempt ||
attempt.phase !== 'armed'
)
return;
attempt.phase = 'flying';
if (_triggerApproachTimer !== null) cancelDelay(_triggerApproachTimer);
_triggerApproachTimer = null;
_removeTriggerMoveStart?.();
_removeTriggerMoveEnd?.();
_removeTriggerMoveStart = null;
_removeTriggerMoveEnd = null;
_triggerCalloutStartedAt = now();
requestRender('bhote-koshi-trigger-record-reveal');
const port = findCamera(_viewer);
if (!port) return;
const generation = _generation;
_triggerApproachInFlight = true;
const finish = () => {
if (_triggerApproachAttempt !== attempt) return;
attempt.phase = 'finished';
_triggerApproachInFlight = false;
};
port.flyTo(
{
lon: TRIGGER_APPROACH_CAMERA.lon,
lat: TRIGGER_APPROACH_CAMERA.lat,
height: TRIGGER_APPROACH_CAMERA.alt,
},
{
orientation: {
heading: toRadians(TRIGGER_APPROACH_CAMERA.heading),
pitch: toRadians(TRIGGER_APPROACH_CAMERA.pitch),
roll: toRadians(TRIGGER_APPROACH_CAMERA.roll),
},
durationS: TRIGGER_APPROACH_DURATION_SEC,
easing: 'cubicInOut',
onComplete: () => {
if (_triggerApproachAttempt !== attempt || attempt.phase !== 'flying')
return;
if (
!_enabled ||
generation !== _generation ||
_presentation !== BHOTE_KOSHI_TRIGGER_RECORD_PRESENTATION
) {
finish();
return;
}
attempt.phase = 'orbiting';
port.flyTo(
{
lon: TRIGGER_ORBIT_CAMERA.lon,
lat: TRIGGER_ORBIT_CAMERA.lat,
height: TRIGGER_ORBIT_CAMERA.alt,
},
{
orientation: {
heading: toRadians(TRIGGER_ORBIT_CAMERA.heading),
pitch: toRadians(TRIGGER_ORBIT_CAMERA.pitch),
roll: toRadians(TRIGGER_ORBIT_CAMERA.roll),
},
durationS: TRIGGER_ORBIT_DURATION_SEC,
easing: 'sineInOut',
onComplete: finish,
onCancel: finish,
},
);
},
onCancel: finish,
},
);
}
function armTriggerApproach() {
if (!_approachEnabled) {
_triggerCalloutStartedAt = now();
return;
}
const attempt = { phase: 'armed' };
_triggerApproachAttempt = attempt;
const start = () => startTriggerApproach(attempt);
const camera = findCamera(_viewer);
if (!camera) {
start();
return;
}
_removeTriggerMoveStart = camera.on('moveStart', () => {
if (_triggerApproachAttempt !== attempt || attempt.phase !== 'armed')
return;
if (_triggerApproachTimer !== null) cancelDelay(_triggerApproachTimer);
_triggerApproachTimer = null;
_removeTriggerMoveStart?.();
_removeTriggerMoveStart = null;
_removeTriggerMoveEnd = camera.on('moveEnd', start);
});
_triggerApproachTimer = scheduleDelay(start, TRIGGER_APPROACH_ARM_MS);
}
function addNepalCallout(
sequenceStartedAt = now(),
labelPlacement = 'right',
{ showAnchor = true } = {},
) {
addCallout(NEPAL, BORDER_ACCENT, {
labelPlacement,
sequenceStartedAt,
showAnchor,
});
}
function addNearbyCityCallouts(sequenceStartedAt) {
NEARBY_CITIES.forEach((city, index) => {
const visibleAt =
sequenceStartedAt +
CITY_CALLOUT_START_DELAY_MS +
index * CITY_CALLOUT_STAGGER_MS;
const progress = () =>
smoothstep(0, 1, (now() - visibleAt) / CITY_CALLOUT_REVEAL_MS);
const labelOnLeft = city.placement === 'left';
const labelLower = city.placement === 'right-lower';
const position = fromDegrees(city.lon, city.lat, city.heightM);
queueOverlayEntry({
id: `bhote-koshi-city-${city.id}`,
position,
variant: 'label',
paintLane: 'ambient-label',
title: city.title,
details: [],
accent: BORDER_ACCENT,
sourceAlpha: progress,
presentationScale: () => 0.92 + progress() * 0.08,
leaderProgress: progress,
contentAlpha: progress,
anchorDot: true,
leaderStyle: 'elbow',
priority: 700_000 - index,
collisionGroup: 'nepal-nearby-city',
zIndex: 44,
minDistance: 0,
maxDistance: 3_000_000,
distanceFadeStartRatio: 0.82,
distanceScale: {
near: 100000,
nearValue: 1.08,
far: 3000000,
farValue: 0.78,
},
edgeFade: 'keyhole',
horizonCull: true,
terrainOcclusion: false,
gapPx: 14,
placement: labelLower ? 'below' : labelOnLeft ? 'left' : 'right',
});
});
}
function addIncidentPlaceCallouts(
sequenceStartedAt,
{ pulseHalos = false, places = INCIDENT_OVERVIEW_PLACES } = {},
) {
places.forEach((place, index) => {
const visibleAt =
sequenceStartedAt +
PLACE_CALLOUT_START_DELAY_MS +
index * PLACE_CALLOUT_STAGGER_MS;
const progress = () =>
smoothstep(0, 1, (now() - visibleAt) / PLACE_CALLOUT_REVEAL_MS);
const labelOnLeft = place.placement === 'left';
const labelLower = place.placement === 'right-lower';
const position = fromDegrees(place.lon, place.lat, place.heightM);
if (pulseHalos) {
const pulseSequenceDurationMs =
PLACE_CALLOUT_STAGGER_MS * places.length;
const pulseWindowElapsed = () => {
const sequenceElapsed = Math.max(
0,
now() - sequenceStartedAt - PLACE_CALLOUT_START_DELAY_MS,
);
return (
(sequenceElapsed % pulseSequenceDurationMs) -
index * PLACE_CALLOUT_STAGGER_MS
);
};
const pulseIsActive = () => {
const elapsed = pulseWindowElapsed();
return (
now() >= visibleAt &&
elapsed >= 0 &&
elapsed < PLACE_CALLOUT_STAGGER_MS
);
};
const pulseProgress = () => {
return Math.max(
0,
Math.min(1, pulseWindowElapsed() / PLACE_CALLOUT_STAGGER_MS),
);
};
addHalo({
id: `bhote-koshi-place-${place.id}-halo`,
subject: place,
color: INCIDENT_ACCENT,
visible: pulseIsActive,
progress: pulseProgress,
fillAlpha: (p) => 0.16 * (1 - p),
ringAlpha: (p) => 0.08 + 0.78 * (1 - p),
scaleByDistance: {
near: 5000,
nearValue: 1,
far: 500000,
farValue: 0.82,
},
});
}
queueOverlayEntry({
id: `bhote-koshi-place-${place.id}`,
position,
variant: 'label',
paintLane: 'ambient-label',
title: `${String(index + 1).padStart(2, '0')} · ${placeTitle(place.title)}`,
details: [],
accent: INCIDENT_ACCENT,
sourceAlpha: progress,
presentationScale: () => 0.92 + progress() * 0.08,
leaderProgress: progress,
contentAlpha: progress,
anchorDot: true,
leaderStyle: 'elbow',
priority: 800_000 - index,
collisionGroup: 'bhote-koshi-place',
zIndex: 46,
minDistance: 0,
maxDistance: 500_000,
distanceFadeStartRatio: 0.82,
distanceScale: {
near: 5000,
nearValue: 1.08,
far: 500000,
farValue: 0.82,
},
edgeFade: 'keyhole',
horizonCull: true,
terrainOcclusion: false,
gapPx: 14,
placement: labelLower ? 'below' : labelOnLeft ? 'left' : 'right',
});
});
}
function addIncidentFloodPath(sequenceStartedAt) {
const positions = BHOTE_KOSHI_FLOOD_PATH.map(([lon, lat]) =>
fromDegrees(lon, lat),
);
const drawStartedAt = sequenceStartedAt + FLOOD_PATH_START_DELAY_MS;
addRevealedLine({
id: 'bhote-koshi-flood-path',
positions,
widthPx: 3.5,
color: hexColor(BORDER_ACCENT, 0.96),
progress: () => (now() - drawStartedAt) / FLOOD_PATH_DRAW_DURATION_MS,
visible: () => now() >= drawStartedAt,
});
}
function addNepalBoundary(ring, sequenceStartedAt) {
const closed = closeRegionRing(ring);
if (closed.length < 4) return false;
const positions = closed.map(([lon, lat]) => fromDegrees(lon, lat));
const drawStartedAt = sequenceStartedAt + BORDER_START_DELAY_MS;
const progress = () => (now() - drawStartedAt) / BORDER_DRAW_DURATION_MS;
_fill = {
visible: () => now() >= drawStartedAt,
item: {
id: 'nepal-border-fill',
geometry: {
kind: 'polygon',
rings: [closed.slice(0, -1).map(([lon, lat]) => ({ lon, lat }))],
},
fill: hexColor(BORDER_ACCENT, 0.055),
height: 'clampGround',
clampTo: 'both',
},
};
for (const [id, widthPx, alpha] of [
['nepal-border-halo', 5, 0.12],
['nepal-border-highlight', 2.5, 0.96],
])
addRevealedLine({
id,
positions,
widthPx,
color: hexColor(BORDER_ACCENT, alpha),
progress,
visible: () => true,
});
// The callout pulse draws each step of the reveal (`syncDrawn`).
return true;
}
function renderPresentation() {
if (!_drawing) return;
stopAnimations();
overlayHost.clearSource(BHOTE_KOSHI_LOCATOR_OVERLAY_SOURCE_ID);
_overlayEntries = [];
resetDrawn();
if (_presentation === NEPAL_CONTEXT_PRESENTATION) {
addNepalCallout();
} else if (_presentation === BHOTE_KOSHI_INCIDENT_PLACES_PRESENTATION) {
const sequenceStartedAt = now();
addIncidentPlaceCallouts(sequenceStartedAt, {
pulseHalos: true,
places: INCIDENT_OVERVIEW_PLACES,
});
_placeRevealMoving = true;
_placeRevealSettledAt =
sequenceStartedAt +
PLACE_CALLOUT_START_DELAY_MS +
(INCIDENT_OVERVIEW_PLACES.length - 1) * PLACE_CALLOUT_STAGGER_MS +
PLACE_CALLOUT_REVEAL_MS;
} else if (_presentation === BHOTE_KOSHI_FLOOD_PATH_PRESENTATION) {
const sequenceStartedAt = now();
const settledPlacesAt =
sequenceStartedAt -
PLACE_CALLOUT_START_DELAY_MS -
(INCIDENT_OVERVIEW_PLACES.length - 1) * PLACE_CALLOUT_STAGGER_MS -
PLACE_CALLOUT_REVEAL_MS;
addIncidentFloodPath(sequenceStartedAt);
addIncidentPlaceCallouts(settledPlacesAt);
} else if (_presentation === BHOTE_KOSHI_PATH_OVERVIEW_PRESENTATION) {
const sequenceStartedAt = now();
const settledPathAt =
sequenceStartedAt -
FLOOD_PATH_START_DELAY_MS -
FLOOD_PATH_DRAW_DURATION_MS;
const settledPlacesAt =
sequenceStartedAt -
PLACE_CALLOUT_START_DELAY_MS -
(INCIDENT_OVERVIEW_PLACES.length - 1) * PLACE_CALLOUT_STAGGER_MS -
PLACE_CALLOUT_REVEAL_MS;
addIncidentFloodPath(settledPathAt);
addIncidentPlaceCallouts(settledPlacesAt);
} else if (_presentation === BHOTE_KOSHI_TRIGGER_RECORD_PRESENTATION) {
const sequenceStartedAt = now();
const settledPathAt =
sequenceStartedAt -
FLOOD_PATH_START_DELAY_MS -
FLOOD_PATH_DRAW_DURATION_MS;
addIncidentFloodPath(settledPathAt);
addTriggerRecordCallout();
armTriggerApproach();
} else {
const sequenceStartedAt = now();
addNepalCallout(sequenceStartedAt, 'left');
if (!_boundaryResolved) {
commitDrawn();
publishOverlayEntries();
startCalloutAnimation();
requestRender('bhote-koshi-locator-presentation');
return;
}
if (_presentation === BHOTE_KOSHI_CITY_CONTEXT_PRESENTATION) {
const settledAt =
sequenceStartedAt - BORDER_START_DELAY_MS - BORDER_DRAW_DURATION_MS;
if (_boundaryRing) addNepalBoundary(_boundaryRing, settledAt);
addIncidentCallout(sequenceStartedAt - CALLOUT_REVEAL_DURATION_MS);
addNearbyCityCallouts(sequenceStartedAt);
} else {
if (_boundaryRing) addNepalBoundary(_boundaryRing, sequenceStartedAt);
const incidentDelayMs = _boundaryRing
? BORDER_START_DELAY_MS +
BORDER_DRAW_DURATION_MS +
INCIDENT_CALLOUT_GAP_MS
: BORDER_START_DELAY_MS;
addIncidentCallout(sequenceStartedAt, incidentDelayMs);
}
}
commitDrawn();
publishOverlayEntries({ moving: _placeRevealMoving });
startCalloutAnimation();
requestRender('bhote-koshi-locator-presentation');
}
async function init(viewer) {
_viewer = viewer;
return true;
}
async function enable(viewer, { signal } = {}) {
_viewer = viewer;
_enabled = true;
_boundaryReady = false;
_boundaryResolved = false;
_boundaryRing = null;
const generation = ++_generation;
removeDrawn();
_drawing = true;
renderPresentation();
registerDynamicCredit(viewer, BHOTE_KOSHI_LOCATOR_CREDIT);
showOsmCredit(viewer, BHOTE_KOSHI_LOCATOR_LAYER_ID);
installCalloutClick(viewer);
requestRender('bhote-koshi-locator-callout');
try {
const boundary = await boundaryResolver(signal);
if (signal?.aborted || !_enabled || generation !== _generation)
throw abortError();
_boundaryRing = closeRegionRing(boundary?.ring);
_boundaryReady = _boundaryRing.length >= 4;
_boundaryResolved = true;
if (!_boundaryReady && presentationUsesBoundary(_presentation)) {
console.warn('[Data:BhoteKoshiLocator] Nepal boundary unavailable');
}
if (presentationUsesBoundary(_presentation)) {
renderPresentation();
}
requestRender('bhote-koshi-locator-boundary');
return true;
} catch (error) {
if (error?.name === 'AbortError') {
if (generation === _generation) removeDrawn();
throw error;
}
console.warn(
'[Data:BhoteKoshiLocator] Nepal boundary lookup failed:',
error,
);
_boundaryResolved = true;
_boundaryRing = null;
if (presentationUsesBoundary(_presentation)) renderPresentation();
requestRender('bhote-koshi-locator-degraded');
return true;
}
}
/**
* An actionable callout of ours (the trigger record's) is a card painted
* over the globe: a click on it opens its source, as its keyboard action
* does. Like the other cards, it leaves a drag alone and yields to a layer
* that acts on what is under it (an aircraft, a vessel): its exact pick, or
* a coarse tap's touch contact whose layer acts on nearby contacts.
*/
function installCalloutClick(viewer) {
if (_removeClick) return;
let clicks = null;
try {
clicks = input?.(viewer) ?? null;
} catch {
clicks = null;
}
_removeClick =
clicks?.onClick?.((event) => {
if (!_enabled || !isTrackingSelectionGesture(event.gesture)) return;
const top = hitTest?.(event.screenPosition?.x, event.screenPosition?.y);
if (top?.sourceId !== BHOTE_KOSHI_LOCATOR_OVERLAY_SOURCE_ID) return;
const exactId = resolvePickId(event.topHit ?? null);
if (
exactId &&
isActedOnByOtherLayer(BHOTE_KOSHI_LOCATOR_LAYER_ID, exactId, {
click: event,
})
)
return;
const contactId = resolvePickId(event.hit ?? null);
if (
contactId &&
contactId !== exactId &&
isActedOnByOtherLayer(BHOTE_KOSHI_LOCATOR_LAYER_ID, contactId, {
expanded: true,
click: event,
})
)
return;
if (typeof top.entry?.activate === 'function') top.entry.activate();
}) ?? null;
}
async function disable() {
hideOsmCredit(_viewer, BHOTE_KOSHI_LOCATOR_LAYER_ID);
_removeClick?.();
_removeClick = null;
_enabled = false;
_boundaryReady = false;
_boundaryResolved = false;
_boundaryRing = null;
_generation += 1;
removeDrawn();
requestRender('bhote-koshi-locator-disable');
return true;
}
async function destroy() {
await disable();
_viewer = null;
}
return {
id: BHOTE_KOSHI_LOCATOR_LAYER_ID,
name: 'Bhote Koshi Locator',
// Scene-owned component; retain registration without a standalone menu row.
showInTogglePanel: false,
icon: '◎',
source: 'OpenStreetMap + GeoPera',
updateInterval: 0,
init,
enable,
disable,
update: async () => true,
destroy,
cancelSceneMotion() {
clearTriggerApproach({ preserveCallout: true });
},
setParams(params = {}) {
_presentation = normalizePresentation(params.presentation);
_approachEnabled =
_presentation === BHOTE_KOSHI_TRIGGER_RECORD_PRESENTATION &&
params.preview !== true;
if (_enabled) renderPresentation();
return true;
},
getParams() {
return { presentation: _presentation };
},
getRowControls() {
return {
chips: [
{
id: 'nepal-context',
// i18n-ignore: country name
label: 'NEPAL',
active: _presentation === NEPAL_CONTEXT_PRESENTATION,
title: t(
'Show the Nepal context callout without a border or country fill',
),
params: { presentation: NEPAL_CONTEXT_PRESENTATION },
},
{
id: 'bhote-koshi-regional',
// i18n-ignore: river name (Bhote Koshi)
label: 'BHOTE',
active: _presentation === BHOTE_KOSHI_REGIONAL_PRESENTATION,
title: t(
'Introduce Nepal, draw its border, then reveal the Bhote Koshi incident',
),
params: { presentation: BHOTE_KOSHI_REGIONAL_PRESENTATION },
},
{
id: 'bhote-koshi-city-context',
label: t('CITIES'),
active: _presentation === BHOTE_KOSHI_CITY_CONTEXT_PRESENTATION,
title: t(
'Keep the regional incident context and introduce nearby city labels',
),
params: { presentation: BHOTE_KOSHI_CITY_CONTEXT_PRESENTATION },
},
{
id: 'bhote-koshi-incident-places',
label: t('PLACES'),
active: _presentation === BHOTE_KOSHI_INCIDENT_PLACES_PRESENTATION,
title: t(
'Introduce the reconstruction scene key places from trigger to downstream',
),
params: { presentation: BHOTE_KOSHI_INCIDENT_PLACES_PRESENTATION },
},
{
id: 'bhote-koshi-flood-path',
label: t('PATH'),
active: _presentation === BHOTE_KOSHI_FLOOD_PATH_PRESENTATION,
title: t(
'Animate the sourced cyan river-centerline route to Trishuli Bazaar',
),
params: { presentation: BHOTE_KOSHI_FLOOD_PATH_PRESENTATION },
},
{
id: 'bhote-koshi-path-overview',
label: t('OVERVIEW'),
active: _presentation === BHOTE_KOSHI_PATH_OVERVIEW_PRESENTATION,
title: t(
'Keep the completed flood path and location labels visible',
),
params: { presentation: BHOTE_KOSHI_PATH_OVERVIEW_PRESENTATION },
},
{
id: 'bhote-koshi-trigger-record',
label: t('RECORD'),
active: _presentation === BHOTE_KOSHI_TRIGGER_RECORD_PRESENTATION,
title: t(
'Reveal the trigger record while making a slow camera approach',
),
params: {
presentation: BHOTE_KOSHI_TRIGGER_RECORD_PRESENTATION,
preview: true,
},
},
],
legend: [],
};
},
getStats() {
return {
count: _enabled ? 1 : 0,
status: !_enabled
? 'idle'
: _presentation === BHOTE_KOSHI_INCIDENT_PLACES_PRESENTATION ||
_presentation === BHOTE_KOSHI_FLOOD_PATH_PRESENTATION ||
_presentation === BHOTE_KOSHI_PATH_OVERVIEW_PRESENTATION ||
_presentation === BHOTE_KOSHI_TRIGGER_RECORD_PRESENTATION ||
_boundaryReady
? 'nominal'
: 'degraded',
source: 'OpenStreetMap + GeoPera',
coverage: !_enabled
? 'Incident locator'
: _presentation === NEPAL_CONTEXT_PRESENTATION
? 'Nepal context'
: _presentation === BHOTE_KOSHI_CITY_CONTEXT_PRESENTATION
? 'Bhote Koshi · Nearby cities'
: _presentation === BHOTE_KOSHI_INCIDENT_PLACES_PRESENTATION
? 'Bhote Koshi · Incident places'
: _presentation === BHOTE_KOSHI_FLOOD_PATH_PRESENTATION
? 'Bhote Koshi · Flood path'
: _presentation === BHOTE_KOSHI_PATH_OVERVIEW_PRESENTATION
? 'Bhote Koshi · Path overview'
: _presentation === BHOTE_KOSHI_TRIGGER_RECORD_PRESENTATION
? 'Bhote Koshi · Trigger record'
: 'Nepal · Bhote Koshi',
};
},
};
}