diff --git a/src/app/layers/cyclones.js b/src/app/layers/cyclones.js index bed75c76e..e0cd508b0 100644 --- a/src/app/layers/cyclones.js +++ b/src/app/layers/cyclones.js @@ -3,9 +3,8 @@ import * as context from '../../data/contextStore.js'; /** Wire cyclone selection to the application shared context. */ export function createApplicationCyclones(options) { - const browserContext = typeof window !== 'undefined' ? { context } : {}; return createCyclonesLayer({ - ...browserContext, + context: typeof window !== 'undefined' ? context : null, ...options, }); } diff --git a/src/layers/cyclones/index.js b/src/layers/cyclones/index.js index 95655d5d0..90936edf3 100644 --- a/src/layers/cyclones/index.js +++ b/src/layers/cyclones/index.js @@ -84,7 +84,6 @@ export function createCyclonesLayer({ selectionIntent = 'auto', navigationGeneration = 0, selectedContextStormId = null, - selectedContextEntity = null, clickHandler = null, removeClickCapture = null; let enabled = false, @@ -98,20 +97,19 @@ export function createCyclonesLayer({ function clearSelectedContext({ evicted = false } = {}) { if (selectedContextStormId) { if (!evicted) - context?.clearSelectedEntityContextForLayer?.('weather-cyclones'); - context?.removeEntityContextsForLayer?.('weather-cyclones'); + context.clearSelectedEntityContextForLayer('weather-cyclones'); + context.removeEntityContextsForLayer('weather-cyclones'); } selectedContextStormId = null; - selectedContextEntity = null; } // Callers publish only while selectedId names a storm in the snapshot. function publishSelectedContext({ announce = false } = {}) { const storm = selected(); if (!context) return; - selectedContextEntity ||= { show: true }; + const entity = {}; const contextId = `cyclone:${storm.id}`; - const record = context.registerEntityContext?.(selectedContextEntity, { + context.registerEntityContext(entity, { id: contextId, layerId: 'weather-cyclones', layerName: 'Cyclone advisories', @@ -145,10 +143,9 @@ export function createCyclonesLayer({ : undefined, }, }); - if (!record) return; selectedContextStormId = storm.id; - if (announce) context.selectEntityContext?.(selectedContextEntity); - context.removeEntityContextsForLayer?.('weather-cyclones', { + if (announce) context.selectEntityContext(entity); + context.removeEntityContextsForLayer('weather-cyclones', { retainIds: new Set([contextId]), }); } diff --git a/src/layers/cyclones/index.test.mjs b/src/layers/cyclones/index.test.mjs index 41ecaf3d1..e826f392e 100644 --- a/src/layers/cyclones/index.test.mjs +++ b/src/layers/cyclones/index.test.mjs @@ -488,12 +488,7 @@ test('shared cyclone context distinguishes switches, deliberate clears and feed assert.equal(store.entities.size, 0); h.layer.setParams({ stormId: 'ep152026' }); - const record = store.entities.get('cyclone:ep152026'); - assert.equal(record.layerId, 'weather-cyclones'); - assert.equal(record.source, 'NOAA NHC / CPHC'); - assert.equal(record.label, 'Fifteen-E'); - assert.equal(record.latitude, 15.5); - assert.equal(record.longitude, -125.8); + assert.equal(store.entities.get('cyclone:ep152026').label, 'Fifteen-E'); let properties = await selectedProperties(); assert.equal(properties.classification, 'PTC'); assert.equal(properties.classificationName, 'Post-tropical cyclone'); @@ -652,24 +647,11 @@ test('cyclone clears leave another layer selection and its records alone', async 'no clear is reported for a foreign selection', ); + // A cyclone clear does not report a dangling foreign selection as evicted. + store.entities.delete('flight:abc123'); h.layer.disable(); assert.equal(store.selectedEntityId, 'flight:abc123'); assert.equal(events.length, before); - - // A cyclone feed failure does not evict a dangling foreign selection. - store.entities.delete('flight:abc123'); - let fail = false; - const other = open({ - getSnapshot: async () => { - if (fail) throw new Error('Network unavailable'); - return snapshot(); - }, - }); - other.layer.enable(); - await other.layer.update(); - fail = true; - await other.layer.update(); - assert.equal(events.length, before); }); });