mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 10:12:18 +00:00
Every layer draws on both engines, so the per-engine availability machinery always answered yes. The renderer manifest is now the id to display map plus the wind flow backend; the catalog filter, the voice and QA-probe refusals and the engine-kind checks go with it. The Navara notice lists the same layers in the same words. Paths that read the Cesium viewer behind an engine that is always there are gone: the Recent Imagery viewer fallbacks, the shell's imagery-host service (one shared host module remains), the engineless map controller, viewer gates in voice actions, world packets and camera verbs, the orientation controls' tracked-entity fallback, and the Bhote Koshi and FIRMS Cesium-shaped paths. setCameraInputs, which nothing called, leaves the contract; suspensions remain. Smaller duplicates go too: one tracker-release helper for navigation and location, the no-op frame latch, missing-engine guards, one name for the injected display, flat bikeshare and installations displays, one overlay host and binder, one name per world-overlay method, and stub-viewer guards in the Cesium engine. Layers that still read the viewer keep the shared init(viewer, context) entry. Behaviour is unchanged on both engines. Viewer lines fall from 849 to 750 and engine-name literals from 32 to 27.
142 lines
5.3 KiB
JavaScript
142 lines
5.3 KiB
JavaScript
import { bindOverlayHost } from '../../overlays/bindOverlayHost.js';
|
|
import { adaptFirmsRecords } from '../../data/firmsAdapt.js';
|
|
import { fireDetectionKey } from '../../data/firmsLabels.js';
|
|
import { filterFires } from '../../data/firmsIntensity.js';
|
|
import { msg } from '../../i18n/index.js';
|
|
|
|
export function createIngestion({
|
|
layerState,
|
|
services,
|
|
components,
|
|
config,
|
|
feed,
|
|
}) {
|
|
const { clearSelectedEntityContextForLayer } = bindOverlayHost(
|
|
services.context,
|
|
() => layerState._renderer?.engine,
|
|
);
|
|
const { id } = config;
|
|
|
|
/** Replace a validated snapshot while preserving source freshness and selection identity. */
|
|
|
|
async function loadHeatmap() {
|
|
if (!layerState._renderer || !layerState._enabled) return;
|
|
layerState.request?.abort();
|
|
const request = new AbortController();
|
|
layerState.request = request;
|
|
layerState._loading = true;
|
|
|
|
try {
|
|
const payload = await feed.getSnapshot({ signal: request.signal });
|
|
if (
|
|
request.signal.aborted ||
|
|
layerState.request !== request ||
|
|
!layerState._enabled
|
|
)
|
|
return;
|
|
if (payload.keyRequired) {
|
|
layerState._keyRequired = true;
|
|
layerState._error = null;
|
|
layerState._stale = false;
|
|
return;
|
|
}
|
|
layerState._keyRequired = false;
|
|
layerState._error = null;
|
|
layerState._stale = Boolean(payload?.stale);
|
|
const previousSelection = layerState._selectedFire;
|
|
layerState._selectedFire = null;
|
|
layerState._allFires = adaptFirmsRecords(payload?.fires);
|
|
// Sorted once per payload; applyFilter only filters, so a slider drag
|
|
// over 200k detections never re-sorts.
|
|
layerState._allFiresByFrp = [...layerState._allFires].sort(
|
|
(a, b) => b.frp - a.frp,
|
|
);
|
|
applyFilter();
|
|
// Data age, not response age: a stale proxy payload truthfully reads old.
|
|
layerState._lastUpdate = Number.isFinite(payload?.fetchedAt)
|
|
? payload.fetchedAt
|
|
: Date.now();
|
|
// Settle the previous selection BEFORE the LOD rebuild. renderCurrentLod
|
|
// runs refreshContextRegistrations(), which deletes every context record
|
|
// not in the new top-N — including the one the store still points at.
|
|
// Clearing after that deletion fails the ownership guard inside
|
|
// clearSelectedEntityContextForLayer and emits nothing at all, so an
|
|
// eviction-aware readout never hears that its subject is gone.
|
|
const reselected = findMatchingFire(previousSelection);
|
|
if (!reselected && previousSelection) {
|
|
// The selected detection is not in the new payload: it left the feed
|
|
// rather than being deselected. Eviction-aware readouts hold their
|
|
// last-known values for this instead of tearing down.
|
|
clearSelectedEntityContextForLayer(id, { evicted: true });
|
|
}
|
|
layerState._selectedFire = reselected;
|
|
components.rendering.renderCurrentLod(true);
|
|
if (reselected) components.selection.selectFire(reselected, false);
|
|
layerState._rowControlsListener?.();
|
|
} catch (error) {
|
|
if (
|
|
request.signal.aborted ||
|
|
layerState.request !== request ||
|
|
!layerState._enabled
|
|
)
|
|
return;
|
|
console.warn(`[Data:${id}] FIRMS live load failed:`, error);
|
|
// English data (stats reach the voice tools); the panel translates it.
|
|
layerState._error = msg('live feed unavailable');
|
|
} finally {
|
|
if (layerState.request === request) {
|
|
layerState.request = null;
|
|
layerState._loading = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Run the intensity filter over the loaded payload. This is the ONE place
|
|
* the shown set is derived: `_fires` / `_firesByFrp` feed markers, cards,
|
|
* the heatmap, the context store, the top-fires query and the analyst
|
|
* records, so none of them can disagree about which fires exist. Cells and
|
|
* the heat raster are built per shown set, so their caches go with it.
|
|
*/
|
|
|
|
function applyFilter() {
|
|
layerState._fires = filterFires(layerState._allFires, layerState._filter);
|
|
layerState._cellCacheByGrid.clear();
|
|
layerState._heatRaster = null;
|
|
layerState._firesByFrp = filterFires(
|
|
layerState._allFiresByFrp,
|
|
layerState._filter,
|
|
);
|
|
layerState._count = layerState._fires.length;
|
|
layerState._totalCount = layerState._allFires.length;
|
|
}
|
|
|
|
/**
|
|
* Find the record in the freshly-loaded set matching a previous selection.
|
|
* Identity is the detection itself (lat/lon/acquisition time) — indices
|
|
* are regenerated every fetch, so object/index identity cannot be used.
|
|
* @param {?Object} previous - Previously selected fire record.
|
|
* @returns {?Object} Matching new record.
|
|
*/
|
|
|
|
function findMatchingFire(previous) {
|
|
if (!previous) return null;
|
|
const key = fireDetectionKey(previous);
|
|
return (
|
|
layerState._fires.find((fire) => fireDetectionKey(fire) === key) || null
|
|
);
|
|
}
|
|
const methods = {
|
|
async update() {
|
|
if (layerState._destroyed || !layerState._enabled || layerState._loading)
|
|
return;
|
|
// Scheduled 10-minute poll (and the manager's immediate first update):
|
|
// refetch live fires through the proxy and re-render. Viewport-driven
|
|
// re-renders between polls are handled by the LOD watcher.
|
|
await loadHeatmap();
|
|
},
|
|
};
|
|
|
|
return { loadHeatmap, applyFilter, findMatchingFire, methods };
|
|
}
|