feat(cyclones): publish explicit selection to shared context

This commit is contained in:
Kevin Rajan committed 2026-09-29 00:20:16 -05:00
1 parent e7707d9a0f
commit 28f3243090
5 files changed
+138 -3

No files matched your search

+52
View File
@@ -37,6 +37,7 @@ export function createCyclonesLayer({
feed,
hitTestOverlay = hitTestWorldOverlay,
overlayHost,
context = null,
cesium = Cesium,
createRendering = createCycloneRendering,
matchMedia = globalThis.matchMedia?.bind(globalThis),
@@ -52,6 +53,8 @@ export function createCyclonesLayer({
selectedId = null,
selectionIntent = 'auto',
navigationGeneration = 0,
selectedContextStormId = null,
selectedContextEntity = null,
clickHandler = null,
removeClickCapture = null;
let enabled = false,
@@ -62,6 +65,46 @@ export function createCyclonesLayer({
const notify = () => listener?.();
const selected = () =>
snapshot?.storms.find((storm) => storm.id === selectedId) || null;
function clearSelectedContext() {
context?.removeEntityContextsForLayer?.('weather-cyclones');
selectedContextStormId = null;
selectedContextEntity = null;
}
function publishSelectedContext({ announce = false } = {}) {
const storm = selected();
if (!storm || !context) {
if (!storm) clearSelectedContext();
return null;
}
selectedContextEntity ||= { show: true };
const record = context.registerEntityContext?.(selectedContextEntity, {
id: `cyclone:${storm.id}`,
layerId: 'weather-cyclones',
layerName: 'Cyclone advisories',
source: 'NOAA NHC / CPHC',
label: `Cyclone · ${storm.name}`,
latitude: storm.position.latitude,
longitude: storm.position.longitude,
properties: {
classification: storm.classification,
basin: storm.basin,
advisoryNumber: storm.advisoryNumber,
issuedAt: storm.issuedAt,
positionAt: storm.positionAt,
windKt: storm.windKt,
pressureHpa: storm.pressureHpa,
movement: storm.movement,
advisoryUrl: storm.advisoryUrl,
},
});
if (!record) return null;
selectedContextStormId = storm.id;
if (announce) context.selectEntityContext?.(selectedContextEntity);
return record;
}
function select(id) {
if (selectedId !== id) ++navigationGeneration;
selectedId = id;
@@ -206,6 +249,7 @@ export function createCyclonesLayer({
selectedId = null;
selectionIntent = 'auto';
++navigationGeneration;
clearSelectedContext();
rendering?.clear();
},
async update(_viewer, { signal } = {}) {
@@ -229,6 +273,7 @@ export function createCyclonesLayer({
snapshot = next;
selectedId = null;
++navigationGeneration;
clearSelectedContext();
error = next.reason || 'Cyclone advisories unavailable';
return true;
}
@@ -251,6 +296,10 @@ export function createCyclonesLayer({
: snapshot.storms[0]?.id || null,
);
else rendering.setSelection(selectedId);
if (selectedContextStormId) {
if (selectedId === selectedContextStormId) publishSelectedContext();
else clearSelectedContext();
}
return true;
} catch (cause) {
if (controller.signal.aborted || request !== controller) return false;
@@ -260,6 +309,7 @@ export function createCyclonesLayer({
snapshot = null;
selectedId = null;
++navigationGeneration;
clearSelectedContext();
return true;
} finally {
signal?.removeEventListener('abort', abort);
@@ -275,6 +325,7 @@ export function createCyclonesLayer({
if (params.clear === true || params.stormId === null) {
selectionIntent = 'cleared';
select(null);
clearSelectedContext();
notify();
} else if (
typeof params.stormId === 'string' &&
@@ -282,6 +333,7 @@ export function createCyclonesLayer({
) {
selectionIntent = 'user';
select(params.stormId);
publishSelectedContext({ announce: true });
notify();
}
const storm = selected();