mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-21 18:52:18 +00:00
Draw nine layers' fills through engine.ground, one display each
Earthquakes, air quality, GNSS Integrity, fire perimeters, Prohibited & Restricted Airspace, Active Fires, S2 GhostMaps, cyclone advisories and submarine cables each have one render/display.js on the globe contract; their render/cesium* and render/navara* files go. Their discs, cells, polygons and corridors are engine.ground sets, so on Navara they come from the one ground screen pass with exact colours instead of nine hand-written classification passes and lit SDK vector layers. Cesium's look stays the reference: - Earthquake and air-quality discs have no outline (Cesium drew none on clamped ellipses); earthquake discs can now be picked on Navara too. - Perimeters, drone zones and GhostMaps polygons outline their outer ring only, as Cesium did. - GNSS cells stay out of the pick pass; cyclone cones, tracks and centres are culled by a port of Cesium's horizon occluder. - Submarine cables are one ground corridor set, as Cesium batched them; landing points, tips and stems are movers and lines. - FIRMS glows are a sprite set and its cells a ground set. The far-zoom heat raster, which no primitive draws yet, sits behind one seam, render/heatField.js, with a Cesium and a Navara backend. The shared Navara ground helpers that only these layers used go (navaraGroundCells, the cell and ground geometry, the zone renderers), as does the ground prototype script. Coupling: layer renderer lines fall from 1636/6953 to 1011/4832 (Cesium/Navara), Navara ground passes from 7 to 5, Cesium-importing files from 65 to 53, engine.extensions reads from 26 to 19.
This commit is contained in:
1 parent
974a0b6361
commit
54fe0aea40
124 files changed
+8407
-9576
No files matched your search
@@ -5,6 +5,7 @@ import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import * as Cesium from 'cesium';
|
||||
import { createFakeGroundHarness } from '../testSupport/groundDisplayEngines.mjs';
|
||||
import {
|
||||
EARTHQUAKE_OVERLAY_COHORT_LIMIT,
|
||||
EARTHQUAKE_OVERLAY_COLLISION_CAPACITY,
|
||||
@@ -92,25 +93,15 @@ test('earthquake overlay copy keeps source-side magnitude formatting and bounded
|
||||
assert.equal(cohort.at(-1).id, 'quake-020');
|
||||
});
|
||||
|
||||
test('real earthquake lifecycle publishes host labels while runtime entities carry no label graphic', async () => {
|
||||
test('real earthquake lifecycle draws ground discs and publishes their labels to the host', async () => {
|
||||
const originalFetch = globalThis.fetch;
|
||||
const hostCalls = [];
|
||||
const dataSources = [];
|
||||
const ground = createFakeGroundHarness();
|
||||
const overlayHost = {
|
||||
setEntries: (...args) => hostCalls.push(['entries', ...args]),
|
||||
setVisible: (...args) => hostCalls.push(['visible', ...args]),
|
||||
clearSource: (...args) => hostCalls.push(['clear', ...args]),
|
||||
};
|
||||
const viewer = {
|
||||
dataSources: {
|
||||
add(dataSource) { dataSources.push(dataSource); return dataSource; },
|
||||
remove(dataSource) {
|
||||
const index = dataSources.indexOf(dataSource);
|
||||
if (index >= 0) dataSources.splice(index, 1);
|
||||
return index >= 0;
|
||||
},
|
||||
},
|
||||
};
|
||||
globalThis.fetch = async () => ({
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
@@ -130,13 +121,14 @@ test('real earthquake lifecycle publishes host labels while runtime entities car
|
||||
});
|
||||
const layer = createEarthquakesLayer({ overlayHost });
|
||||
try {
|
||||
layer.init(viewer);
|
||||
layer.enable(viewer);
|
||||
await layer.update(viewer);
|
||||
layer.init(null, { engine: ground.engine });
|
||||
layer.enable();
|
||||
await layer.update();
|
||||
|
||||
const entities = dataSources[0].entities.values;
|
||||
assert.equal(entities.length, 2, 'runtime guard requires populated real source entities');
|
||||
assert.ok(entities.every((entity) => entity.label === undefined));
|
||||
const { items } = ground.set('earthquakes');
|
||||
assert.equal(items.length, 2, 'runtime guard requires populated ground discs');
|
||||
assert.ok(items.every((item) => Object.keys(item).every((key) =>
|
||||
['center', 'radiusM', 'fill', 'pickId'].includes(key))), 'a disc carries no label');
|
||||
const publication = hostCalls.find(([type]) => type === 'entries');
|
||||
assert.ok(publication, 'real update path must publish the overlay source');
|
||||
assert.deepEqual(publication[2].map(({ title }) => title), ['M5.2', 'M3.0']);
|
||||
@@ -146,14 +138,14 @@ test('real earthquake lifecycle publishes host labels while runtime entities car
|
||||
moving: false,
|
||||
});
|
||||
|
||||
layer.disable(viewer);
|
||||
assert.equal(dataSources[0].show, false);
|
||||
layer.disable();
|
||||
assert.equal(ground.set('earthquakes').shown, false);
|
||||
assert.deepEqual(hostCalls.slice(-2), [
|
||||
['clear', 'earthquakes'],
|
||||
['visible', 'earthquakes', false],
|
||||
]);
|
||||
layer.destroy(viewer);
|
||||
assert.equal(dataSources.length, 0);
|
||||
layer.destroy();
|
||||
assert.equal(ground.sets(), 0);
|
||||
assert.deepEqual(hostCalls.slice(-2), [
|
||||
['clear', 'earthquakes'],
|
||||
['visible', 'earthquakes', false],
|
||||
@@ -164,20 +156,14 @@ test('real earthquake lifecycle publishes host labels while runtime entities car
|
||||
});
|
||||
|
||||
// ── Perf pin: the 2026-08-20 earthquakes frame-rate cliff ────────────────────
|
||||
// Every disc is a CLAMP_TO_GROUND ellipse. When its axes were a
|
||||
// `CallbackProperty`, Cesium re-tessellated all 58 ground primitives on EVERY
|
||||
// frame: 32.4 ms/frame and 30 fps for 58 contacts, against 1.4 ms/60 fps with
|
||||
// the layer off. Static axes restored 60 fps. Both halves of the fix are
|
||||
// pinned — the runtime property shape, and the source-level guards.
|
||||
test('quake disc axes are STATIC — a per-frame callback re-tessellates ground geometry', async () => {
|
||||
// Every disc is ground geometry. When its axes were a per-frame callback,
|
||||
// Cesium re-tessellated all 58 ground primitives on EVERY frame: 32.4
|
||||
// ms/frame and 30 fps for 58 contacts, against 1.4 ms/60 fps with the layer
|
||||
// off. Static radii restored 60 fps. Both halves of the fix are pinned — one
|
||||
// commit per refresh with a plain radius, and the source-level guards.
|
||||
test('quake disc radii are STATIC — a per-frame rebuild re-tessellates ground geometry', async () => {
|
||||
const originalFetch = globalThis.fetch;
|
||||
const dataSources = [];
|
||||
const viewer = {
|
||||
dataSources: {
|
||||
add(dataSource) { dataSources.push(dataSource); return dataSource; },
|
||||
remove() { return true; },
|
||||
},
|
||||
};
|
||||
const ground = createFakeGroundHarness();
|
||||
const layer = createEarthquakesLayer({
|
||||
overlayHost: { setEntries() {}, setVisible() {}, clearSource() {} },
|
||||
});
|
||||
@@ -192,26 +178,25 @@ test('quake disc axes are STATIC — a per-frame callback re-tessellates ground
|
||||
}),
|
||||
});
|
||||
try {
|
||||
layer.init(viewer);
|
||||
layer.enable(viewer);
|
||||
await layer.update(viewer);
|
||||
layer.init(null, { engine: ground.engine });
|
||||
layer.enable();
|
||||
await layer.update();
|
||||
|
||||
const [entity] = dataSources[0].entities.values;
|
||||
assert.ok(entity.ellipse, 'the disc is an ellipse graphic');
|
||||
for (const axis of ['semiMajorAxis', 'semiMinorAxis']) {
|
||||
const property = entity.ellipse[axis];
|
||||
assert.equal(
|
||||
property instanceof Cesium.CallbackProperty,
|
||||
false,
|
||||
`${axis} must not be a CallbackProperty — it rebuilds the ground primitive every frame`,
|
||||
);
|
||||
assert.equal(property.isConstant, true, `${axis} must be a constant property`);
|
||||
// Magnitude 5.5 → 2^5.5 * 1000 m, unchanged by the dropped pulse.
|
||||
assert.equal(property.getValue(Cesium.JulianDate.now()), Math.pow(2, 5.5) * 1000);
|
||||
}
|
||||
const set = ground.set('earthquakes');
|
||||
const [disc] = set.items;
|
||||
assert.equal(set.options.kind, 'disc', 'the disc is a ground disc');
|
||||
// Magnitude 5.5 → 2^5.5 * 1000 m, unchanged by the dropped pulse.
|
||||
assert.equal(disc.radiusM, Math.pow(2, 5.5) * 1000);
|
||||
ground.engine.fake.frames(30);
|
||||
assert.equal(
|
||||
ground.set('earthquakes').commits,
|
||||
set.commits,
|
||||
'frames must not rebuild the ground discs',
|
||||
);
|
||||
} finally {
|
||||
globalThis.fetch = originalFetch;
|
||||
layer.destroy(viewer);
|
||||
layer.destroy();
|
||||
ground.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -223,13 +208,9 @@ test('quake disc axes are STATIC — a per-frame callback re-tessellates ground
|
||||
test('a quake poll still reaches the screen with the render loop idle', async () => {
|
||||
const originalFetch = globalThis.fetch;
|
||||
const renderRequests = [];
|
||||
const dataSources = [];
|
||||
const ground = createFakeGroundHarness();
|
||||
const viewer = {
|
||||
scene: { requestRenderMode: false, requestRender: () => renderRequests.push(Date.now()) },
|
||||
dataSources: {
|
||||
add(dataSource) { dataSources.push(dataSource); return dataSource; },
|
||||
remove() { return true; },
|
||||
},
|
||||
};
|
||||
const layer = createEarthquakesLayer({
|
||||
overlayHost: { setEntries() {}, setVisible() {}, clearSource() {} },
|
||||
@@ -251,7 +232,7 @@ test('a quake poll still reaches the screen with the render loop idle', async ()
|
||||
// frame. Drop that from the baseline or the enable assertion below can pass on
|
||||
// the install alone, without the manager ever requesting anything.
|
||||
renderRequests.length = 0;
|
||||
const manager = new DataLayerManager(viewer);
|
||||
const manager = new DataLayerManager(viewer, { engine: ground.engine });
|
||||
// updateInterval -1 keeps the poll loop unarmed; we drive one tick by hand.
|
||||
manager.register({ ...layer, updateInterval: -1 });
|
||||
try {
|
||||
@@ -264,7 +245,7 @@ test('a quake poll still reaches the screen with the render loop idle', async ()
|
||||
|
||||
// ...and the poll that populated the discs must still have asked for a frame,
|
||||
// because in idle mode nothing repaints on its own.
|
||||
assert.ok(dataSources[0].entities.values.length > 0, 'the enable poll produced discs');
|
||||
assert.ok(ground.set('earthquakes').items.length > 0, 'the enable poll produced discs');
|
||||
assert.ok(renderRequests.length > 0, 'enabling the layer must request a render in idle mode');
|
||||
// Named, not merely counted: the frame has to come from the manager's
|
||||
// visibility request, not from some incidental repaint.
|
||||
@@ -290,11 +271,12 @@ test('a quake poll still reaches the screen with the render loop idle', async ()
|
||||
globalThis.fetch = originalFetch;
|
||||
await manager.setEnabled('earthquakes', false, { origin: 'test' }).catch(() => {});
|
||||
_resetRenderGovernorForTest();
|
||||
ground.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
test('the earthquakes layer installs no per-frame callback and no continuous-render hold', () => {
|
||||
const source = ['index', 'model', 'source', 'render/cesium'].map(name =>
|
||||
const source = ['index', 'model', 'source', 'render/display'].map(name =>
|
||||
readFileSync(new URL(`../layers/earthquakes/${name}.js`, import.meta.url), 'utf8')).join('\n');
|
||||
assert.doesNotMatch(
|
||||
source,
|
||||
@@ -310,43 +292,36 @@ test('the earthquakes layer installs no per-frame callback and no continuous-ren
|
||||
|
||||
test('earthquake refresh reports failure and clears it only after a successful response', async () => {
|
||||
const originalFetch = globalThis.fetch;
|
||||
const dataSources = [];
|
||||
const viewer = {
|
||||
dataSources: {
|
||||
add(dataSource) { dataSources.push(dataSource); return dataSource; },
|
||||
remove() { return true; },
|
||||
},
|
||||
};
|
||||
const ground = createFakeGroundHarness();
|
||||
const layer = createEarthquakesLayer({
|
||||
overlayHost: { setEntries() {}, setVisible() {}, clearSource() {} },
|
||||
});
|
||||
try {
|
||||
layer.init(viewer);
|
||||
layer.enable(viewer);
|
||||
layer.init(null, { engine: ground.engine });
|
||||
layer.enable();
|
||||
globalThis.fetch = async () => ({ ok: false, status: 503 });
|
||||
assert.equal(await layer.update(viewer), false);
|
||||
assert.equal(await layer.update(), false);
|
||||
assert.equal(layer.getStats().error, 'USGS HTTP 503');
|
||||
|
||||
globalThis.fetch = async () => ({
|
||||
ok: true,
|
||||
json: async () => ({ features: [] }),
|
||||
});
|
||||
assert.equal(await layer.update(viewer), true);
|
||||
assert.equal(await layer.update(), true);
|
||||
assert.equal(layer.getStats().error, null);
|
||||
assert.ok(Number.isFinite(layer.getStats().lastUpdate));
|
||||
} finally {
|
||||
globalThis.fetch = originalFetch;
|
||||
layer.destroy(viewer);
|
||||
layer.destroy();
|
||||
ground.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
test('malformed earthquake refresh preserves entities, overlays, count and timestamp', async () => {
|
||||
test('malformed earthquake refresh preserves discs, overlays, count and timestamp', async () => {
|
||||
const originalFetch = globalThis.fetch;
|
||||
const dataSources = [];
|
||||
const ground = createFakeGroundHarness();
|
||||
const discs = () => ground.set('earthquakes').items;
|
||||
const publications = [];
|
||||
const viewer = { dataSources: {
|
||||
add(source) { dataSources.push(source); }, remove() { return true; },
|
||||
} };
|
||||
const layer = createEarthquakesLayer({ overlayHost: {
|
||||
setEntries(...args) { publications.push(args); }, setVisible() {}, clearSource() {},
|
||||
} });
|
||||
@@ -354,19 +329,18 @@ test('malformed earthquake refresh preserves entities, overlays, count and times
|
||||
properties: { mag: 4, time: 100, place: 'Fixture' } };
|
||||
const respond = (features) => { globalThis.fetch = async () => ({ ok: true, json: async () => ({ features }) }); };
|
||||
try {
|
||||
layer.init(viewer);
|
||||
layer.enable(viewer);
|
||||
layer.init(null, { engine: ground.engine });
|
||||
layer.enable();
|
||||
respond([good]);
|
||||
assert.equal(await layer.update(viewer), true);
|
||||
const entity = dataSources[0].entities.values[0];
|
||||
assert.equal(await layer.update(), true);
|
||||
const drawn = discs();
|
||||
const stats = layer.getStats();
|
||||
for (const properties of ['invalid', 123, [], true]) {
|
||||
const bad = { ...good, id: 'bad-properties', properties };
|
||||
for (const features of [[bad], [good, bad]]) {
|
||||
respond(features);
|
||||
assert.equal(await layer.update(viewer), false);
|
||||
assert.equal(dataSources[0].entities.values.length, 1);
|
||||
assert.equal(dataSources[0].entities.values[0], entity);
|
||||
assert.equal(await layer.update(), false);
|
||||
assert.equal(discs(), drawn);
|
||||
assert.equal(layer.getStats().count, stats.count);
|
||||
assert.equal(layer.getStats().lastUpdate, stats.lastUpdate);
|
||||
assert.equal(layer.getStats().error, 'Malformed USGS response');
|
||||
@@ -381,24 +355,24 @@ test('malformed earthquake refresh preserves entities, overlays, count and times
|
||||
{ ...good, properties: { mag: '4' } },
|
||||
{ ...good, properties: { mag: Infinity } }, good]) {
|
||||
respond([good, bad]);
|
||||
assert.equal(await layer.update(viewer), false);
|
||||
assert.equal(dataSources[0].entities.values.length, 1);
|
||||
assert.equal(dataSources[0].entities.values[0], entity);
|
||||
assert.equal(await layer.update(), false);
|
||||
assert.equal(discs(), drawn);
|
||||
assert.equal(layer.getStats().count, stats.count);
|
||||
assert.equal(layer.getStats().lastUpdate, stats.lastUpdate);
|
||||
assert.equal(layer.getStats().error, 'Malformed USGS response');
|
||||
assert.equal(publications.length, 1);
|
||||
}
|
||||
respond([{ ...good, properties: { mag: null } }]);
|
||||
assert.equal(await layer.update(viewer), true);
|
||||
assert.equal(dataSources[0].entities.values.length, 0);
|
||||
assert.equal(await layer.update(), true);
|
||||
assert.equal(discs().length, 0);
|
||||
assert.equal(layer.getStats().error, null);
|
||||
assert.equal(publications.at(-1)[1].length, 0);
|
||||
respond([good]);
|
||||
assert.equal(await layer.update(viewer), true);
|
||||
assert.equal(dataSources[0].entities.values.length, 1);
|
||||
assert.equal(await layer.update(), true);
|
||||
assert.equal(discs().length, 1);
|
||||
} finally {
|
||||
globalThis.fetch = originalFetch;
|
||||
layer.destroy(viewer);
|
||||
layer.destroy();
|
||||
ground.destroy();
|
||||
}
|
||||
});
|
||||
@@ -16,6 +16,8 @@ import {
|
||||
import { FIRE_ANCHOR_LIFT_M } from './fireAnchors.js';
|
||||
import { getLocale, setLocale } from '../i18n/index.js';
|
||||
import { reportMeshFloorCell, setMeshFloorPreferred } from './groundFloor.js';
|
||||
import { createCesiumMoversEngine } from '../testSupport/cesiumMoversEngine.mjs';
|
||||
import { createFakeEventHandlers } from '../globe/cesium/testing/fakeViewer.mjs';
|
||||
|
||||
const NOW = Date.UTC(2026, 6, 17, 4, 0);
|
||||
const H = 3600000;
|
||||
@@ -40,13 +42,24 @@ function fire(overrides = {}) {
|
||||
}
|
||||
|
||||
test('buildFireCard: title carries FRP, detail carries conf/age/satellite', () => {
|
||||
const card = buildFireCard({ fire: fire(), position: { x: 1, y: 2, z: 3 } }, NOW);
|
||||
const card = buildFireCard(
|
||||
{ fire: fire(), position: { x: 1, y: 2, z: 3 } },
|
||||
NOW,
|
||||
);
|
||||
assert.equal(card.title, '▲ 1520 MW');
|
||||
assert.equal(card.details.length, 1);
|
||||
assert.equal(card.details[0], 'high · 2h · N20');
|
||||
assert.equal(card.selected, false);
|
||||
assert.equal(card.accent, accentForSeverity('white-hot'), 'FRP 1520 is white-hot');
|
||||
assert.deepEqual(card.position, { x: 1, y: 2, z: 3 }, 'uses the candidate position untouched');
|
||||
assert.equal(
|
||||
card.accent,
|
||||
accentForSeverity('white-hot'),
|
||||
'FRP 1520 is white-hot',
|
||||
);
|
||||
assert.deepEqual(
|
||||
card.position,
|
||||
{ x: 1, y: 2, z: 3 },
|
||||
'uses the candidate position untouched',
|
||||
);
|
||||
});
|
||||
|
||||
test('buildFireCard: missing acquisition time omits the age segment', () => {
|
||||
@@ -60,17 +73,17 @@ test('buildFireCard: power that rounds to 10 MW drops the decimal', () => {
|
||||
NOW,
|
||||
);
|
||||
assert.equal(crossed.title, '▲ 10 MW');
|
||||
const below = buildFireCard(
|
||||
{ fire: fire({ frp: 9.94 }), position: {} },
|
||||
NOW,
|
||||
);
|
||||
const below = buildFireCard({ fire: fire({ frp: 9.94 }), position: {} }, NOW);
|
||||
assert.equal(below.title, '▲ 9.9 MW');
|
||||
const selected = buildSelectedFireCard(fire({ frp: 9.96 }), NOW);
|
||||
assert.equal(selected.title, 'FIRE · 10 MW');
|
||||
});
|
||||
|
||||
test('buildFireCard: SNPP satellite code renders as SNPP, weak fire is an ember', () => {
|
||||
const card = buildFireCard({ fire: fire({ satellite: 'N', frp: 0.8, confidence: 0.3 }), position: {} }, NOW);
|
||||
const card = buildFireCard(
|
||||
{ fire: fire({ satellite: 'N', frp: 0.8, confidence: 0.3 }), position: {} },
|
||||
NOW,
|
||||
);
|
||||
assert.match(card.details[0], /SNPP$/);
|
||||
assert.equal(card.title, '▲ 0.8 MW');
|
||||
assert.equal(card.accent, accentForSeverity('ember'));
|
||||
@@ -87,7 +100,10 @@ test('buildFireCard: accent steps through the FRP ramp at 5 · 20 · 50 · 100
|
||||
assert.equal(accentAt(300), accentForSeverity('white-hot'));
|
||||
// Confidence never moves the color: a low-confidence 864 MW fire stays red.
|
||||
assert.equal(
|
||||
buildFireCard({ fire: fire({ frp: 864, confidence: 0.3 }), position: {} }, NOW).accent,
|
||||
buildFireCard(
|
||||
{ fire: fire({ frp: 864, confidence: 0.3 }), position: {} },
|
||||
NOW,
|
||||
).accent,
|
||||
accentForSeverity('white-hot'),
|
||||
);
|
||||
});
|
||||
@@ -149,7 +165,10 @@ test('fire anchor: cold floor renders at 0, then re-grounds when the floor warms
|
||||
const f = fire({ lat: 55.501, lon: -120.501 });
|
||||
const before = buildSelectedFireCard(f, NOW);
|
||||
const cartoBefore = Cesium.Cartographic.fromCartesian(before.position);
|
||||
assert.ok(Math.abs(cartoBefore.height) < 0.5, `cold floor anchors at ellipsoid 0, got ${cartoBefore.height}`);
|
||||
assert.ok(
|
||||
Math.abs(cartoBefore.height) < 0.5,
|
||||
`cold floor anchors at ellipsoid 0, got ${cartoBefore.height}`,
|
||||
);
|
||||
|
||||
setMeshFloorPreferred(true);
|
||||
reportMeshFloorCell(55.501, -120.501, 900);
|
||||
@@ -157,23 +176,37 @@ test('fire anchor: cold floor renders at 0, then re-grounds when the floor warms
|
||||
const cartoAfter = Cesium.Cartographic.fromCartesian(after.position);
|
||||
assert.ok(
|
||||
Math.abs(cartoAfter.height - (900 + FIRE_ANCHOR_LIFT_M)) < 0.5,
|
||||
`warm floor re-anchors at floor + lift, got ${cartoAfter.height}`
|
||||
`warm floor re-anchors at floor + lift, got ${cartoAfter.height}`,
|
||||
);
|
||||
});
|
||||
|
||||
test('buildCellCard: singular noun and missing-age omission', () => {
|
||||
const candidate = { cell: { count: 1, maxFrp: 9.9, newestAcqMs: 0 }, position: {}, accent: undefined };
|
||||
const candidate = {
|
||||
cell: { count: 1, maxFrp: 9.9, newestAcqMs: 0 },
|
||||
position: {},
|
||||
accent: undefined,
|
||||
};
|
||||
const card = buildCellCard(candidate, NOW);
|
||||
assert.equal(card.title, '1 FIRE');
|
||||
assert.equal(card.details[0], 'max 9.9 MW');
|
||||
assert.equal(card.accent, accentForSeverity('ember'), 'missing accent defaults to the weakest stop');
|
||||
assert.equal(
|
||||
card.accent,
|
||||
accentForSeverity('ember'),
|
||||
'missing accent defaults to the weakest stop',
|
||||
);
|
||||
});
|
||||
|
||||
test('FIRMS host policy keeps ambient cards bounded and selected cards protected', () => {
|
||||
const ambient = applyFirmsOverlayPolicy(buildFireCard({
|
||||
fire: fire(),
|
||||
position: new Cesium.Cartesian3(1, 2, 3),
|
||||
}, NOW), 4_500_000);
|
||||
const ambient = applyFirmsOverlayPolicy(
|
||||
buildFireCard(
|
||||
{
|
||||
fire: fire(),
|
||||
position: new Cesium.Cartesian3(1, 2, 3),
|
||||
},
|
||||
NOW,
|
||||
),
|
||||
4_500_000,
|
||||
);
|
||||
assert.equal(ambient.variant, 'card');
|
||||
assert.equal(ambient.protected, false);
|
||||
assert.equal(ambient.collisionGroup, 'ambient-card');
|
||||
@@ -182,56 +215,38 @@ test('FIRMS host policy keeps ambient cards bounded and selected cards protected
|
||||
assert.equal(ambient.edgeFade, 'keyhole');
|
||||
assert.equal(ambient.cardStyle, 'tactical');
|
||||
assert.equal(ambient.verticalOnly, true);
|
||||
assert.equal(ambient.gapPx, Math.max(12, buildFireCard({ fire: fire(), position: {} }, NOW).gapPx + 8));
|
||||
assert.equal(
|
||||
ambient.gapPx,
|
||||
Math.max(12, buildFireCard({ fire: fire(), position: {} }, NOW).gapPx + 8),
|
||||
);
|
||||
assert.equal(ambient.leaderOffsetPx, ambient.gapPx - 6);
|
||||
|
||||
const selected = applyFirmsOverlayPolicy(buildSelectedFireCard(fire(), NOW), 4_500_000);
|
||||
const selected = applyFirmsOverlayPolicy(
|
||||
buildSelectedFireCard(fire(), NOW),
|
||||
4_500_000,
|
||||
);
|
||||
assert.equal(selected.variant, 'selected');
|
||||
assert.equal(selected.protected, true);
|
||||
assert.equal(selected.maxDistance, Number.POSITIVE_INFINITY);
|
||||
});
|
||||
|
||||
class MockEvent {
|
||||
constructor() { this.listeners = new Set(); }
|
||||
|
||||
addEventListener(listener) {
|
||||
this.listeners.add(listener);
|
||||
return () => this.listeners.delete(listener);
|
||||
}
|
||||
}
|
||||
|
||||
test('real FIRMS lifecycle clears host entries on disable and destroy', async () => {
|
||||
const originalFetch = globalThis.fetch;
|
||||
const originalWindow = globalThis.window;
|
||||
const calls = [];
|
||||
const preRender = new MockEvent();
|
||||
const moveEnd = new MockEvent();
|
||||
globalThis.fetch = async () => ({
|
||||
ok: false,
|
||||
status: 503,
|
||||
json: async () => ({ error: 'no_key' }),
|
||||
});
|
||||
globalThis.window = new EventTarget();
|
||||
const dataSources = [];
|
||||
const viewer = {
|
||||
dataSources: {
|
||||
add(value) { dataSources.push(value); return value; },
|
||||
remove(value) {
|
||||
const index = dataSources.indexOf(value);
|
||||
if (index >= 0) dataSources.splice(index, 1);
|
||||
},
|
||||
},
|
||||
camera: {
|
||||
moveEnd,
|
||||
positionWC: Cesium.Cartesian3.fromDegrees(-97.7, 30.2, 1_000_000),
|
||||
positionCartographic: { height: 1_000_000 },
|
||||
},
|
||||
scene: {
|
||||
canvas: { clientWidth: 800, clientHeight: 600 },
|
||||
preRender,
|
||||
primitives: { contains() { return false; } },
|
||||
},
|
||||
};
|
||||
const { engine, viewer } = createCesiumMoversEngine({
|
||||
engineOptions: { createEventHandler: createFakeEventHandlers().create },
|
||||
});
|
||||
viewer.scene.groundPrimitives = new Cesium.PrimitiveCollection();
|
||||
engine.camera.setView({
|
||||
destination: Cesium.Cartesian3.fromDegrees(-97.7, 30.2, 1_000_000),
|
||||
});
|
||||
const layer = createFirmsHeatmapLayer({
|
||||
id: 'firms',
|
||||
name: 'FIRMS',
|
||||
@@ -240,29 +255,33 @@ test('real FIRMS lifecycle clears host entries on disable and destroy', async ()
|
||||
setVisible: (...args) => calls.push(['visible', ...args]),
|
||||
clearSource: (...args) => calls.push(['clear', ...args]),
|
||||
},
|
||||
screenSpaceEventHandlerFactory: () => ({ setInputAction() {}, destroy() {} }),
|
||||
});
|
||||
try {
|
||||
layer.init(viewer);
|
||||
await layer.enable(viewer);
|
||||
layer.init(null, { engine });
|
||||
await layer.enable();
|
||||
assert.deepEqual(calls.at(-1), ['visible', FIRMS_OVERLAY_SOURCE_ID, true]);
|
||||
layer.disable();
|
||||
assert.deepEqual(calls.slice(-2), [
|
||||
['clear', FIRMS_OVERLAY_SOURCE_ID],
|
||||
['visible', FIRMS_OVERLAY_SOURCE_ID, false],
|
||||
]);
|
||||
await layer.enable(viewer);
|
||||
layer.destroy(viewer);
|
||||
await layer.enable();
|
||||
layer.destroy();
|
||||
assert.ok(calls.some(([type]) => type === 'clear'));
|
||||
assert.deepEqual(calls.slice(-2), [
|
||||
['clear', FIRMS_OVERLAY_SOURCE_ID],
|
||||
['visible', FIRMS_OVERLAY_SOURCE_ID, false],
|
||||
]);
|
||||
const callCount = calls.length;
|
||||
await layer.enable(viewer);
|
||||
assert.equal(calls.length, callCount, 'destroyed FIRMS layers reject late enable work');
|
||||
await layer.enable();
|
||||
assert.equal(
|
||||
calls.length,
|
||||
callCount,
|
||||
'destroyed FIRMS layers reject late enable work',
|
||||
);
|
||||
assert.equal(FIRMS_AMBIENT_COHORT_LIMIT, 18);
|
||||
} finally {
|
||||
engine.destroy();
|
||||
globalThis.fetch = originalFetch;
|
||||
if (originalWindow === undefined) delete globalThis.window;
|
||||
else globalThis.window = originalWindow;
|
||||
|
||||
+417
-143
@@ -7,14 +7,22 @@ import {
|
||||
fireCullPosition,
|
||||
} from './firmsHeatmap.js';
|
||||
import { FIRE_ANCHOR_LIFT_M } from './fireAnchors.js';
|
||||
import { FIRMS_AMBIENT_COHORT_LIMIT, FIRMS_OVERLAY_SOURCE_ID } from './firmsLabels.js';
|
||||
import {
|
||||
FIRMS_AMBIENT_COHORT_LIMIT,
|
||||
FIRMS_OVERLAY_SOURCE_ID,
|
||||
} from './firmsLabels.js';
|
||||
import {
|
||||
_clearMeshFloorCellsForTest,
|
||||
reportMeshFloorCell,
|
||||
setMeshFloorPreferred,
|
||||
} from './groundFloor.js';
|
||||
import { unregisterSpriteCollection } from './spriteOrder.js';
|
||||
import { isOverlayPointVisible, normalizeOverlayEntry } from '../overlays/worldOverlay.js';
|
||||
import { createCesiumMoversEngine } from '../testSupport/cesiumMoversEngine.mjs';
|
||||
import { createFakeEventHandlers } from '../globe/cesium/testing/fakeViewer.mjs';
|
||||
import { createFirmsDisplay } from '../layers/firms/render/display.js';
|
||||
import {
|
||||
isOverlayPointVisible,
|
||||
normalizeOverlayEntry,
|
||||
} from '../overlays/worldOverlay.js';
|
||||
|
||||
const AUSTIN = { lon: -97.7, lat: 30.2 };
|
||||
/** Antipode of Austin — as far behind the limb as a point on Earth can be. */
|
||||
@@ -38,8 +46,13 @@ function billboard(position, show = true) {
|
||||
position,
|
||||
_show: show,
|
||||
writes: 0,
|
||||
get show() { return this._show; },
|
||||
set show(value) { this._show = value; this.writes += 1; },
|
||||
get show() {
|
||||
return this._show;
|
||||
},
|
||||
set show(value) {
|
||||
this._show = value;
|
||||
this.writes += 1;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -62,17 +75,36 @@ function occluderOverAustin(heightM) {
|
||||
|
||||
test('applyHorizonCull: far-side fires are hidden, near-side fires stay visible', () => {
|
||||
const occluder = occluderOverAustin(REPRO_HEIGHT_M);
|
||||
const near = billboard(Cesium.Cartesian3.fromDegrees(AUSTIN.lon, AUSTIN.lat, 0));
|
||||
const nearby = billboard(Cesium.Cartesian3.fromDegrees(AUSTIN.lon + 6, AUSTIN.lat + 4, 0));
|
||||
const far = billboard(Cesium.Cartesian3.fromDegrees(ANTIPODE.lon, ANTIPODE.lat, 0));
|
||||
const otherSide = billboard(Cesium.Cartesian3.fromDegrees(TOKYO.lon, TOKYO.lat, 0));
|
||||
const near = billboard(
|
||||
Cesium.Cartesian3.fromDegrees(AUSTIN.lon, AUSTIN.lat, 0),
|
||||
);
|
||||
const nearby = billboard(
|
||||
Cesium.Cartesian3.fromDegrees(AUSTIN.lon + 6, AUSTIN.lat + 4, 0),
|
||||
);
|
||||
const far = billboard(
|
||||
Cesium.Cartesian3.fromDegrees(ANTIPODE.lon, ANTIPODE.lat, 0),
|
||||
);
|
||||
const otherSide = billboard(
|
||||
Cesium.Cartesian3.fromDegrees(TOKYO.lon, TOKYO.lat, 0),
|
||||
);
|
||||
|
||||
const visible = applyHorizonCull(collection([near, nearby, far, otherSide]), occluder);
|
||||
const visible = applyHorizonCull(
|
||||
collection([near, nearby, far, otherSide]),
|
||||
occluder,
|
||||
);
|
||||
|
||||
assert.equal(near.show, true, 'the fire under the camera renders');
|
||||
assert.equal(nearby.show, true, 'a fire well inside the horizon renders');
|
||||
assert.equal(far.show, false, 'the antipodal fire must not shine through the planet');
|
||||
assert.equal(otherSide.show, false, 'Tokyo is beyond the limb from Austin at 1.5 Mm');
|
||||
assert.equal(
|
||||
far.show,
|
||||
false,
|
||||
'the antipodal fire must not shine through the planet',
|
||||
);
|
||||
assert.equal(
|
||||
otherSide.show,
|
||||
false,
|
||||
'Tokyo is beyond the limb from Austin at 1.5 Mm',
|
||||
);
|
||||
assert.equal(visible, 2, 'returns the surviving count');
|
||||
});
|
||||
|
||||
@@ -81,15 +113,26 @@ test('applyHorizonCull: raising the camera reveals fires the low camera hid', ()
|
||||
|
||||
const low = paris();
|
||||
applyHorizonCull(collection([low]), occluderOverAustin(REPRO_HEIGHT_M));
|
||||
assert.equal(low.show, false, 'Paris is over the horizon from a 1.5 Mm Austin camera');
|
||||
assert.equal(
|
||||
low.show,
|
||||
false,
|
||||
'Paris is over the horizon from a 1.5 Mm Austin camera',
|
||||
);
|
||||
|
||||
const high = paris();
|
||||
applyHorizonCull(collection([high]), occluderOverAustin(35_000_000));
|
||||
assert.equal(high.show, true, 'from geostationary height the same fire is in view');
|
||||
assert.equal(
|
||||
high.show,
|
||||
true,
|
||||
'from geostationary height the same fire is in view',
|
||||
);
|
||||
});
|
||||
|
||||
test('applyHorizonCull: a hidden fire is restored when it swings back into view', () => {
|
||||
const revealed = billboard(Cesium.Cartesian3.fromDegrees(AUSTIN.lon, AUSTIN.lat, 0), false);
|
||||
const revealed = billboard(
|
||||
Cesium.Cartesian3.fromDegrees(AUSTIN.lon, AUSTIN.lat, 0),
|
||||
false,
|
||||
);
|
||||
applyHorizonCull(collection([revealed]), occluderOverAustin(REPRO_HEIGHT_M));
|
||||
assert.equal(revealed.show, true, 'the cull un-hides as well as hides');
|
||||
assert.equal(revealed.writes, 1);
|
||||
@@ -97,25 +140,56 @@ test('applyHorizonCull: a hidden fire is restored when it swings back into view'
|
||||
|
||||
test('applyHorizonCull: only flipped billboards are written (vertex-buffer churn)', () => {
|
||||
const occluder = occluderOverAustin(REPRO_HEIGHT_M);
|
||||
const stays = billboard(Cesium.Cartesian3.fromDegrees(AUSTIN.lon, AUSTIN.lat, 0), true);
|
||||
const flips = billboard(Cesium.Cartesian3.fromDegrees(ANTIPODE.lon, ANTIPODE.lat, 0), true);
|
||||
const stays = billboard(
|
||||
Cesium.Cartesian3.fromDegrees(AUSTIN.lon, AUSTIN.lat, 0),
|
||||
true,
|
||||
);
|
||||
const flips = billboard(
|
||||
Cesium.Cartesian3.fromDegrees(ANTIPODE.lon, ANTIPODE.lat, 0),
|
||||
true,
|
||||
);
|
||||
|
||||
applyHorizonCull(collection([stays, flips]), occluder);
|
||||
applyHorizonCull(collection([stays, flips]), occluder);
|
||||
|
||||
assert.equal(stays.writes, 0, 'an already-visible billboard is never re-assigned');
|
||||
assert.equal(flips.writes, 1, 'a hidden billboard is written once, not once per pass');
|
||||
assert.equal(
|
||||
stays.writes,
|
||||
0,
|
||||
'an already-visible billboard is never re-assigned',
|
||||
);
|
||||
assert.equal(
|
||||
flips.writes,
|
||||
1,
|
||||
'a hidden billboard is written once, not once per pass',
|
||||
);
|
||||
});
|
||||
|
||||
test('applyHorizonCull: missing collection/occluder/holes are no-ops, not throws', () => {
|
||||
assert.equal(applyHorizonCull(null, occluderOverAustin(REPRO_HEIGHT_M)), 0);
|
||||
assert.equal(applyHorizonCull({ length: 3 }, occluderOverAustin(REPRO_HEIGHT_M)), 0, 'non-collection shape');
|
||||
const item = billboard(Cesium.Cartesian3.fromDegrees(AUSTIN.lon, AUSTIN.lat, 0));
|
||||
assert.equal(applyHorizonCull(collection([item]), null), 0, 'no occluder → leave the layer alone');
|
||||
assert.equal(applyHorizonCull(collection([item]), {}), 0, 'occluder without isPointVisible');
|
||||
assert.equal(
|
||||
applyHorizonCull({ length: 3 }, occluderOverAustin(REPRO_HEIGHT_M)),
|
||||
0,
|
||||
'non-collection shape',
|
||||
);
|
||||
const item = billboard(
|
||||
Cesium.Cartesian3.fromDegrees(AUSTIN.lon, AUSTIN.lat, 0),
|
||||
);
|
||||
assert.equal(
|
||||
applyHorizonCull(collection([item]), null),
|
||||
0,
|
||||
'no occluder → leave the layer alone',
|
||||
);
|
||||
assert.equal(
|
||||
applyHorizonCull(collection([item]), {}),
|
||||
0,
|
||||
'occluder without isPointVisible',
|
||||
);
|
||||
assert.equal(item.writes, 0, 'a skipped pass must not touch show');
|
||||
assert.equal(
|
||||
applyHorizonCull(collection([undefined, item]), occluderOverAustin(REPRO_HEIGHT_M)),
|
||||
applyHorizonCull(
|
||||
collection([undefined, item]),
|
||||
occluderOverAustin(REPRO_HEIGHT_M),
|
||||
),
|
||||
1,
|
||||
'sparse slots are skipped, surviving neighbours still counted',
|
||||
);
|
||||
@@ -127,22 +201,42 @@ test('applyHorizonCull: missing collection/occluder/holes are no-ops, not throws
|
||||
|
||||
test('applyHorizonCull: an index-aligned cull position overrides the render anchor', () => {
|
||||
const occluder = occluderOverAustin(REPRO_HEIGHT_M);
|
||||
const sunken = billboard(Cesium.Cartesian3.fromDegrees(AUSTIN.lon + LIMB_DLON, AUSTIN.lat, -22));
|
||||
const lifted = Cesium.Cartesian3.fromDegrees(AUSTIN.lon + LIMB_DLON, AUSTIN.lat, 12);
|
||||
const sunken = billboard(
|
||||
Cesium.Cartesian3.fromDegrees(AUSTIN.lon + LIMB_DLON, AUSTIN.lat, -22),
|
||||
);
|
||||
const lifted = Cesium.Cartesian3.fromDegrees(
|
||||
AUSTIN.lon + LIMB_DLON,
|
||||
AUSTIN.lat,
|
||||
12,
|
||||
);
|
||||
|
||||
applyHorizonCull(collection([sunken]), occluder);
|
||||
assert.equal(sunken.show, false, 'baseline: the raw sub-ellipsoid anchor false-hides at the limb');
|
||||
assert.equal(
|
||||
sunken.show,
|
||||
false,
|
||||
'baseline: the raw sub-ellipsoid anchor false-hides at the limb',
|
||||
);
|
||||
|
||||
applyHorizonCull(collection([sunken]), occluder, [lifted]);
|
||||
assert.equal(sunken.show, true, 'the lifted cull point keeps the near-limb fire on screen');
|
||||
assert.equal(
|
||||
sunken.show,
|
||||
true,
|
||||
'the lifted cull point keeps the near-limb fire on screen',
|
||||
);
|
||||
});
|
||||
|
||||
test('applyHorizonCull: a lifted cull point does NOT resurrect a genuinely far-side fire', () => {
|
||||
const occluder = occluderOverAustin(REPRO_HEIGHT_M);
|
||||
const far = billboard(Cesium.Cartesian3.fromDegrees(ANTIPODE.lon, ANTIPODE.lat, -22));
|
||||
const far = billboard(
|
||||
Cesium.Cartesian3.fromDegrees(ANTIPODE.lon, ANTIPODE.lat, -22),
|
||||
);
|
||||
const lifted = Cesium.Cartesian3.fromDegrees(ANTIPODE.lon, ANTIPODE.lat, 12);
|
||||
applyHorizonCull(collection([far]), occluder, [lifted]);
|
||||
assert.equal(far.show, false, '12 m of lift must not defeat the actual horizon cull');
|
||||
assert.equal(
|
||||
far.show,
|
||||
false,
|
||||
'12 m of lift must not defeat the actual horizon cull',
|
||||
);
|
||||
});
|
||||
|
||||
test('fireCullPosition: negative-geoid anchor renders at the datum but culls lifted', () => {
|
||||
@@ -160,15 +254,34 @@ test('fireCullPosition: negative-geoid anchor renders at the datum but culls lif
|
||||
`render anchor stays datum-correct at ${-27 + FIRE_ANCHOR_LIFT_M} m, got ${renderCarto.height}`,
|
||||
);
|
||||
|
||||
assert.notEqual(cull, render, 'a sub-ellipsoid anchor gets a separate cull point');
|
||||
assert.notEqual(
|
||||
cull,
|
||||
render,
|
||||
'a sub-ellipsoid anchor gets a separate cull point',
|
||||
);
|
||||
const cullCarto = Cesium.Cartographic.fromCartesian(cull);
|
||||
assert.ok(Math.abs(cullCarto.height - 12) < 0.5, `cull point lifted to 12 m, got ${cullCarto.height}`);
|
||||
assert.equal(fireCullPosition(fire), cull, 'the lifted point is cached, not re-allocated per call');
|
||||
assert.ok(
|
||||
Math.abs(cullCarto.height - 12) < 0.5,
|
||||
`cull point lifted to 12 m, got ${cullCarto.height}`,
|
||||
);
|
||||
assert.equal(
|
||||
fireCullPosition(fire),
|
||||
cull,
|
||||
'the lifted point is cached, not re-allocated per call',
|
||||
);
|
||||
|
||||
// The whole point: the datum-correct point would be culled here, the lifted one is not.
|
||||
const occluder = occluderOverAustin(REPRO_HEIGHT_M);
|
||||
assert.equal(occluder.isPointVisible(render), false, 'baseline defect: −22 m reads beyond the horizon');
|
||||
assert.equal(occluder.isPointVisible(cull), true, 'lifted cull point reads correctly as in view');
|
||||
assert.equal(
|
||||
occluder.isPointVisible(render),
|
||||
false,
|
||||
'baseline defect: −22 m reads beyond the horizon',
|
||||
);
|
||||
assert.equal(
|
||||
occluder.isPointVisible(cull),
|
||||
true,
|
||||
'lifted cull point reads correctly as in view',
|
||||
);
|
||||
} finally {
|
||||
_clearMeshFloorCellsForTest();
|
||||
setMeshFloorPreferred(false);
|
||||
@@ -183,7 +296,11 @@ test('fireCullPosition: a healthy above-ellipsoid anchor is its own cull point',
|
||||
try {
|
||||
const fire = { index: 2, lat, lon, frp: 10, position: null };
|
||||
const cull = fireCullPosition(fire);
|
||||
assert.equal(cull, fire.position, 'no second Cartesian is allocated for the common case');
|
||||
assert.equal(
|
||||
cull,
|
||||
fire.position,
|
||||
'no second Cartesian is allocated for the common case',
|
||||
);
|
||||
} finally {
|
||||
_clearMeshFloorCellsForTest();
|
||||
setMeshFloorPreferred(false);
|
||||
@@ -197,23 +314,50 @@ test('fireCullPosition: a healthy above-ellipsoid anchor is its own cull point',
|
||||
test('isOverlayPointVisible: horizon test prefers entry.cullPosition when present', () => {
|
||||
const viewport = { width: 800, height: 600 };
|
||||
const screen = { x: 400, y: 300 };
|
||||
const render = Cesium.Cartesian3.fromDegrees(AUSTIN.lon + LIMB_DLON, AUSTIN.lat, -22);
|
||||
const lifted = Cesium.Cartesian3.fromDegrees(AUSTIN.lon + LIMB_DLON, AUSTIN.lat, 12);
|
||||
const render = Cesium.Cartesian3.fromDegrees(
|
||||
AUSTIN.lon + LIMB_DLON,
|
||||
AUSTIN.lat,
|
||||
-22,
|
||||
);
|
||||
const lifted = Cesium.Cartesian3.fromDegrees(
|
||||
AUSTIN.lon + LIMB_DLON,
|
||||
AUSTIN.lat,
|
||||
12,
|
||||
);
|
||||
const occluder = occluderOverAustin(REPRO_HEIGHT_M);
|
||||
|
||||
assert.equal(
|
||||
isOverlayPointVisible({ horizonCull: true }, render, screen, viewport, occluder),
|
||||
isOverlayPointVisible(
|
||||
{ horizonCull: true },
|
||||
render,
|
||||
screen,
|
||||
viewport,
|
||||
occluder,
|
||||
),
|
||||
false,
|
||||
'baseline: the render anchor alone false-hides the card',
|
||||
);
|
||||
assert.equal(
|
||||
isOverlayPointVisible({ horizonCull: true, cullPosition: lifted }, render, screen, viewport, occluder),
|
||||
isOverlayPointVisible(
|
||||
{ horizonCull: true, cullPosition: lifted },
|
||||
render,
|
||||
screen,
|
||||
viewport,
|
||||
occluder,
|
||||
),
|
||||
true,
|
||||
'the supplied cull position is what the horizon test uses',
|
||||
);
|
||||
assert.equal(
|
||||
isOverlayPointVisible(
|
||||
{ horizonCull: true, cullPosition: Cesium.Cartesian3.fromDegrees(ANTIPODE.lon, ANTIPODE.lat, 12) },
|
||||
{
|
||||
horizonCull: true,
|
||||
cullPosition: Cesium.Cartesian3.fromDegrees(
|
||||
ANTIPODE.lon,
|
||||
ANTIPODE.lat,
|
||||
12,
|
||||
),
|
||||
},
|
||||
render,
|
||||
screen,
|
||||
viewport,
|
||||
@@ -227,37 +371,80 @@ test('isOverlayPointVisible: horizon test prefers entry.cullPosition when presen
|
||||
test('normalizeOverlayEntry: carries a valid cullPosition, nulls a junk one', () => {
|
||||
const position = { x: 1, y: 2, z: 3 };
|
||||
const source = { x: 4, y: 5, z: 6 };
|
||||
const kept = normalizeOverlayEntry('firms', { id: 'a', position, cullPosition: source });
|
||||
assert.notEqual(kept.cullPosition, source, 'stored as a host-owned copy (a geo Cartesian3)');
|
||||
assert.ok(!(kept.cullPosition instanceof Cesium.Cartesian3), 'not a Cesium value');
|
||||
const kept = normalizeOverlayEntry('firms', {
|
||||
id: 'a',
|
||||
position,
|
||||
cullPosition: source,
|
||||
});
|
||||
assert.notEqual(
|
||||
kept.cullPosition,
|
||||
source,
|
||||
'stored as a host-owned copy (a geo Cartesian3)',
|
||||
);
|
||||
assert.ok(
|
||||
!(kept.cullPosition instanceof Cesium.Cartesian3),
|
||||
'not a Cesium value',
|
||||
);
|
||||
assert.deepEqual(
|
||||
[kept.cullPosition.x, kept.cullPosition.y, kept.cullPosition.z],
|
||||
[4, 5, 6],
|
||||
);
|
||||
const dropped = normalizeOverlayEntry('firms', { id: 'b', position, cullPosition: { x: NaN, y: 5, z: 6 } });
|
||||
assert.equal(dropped.cullPosition, null, 'a malformed cull point falls back to the render position');
|
||||
const notAnObject = normalizeOverlayEntry('firms', { id: 'b2', position, cullPosition: 42 });
|
||||
assert.equal(notAnObject.cullPosition, null, 'a non-object cull point is rejected');
|
||||
const dropped = normalizeOverlayEntry('firms', {
|
||||
id: 'b',
|
||||
position,
|
||||
cullPosition: { x: NaN, y: 5, z: 6 },
|
||||
});
|
||||
assert.equal(
|
||||
dropped.cullPosition,
|
||||
null,
|
||||
'a malformed cull point falls back to the render position',
|
||||
);
|
||||
const notAnObject = normalizeOverlayEntry('firms', {
|
||||
id: 'b2',
|
||||
position,
|
||||
cullPosition: 42,
|
||||
});
|
||||
assert.equal(
|
||||
notAnObject.cullPosition,
|
||||
null,
|
||||
'a non-object cull point is rejected',
|
||||
);
|
||||
// Non-adopting sources keep their existing BEHAVIOUR and steady-frame
|
||||
// allocation profile; the normalized record does gain an enumerable
|
||||
// `cullPosition: null` field, which is why this asserts null rather than
|
||||
// absence.
|
||||
const absent = normalizeOverlayEntry('firms', { id: 'c', position });
|
||||
assert.equal(absent.cullPosition, null, 'sources that do not opt in resolve to no cull anchor');
|
||||
assert.equal(
|
||||
absent.cullPosition,
|
||||
null,
|
||||
'sources that do not opt in resolve to no cull anchor',
|
||||
);
|
||||
});
|
||||
|
||||
test('normalizeOverlayEntry: the stored cull anchor is a snapshot, not the caller object', () => {
|
||||
const position = { x: 1, y: 2, z: 3 };
|
||||
const caller = new Cesium.Cartesian3(4, 5, 6);
|
||||
const normalized = normalizeOverlayEntry('firms', { id: 'a', position, cullPosition: caller });
|
||||
assert.notEqual(normalized.cullPosition, caller, 'the host must not retain the caller reference');
|
||||
const normalized = normalizeOverlayEntry('firms', {
|
||||
id: 'a',
|
||||
position,
|
||||
cullPosition: caller,
|
||||
});
|
||||
assert.notEqual(
|
||||
normalized.cullPosition,
|
||||
caller,
|
||||
'the host must not retain the caller reference',
|
||||
);
|
||||
|
||||
// Sources legitimately recycle scratch vectors between publishes; a mutation
|
||||
// after normalization must never reach the per-frame occluder.
|
||||
caller.x = NaN;
|
||||
caller.y = 999;
|
||||
assert.deepEqual(
|
||||
[normalized.cullPosition.x, normalized.cullPosition.y, normalized.cullPosition.z],
|
||||
[
|
||||
normalized.cullPosition.x,
|
||||
normalized.cullPosition.y,
|
||||
normalized.cullPosition.z,
|
||||
],
|
||||
[4, 5, 6],
|
||||
'post-normalize mutation of the source vector has no effect',
|
||||
);
|
||||
@@ -277,7 +464,11 @@ test('normalizeOverlayEntry: an accessor-backed cullPosition is read exactly onc
|
||||
const normalized = normalizeOverlayEntry('firms', entry);
|
||||
assert.equal(reads, 1, 'one property read — not one per validated component');
|
||||
assert.deepEqual(
|
||||
[normalized.cullPosition.x, normalized.cullPosition.y, normalized.cullPosition.z],
|
||||
[
|
||||
normalized.cullPosition.x,
|
||||
normalized.cullPosition.y,
|
||||
normalized.cullPosition.z,
|
||||
],
|
||||
[4, 5, 6],
|
||||
);
|
||||
});
|
||||
@@ -288,11 +479,21 @@ test('normalizeOverlayEntry: a throwing cullPosition accessor does not abort nor
|
||||
id: 'a',
|
||||
position,
|
||||
title: 'still normalized',
|
||||
get cullPosition() { throw new Error('hostile accessor'); },
|
||||
get cullPosition() {
|
||||
throw new Error('hostile accessor');
|
||||
},
|
||||
};
|
||||
const normalized = normalizeOverlayEntry('firms', entry);
|
||||
assert.equal(normalized.cullPosition, null, 'the bad anchor degrades to null');
|
||||
assert.equal(normalized.title, 'still normalized', 'the rest of the entry survives');
|
||||
assert.equal(
|
||||
normalized.cullPosition,
|
||||
null,
|
||||
'the bad anchor degrades to null',
|
||||
);
|
||||
assert.equal(
|
||||
normalized.title,
|
||||
'still normalized',
|
||||
'the rest of the entry survives',
|
||||
);
|
||||
assert.equal(normalized.id, 'a');
|
||||
});
|
||||
|
||||
@@ -300,12 +501,6 @@ test('normalizeOverlayEntry: a throwing cullPosition accessor does not abort nor
|
||||
// Layer integration: the three production hooks
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
class MockEvent {
|
||||
constructor() { this.listeners = new Set(); }
|
||||
addEventListener(listener) { this.listeners.add(listener); return () => this.listeners.delete(listener); }
|
||||
emit() { for (const listener of [...this.listeners]) listener(); }
|
||||
}
|
||||
|
||||
/** Canvas stub good enough for the pre-baked glow sprites. */
|
||||
function canvasStub() {
|
||||
return {
|
||||
@@ -337,9 +532,10 @@ function rawFire(lat, lon, frp) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Boots the REAL layer against a headless viewer stub with a REAL
|
||||
* Cesium.BillboardCollection, so the production hooks (not just the pure
|
||||
* predicate) are what the assertions exercise.
|
||||
* Boots the REAL layer on the Cesium engine over a stub scene with a REAL
|
||||
* Cesium.Camera and the engine's REAL Cesium.BillboardCollection, so the
|
||||
* production hooks (not just the pure predicate) are what the assertions
|
||||
* exercise.
|
||||
*/
|
||||
function createHarness(rawFires) {
|
||||
const originalFetch = globalThis.fetch;
|
||||
@@ -357,9 +553,14 @@ function createHarness(rawFires) {
|
||||
|
||||
// Deterministic projection: every distinct world position gets its own
|
||||
// 200 px grid slot (well clear of LABEL_MIN_SEP_PX) inside a 2000×2000
|
||||
// canvas, so declutter geometry never decides these assertions.
|
||||
// canvas, so declutter geometry never decides these assertions. The
|
||||
// engine's projector reads it when the engine is made.
|
||||
const slots = new Map();
|
||||
Cesium.SceneTransforms.worldToWindowCoordinates = (scene, position, result) => {
|
||||
Cesium.SceneTransforms.worldToWindowCoordinates = (
|
||||
scene,
|
||||
position,
|
||||
result,
|
||||
) => {
|
||||
if (!slots.has(position)) slots.set(position, slots.size);
|
||||
const slot = slots.get(position);
|
||||
const out = result || new Cesium.Cartesian2();
|
||||
@@ -368,30 +569,21 @@ function createHarness(rawFires) {
|
||||
return out;
|
||||
};
|
||||
|
||||
const preRender = new MockEvent();
|
||||
const moveEnd = new MockEvent();
|
||||
const primitives = [];
|
||||
const { engine, viewer, primitive, frame } = createCesiumMoversEngine({
|
||||
engineOptions: { createEventHandler: createFakeEventHandlers().create },
|
||||
});
|
||||
viewer.scene.groundPrimitives = new Cesium.PrimitiveCollection();
|
||||
Object.assign(viewer.scene.canvas, { clientWidth: 2000, clientHeight: 2000 });
|
||||
// No view rectangle (Cesium's answer for a view of the sky or the whole
|
||||
// globe): the layer draws the globally strongest detections, so far-side
|
||||
// fires are drawn and only the horizon pass decides what shows.
|
||||
viewer.camera.computeViewRectangle = () => undefined;
|
||||
const moveCameraTo = (lon, lat, height = REPRO_HEIGHT_M) =>
|
||||
engine.camera.setView({
|
||||
destination: Cesium.Cartesian3.fromDegrees(lon, lat, height),
|
||||
});
|
||||
moveCameraTo(AUSTIN.lon, AUSTIN.lat);
|
||||
const entryCalls = [];
|
||||
const viewer = {
|
||||
dataSources: { add: (value) => value, remove: () => {} },
|
||||
camera: {
|
||||
moveEnd,
|
||||
positionWC: Cesium.Cartesian3.fromDegrees(AUSTIN.lon, AUSTIN.lat, REPRO_HEIGHT_M),
|
||||
directionWC: new Cesium.Cartesian3(0, 0, -1),
|
||||
positionCartographic: { height: REPRO_HEIGHT_M },
|
||||
},
|
||||
scene: {
|
||||
canvas: { clientWidth: 2000, clientHeight: 2000 },
|
||||
preRender,
|
||||
primitives: {
|
||||
add: (value) => { primitives.push(value); return value; },
|
||||
remove: () => {},
|
||||
contains: () => false,
|
||||
},
|
||||
frameState: { mode: Cesium.SceneMode.SCENE3D, mapProjection: new Cesium.GeographicProjection() },
|
||||
mapProjection: new Cesium.GeographicProjection(),
|
||||
},
|
||||
};
|
||||
|
||||
const layer = createFirmsHeatmapLayer({
|
||||
id: 'firms',
|
||||
@@ -401,36 +593,58 @@ function createHarness(rawFires) {
|
||||
setVisible: () => {},
|
||||
clearSource: () => {},
|
||||
},
|
||||
screenSpaceEventHandlerFactory: () => ({ setInputAction() {}, destroy() {} }),
|
||||
// The display the registry gives every engine, with image seams.
|
||||
renderer: {
|
||||
create: ({ engine: target, ...options }) =>
|
||||
createFirmsDisplay(target, {
|
||||
...options,
|
||||
loadImage: async () => ({ width: 16, height: 16 }),
|
||||
createCanvas: () => ({ getContext: () => ({ drawImage() {} }) }),
|
||||
}),
|
||||
},
|
||||
});
|
||||
const settle = async () => {
|
||||
for (let i = 0; i < 4; i++)
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
};
|
||||
const drawnCount = () =>
|
||||
engine.movers.list().find((set) => set.id === 'firms:firms')?.count ?? 0;
|
||||
|
||||
return {
|
||||
layer,
|
||||
viewer,
|
||||
preRender,
|
||||
moveEnd,
|
||||
/** The real BillboardCollection the layer created. */
|
||||
billboards: () => primitives[0],
|
||||
engine,
|
||||
/** Attaches the layer to the engine and enables it; markers drawn. */
|
||||
async start() {
|
||||
layer.init(null, { engine });
|
||||
await layer.enable();
|
||||
await settle();
|
||||
},
|
||||
settle,
|
||||
/** The real BillboardCollection the engine drew the markers with. */
|
||||
billboards: () => primitive('firms:firms'),
|
||||
drawnCount,
|
||||
/** Latest entry list published to the overlay host. */
|
||||
latestEntries: () => entryCalls[entryCalls.length - 1] || [],
|
||||
/** `show` flags keyed by billboard pick id. */
|
||||
/** `show` flags of the drawn markers, keyed by billboard pick id. */
|
||||
showById() {
|
||||
const bb = primitives[0];
|
||||
const bb = primitive('firms:firms');
|
||||
const out = new Map();
|
||||
for (let i = 0; i < bb.length; i += 1) out.set(bb.get(i).id, bb.get(i).show);
|
||||
for (let i = 0; i < drawnCount(); i += 1)
|
||||
out.set(bb.get(i).id, bb.get(i).show);
|
||||
return out;
|
||||
},
|
||||
moveCameraTo(lon, lat, height = REPRO_HEIGHT_M) {
|
||||
viewer.camera.positionWC = Cesium.Cartesian3.fromDegrees(lon, lat, height);
|
||||
viewer.camera.positionCartographic = { height };
|
||||
},
|
||||
moveCameraTo,
|
||||
moveEnd: () => viewer.camera.moveEnd.raiseEvent(),
|
||||
preRender: () => frame(),
|
||||
cleanup() {
|
||||
layer.destroy(viewer);
|
||||
unregisterSpriteCollection('firms');
|
||||
layer.destroy();
|
||||
engine.destroy();
|
||||
Cesium.SceneTransforms.worldToWindowCoordinates = originalProject;
|
||||
globalThis.fetch = originalFetch;
|
||||
if (originalWindow === undefined) delete globalThis.window; else globalThis.window = originalWindow;
|
||||
if (originalDocument === undefined) delete globalThis.document; else globalThis.document = originalDocument;
|
||||
if (originalWindow === undefined) delete globalThis.window;
|
||||
else globalThis.window = originalWindow;
|
||||
if (originalDocument === undefined) delete globalThis.document;
|
||||
else globalThis.document = originalDocument;
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -442,14 +656,25 @@ test('layer: a detection rebuild culls its own freshly-added sprites', async ()
|
||||
rawFire(TOKYO.lat, TOKYO.lon, 800),
|
||||
]);
|
||||
try {
|
||||
harness.layer.init(harness.viewer);
|
||||
await harness.layer.enable(harness.viewer);
|
||||
await harness.start();
|
||||
// No camera event has fired — only renderDetections ran.
|
||||
const show = harness.showById();
|
||||
assert.equal(show.size, 3, 'all three detections were rendered');
|
||||
assert.equal(show.get('firms-0'), true, 'the Austin fire under the camera is visible');
|
||||
assert.equal(show.get('firms-1'), false, 'the antipodal fire is culled at build time');
|
||||
assert.equal(show.get('firms-2'), false, 'the Tokyo fire is culled at build time');
|
||||
assert.equal(
|
||||
show.get('firms-0'),
|
||||
true,
|
||||
'the Austin fire under the camera is visible',
|
||||
);
|
||||
assert.equal(
|
||||
show.get('firms-1'),
|
||||
false,
|
||||
'the antipodal fire is culled at build time',
|
||||
);
|
||||
assert.equal(
|
||||
show.get('firms-2'),
|
||||
false,
|
||||
'the Tokyo fire is culled at build time',
|
||||
);
|
||||
} finally {
|
||||
harness.cleanup();
|
||||
}
|
||||
@@ -461,15 +686,23 @@ test('layer: camera moveEnd re-culls without a rebuild', async () => {
|
||||
rawFire(TOKYO.lat, TOKYO.lon, 800),
|
||||
]);
|
||||
try {
|
||||
harness.layer.init(harness.viewer);
|
||||
await harness.layer.enable(harness.viewer);
|
||||
assert.equal(harness.showById().get('firms-1'), false, 'precondition: Tokyo hidden from Austin');
|
||||
await harness.start();
|
||||
assert.equal(
|
||||
harness.showById().get('firms-1'),
|
||||
false,
|
||||
'precondition: Tokyo hidden from Austin',
|
||||
);
|
||||
|
||||
harness.moveCameraTo(TOKYO.lon, TOKYO.lat);
|
||||
harness.moveEnd.emit();
|
||||
harness.moveEnd();
|
||||
await harness.settle();
|
||||
|
||||
const show = harness.showById();
|
||||
assert.equal(show.get('firms-1'), true, 'Tokyo becomes visible once the camera is over it');
|
||||
assert.equal(
|
||||
show.get('firms-1'),
|
||||
true,
|
||||
'Tokyo becomes visible once the camera is over it',
|
||||
);
|
||||
assert.equal(show.get('firms-0'), false, 'Austin drops behind the limb');
|
||||
} finally {
|
||||
harness.cleanup();
|
||||
@@ -482,20 +715,30 @@ test('layer: the throttled preRender watcher re-culls on a camera move', async (
|
||||
rawFire(TOKYO.lat, TOKYO.lon, 800),
|
||||
]);
|
||||
try {
|
||||
harness.layer.init(harness.viewer);
|
||||
await harness.layer.enable(harness.viewer);
|
||||
await harness.start();
|
||||
harness.moveCameraTo(TOKYO.lon, TOKYO.lat);
|
||||
// The watcher is throttled to LOD_CHECK_MS (650 ms) against
|
||||
// performance.now(), whose value at this point depends on process
|
||||
// start-up — so emit, wait out the full throttle window, and emit again.
|
||||
// Whichever tick passes the gate, one of them must run the pass.
|
||||
harness.preRender.emit();
|
||||
await new Promise((resolve) => { setTimeout(resolve, 700); });
|
||||
harness.preRender.emit();
|
||||
harness.preRender();
|
||||
await new Promise((resolve) => {
|
||||
setTimeout(resolve, 700);
|
||||
});
|
||||
harness.preRender();
|
||||
await harness.settle();
|
||||
|
||||
const show = harness.showById();
|
||||
assert.equal(show.get('firms-1'), true, 'Tokyo revealed by the preRender pass');
|
||||
assert.equal(show.get('firms-0'), false, 'Austin culled by the preRender pass');
|
||||
assert.equal(
|
||||
show.get('firms-1'),
|
||||
true,
|
||||
'Tokyo revealed by the preRender pass',
|
||||
);
|
||||
assert.equal(
|
||||
show.get('firms-0'),
|
||||
false,
|
||||
'Austin culled by the preRender pass',
|
||||
);
|
||||
} finally {
|
||||
harness.cleanup();
|
||||
}
|
||||
@@ -507,23 +750,35 @@ test('layer: re-enabling after the camera moved does not expose stale far-side s
|
||||
rawFire(TOKYO.lat, TOKYO.lon, 800),
|
||||
]);
|
||||
try {
|
||||
harness.layer.init(harness.viewer);
|
||||
await harness.layer.enable(harness.viewer);
|
||||
assert.equal(harness.showById().get('firms-1'), false, 'precondition: Tokyo hidden from Austin');
|
||||
await harness.start();
|
||||
assert.equal(
|
||||
harness.showById().get('firms-1'),
|
||||
false,
|
||||
'precondition: Tokyo hidden from Austin',
|
||||
);
|
||||
|
||||
harness.layer.disable();
|
||||
// The camera moves while the layer is OFF: moveEnd is not being listened
|
||||
// to, and the preRender watcher is inert. Nothing re-culls on its own.
|
||||
harness.moveCameraTo(TOKYO.lon, TOKYO.lat);
|
||||
await harness.layer.enable(harness.viewer);
|
||||
await harness.layer.enable();
|
||||
await harness.settle();
|
||||
|
||||
// Assert with NO camera event fired and NO refetch (fires are already
|
||||
// loaded, so enable() does not reload): the enable path itself must have
|
||||
// re-culled before the collection went visible.
|
||||
const show = harness.showById();
|
||||
assert.equal(harness.billboards().show, true, 'the collection is visible again');
|
||||
assert.equal(show.get('firms-1'), true, 'the Tokyo fire is revealed at enable time');
|
||||
assert.equal(show.get('firms-0'), false, 'the Austin fire is NOT left shining through the planet');
|
||||
assert.equal(harness.drawnCount(), 2, 'the markers are drawn again');
|
||||
assert.equal(
|
||||
show.get('firms-1'),
|
||||
true,
|
||||
'the Tokyo fire is revealed at enable time',
|
||||
);
|
||||
assert.equal(
|
||||
show.get('firms-0'),
|
||||
false,
|
||||
'the Austin fire is NOT left shining through the planet',
|
||||
);
|
||||
} finally {
|
||||
harness.cleanup();
|
||||
}
|
||||
@@ -541,8 +796,7 @@ test('layer: a near-limb fire on a sub-ellipsoid anchor is not culled by its dat
|
||||
rawFire(lat, lon, 90),
|
||||
]);
|
||||
try {
|
||||
harness.layer.init(harness.viewer);
|
||||
await harness.layer.enable(harness.viewer);
|
||||
await harness.start();
|
||||
|
||||
const bb = harness.billboards();
|
||||
const sunken = bb.get(1);
|
||||
@@ -551,8 +805,16 @@ test('layer: a near-limb fire on a sub-ellipsoid anchor is not culled by its dat
|
||||
Math.abs(carto.height - (-27 + FIRE_ANCHOR_LIFT_M)) < 0.5,
|
||||
`the sprite still RENDERS at the datum-correct anchor, got ${carto.height}`,
|
||||
);
|
||||
assert.equal(sunken.show, true, 'the near-limb fire stays on screen (lifted cull anchor)');
|
||||
assert.equal(harness.showById().get('firms-0'), true, 'the camera-nadir fire is unaffected');
|
||||
assert.equal(
|
||||
sunken.show,
|
||||
true,
|
||||
'the near-limb fire stays on screen (lifted cull anchor)',
|
||||
);
|
||||
assert.equal(
|
||||
harness.showById().get('firms-0'),
|
||||
true,
|
||||
'the camera-nadir fire is unaffected',
|
||||
);
|
||||
} finally {
|
||||
harness.cleanup();
|
||||
_clearMeshFloorCellsForTest();
|
||||
@@ -562,25 +824,37 @@ test('layer: a near-limb fire on a sub-ellipsoid anchor is not culled by its dat
|
||||
|
||||
test('layer: far-side candidates never displace near-side ambient cards', async () => {
|
||||
const near = [];
|
||||
for (let i = 0; i < 6; i += 1) near.push(rawFire(AUSTIN.lat + i * 0.4, AUSTIN.lon + i * 0.4, 100 - i));
|
||||
for (let i = 0; i < 6; i += 1)
|
||||
near.push(rawFire(AUSTIN.lat + i * 0.4, AUSTIN.lon + i * 0.4, 100 - i));
|
||||
const far = [];
|
||||
for (let i = 0; i < 20; i += 1) far.push(rawFire(ANTIPODE.lat + i * 0.4, ANTIPODE.lon + i * 0.4, 900 - i));
|
||||
for (let i = 0; i < 20; i += 1)
|
||||
far.push(rawFire(ANTIPODE.lat + i * 0.4, ANTIPODE.lon + i * 0.4, 900 - i));
|
||||
// Far-side fires are the STRONGEST, so they lead the FRP-ranked candidate
|
||||
// walk and would eat all 18 ambient slots without the horizon skip.
|
||||
const harness = createHarness([...near, ...far]);
|
||||
try {
|
||||
harness.layer.init(harness.viewer);
|
||||
await harness.layer.enable(harness.viewer);
|
||||
await harness.start();
|
||||
|
||||
const ids = harness.latestEntries().map((entry) => entry.id);
|
||||
assert.ok(ids.length > 0, 'cards were published');
|
||||
assert.ok(ids.length <= FIRMS_AMBIENT_COHORT_LIMIT, 'the ambient cap still holds');
|
||||
assert.ok(
|
||||
ids.length <= FIRMS_AMBIENT_COHORT_LIMIT,
|
||||
'the ambient cap still holds',
|
||||
);
|
||||
// Card ids are `fire:firms:<lat>:<lon>:<acqMs>:<sat>` (the refetch-stable
|
||||
// detection key), so a card is matched back to its seed by coordinate.
|
||||
const nearCoords = new Set(near.map((fire) => `${fire.lat.toFixed(4)}:${fire.lon.toFixed(4)}`));
|
||||
const nearIds = ids.filter((id) => nearCoords.has(id.split(':').slice(2, 4).join(':')));
|
||||
const nearCoords = new Set(
|
||||
near.map((fire) => `${fire.lat.toFixed(4)}:${fire.lon.toFixed(4)}`),
|
||||
);
|
||||
const nearIds = ids.filter((id) =>
|
||||
nearCoords.has(id.split(':').slice(2, 4).join(':')),
|
||||
);
|
||||
assert.equal(nearIds.length, 6, 'every in-view fire gets a card');
|
||||
assert.equal(new Set(nearIds).size, 6, 'six distinct near-side detections, not one repeated');
|
||||
assert.equal(
|
||||
new Set(nearIds).size,
|
||||
6,
|
||||
'six distinct near-side detections, not one repeated',
|
||||
);
|
||||
assert.equal(ids.length, 6, 'no slot is spent on a fire behind the planet');
|
||||
assert.equal(FIRMS_OVERLAY_SOURCE_ID, 'firms');
|
||||
} finally {
|
||||
|
||||
@@ -1,11 +1,19 @@
|
||||
// FIRMS click routes: sprite AND card must both select for detail and hand the
|
||||
// camera over (pre-launch defect #4 + P1-3). Driven through the production
|
||||
// click handler and the production card-render path; only the viewer, the
|
||||
// event handler, the overlay host and the world→window projection are stubbed.
|
||||
// click handler and the production card-render path, on the Cesium engine
|
||||
// over a stub scene; only the scene pick, the event handler, the overlay
|
||||
// host and the world→window projection are stubbed.
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import * as Cesium from 'cesium';
|
||||
import { createFirmsHeatmapLayer, applyFirmsOverlayPolicy, buildCellCard } from './firmsHeatmap.js';
|
||||
import { createCesiumMoversEngine } from '../testSupport/cesiumMoversEngine.mjs';
|
||||
import { createFakeEventHandlers } from '../globe/cesium/testing/fakeViewer.mjs';
|
||||
import { createFirmsDisplay } from '../layers/firms/render/display.js';
|
||||
import {
|
||||
createFirmsHeatmapLayer,
|
||||
applyFirmsOverlayPolicy,
|
||||
buildCellCard,
|
||||
} from './firmsHeatmap.js';
|
||||
import { fireDetectionKey } from './firmsLabels.js';
|
||||
import { registerPickOwner, unregisterPickOwner } from './pickRegistry.js';
|
||||
import { getSelectedEntityContext } from './contextStore.js';
|
||||
@@ -43,8 +51,11 @@ function makeFire(overrides = {}) {
|
||||
* actionable card presents.
|
||||
*/
|
||||
function harness({
|
||||
fires = [makeFire()], picked = null, cardHit = null, cameraPosition = null,
|
||||
withDataSource = false, feed = null,
|
||||
fires = [makeFire()],
|
||||
picked = null,
|
||||
cardHit = null,
|
||||
cameraPosition = null,
|
||||
feed = null,
|
||||
} = {}) {
|
||||
const hadWindow = Object.hasOwn(globalThis, 'window');
|
||||
const priorWindow = globalThis.window;
|
||||
@@ -52,15 +63,29 @@ function harness({
|
||||
const windowTarget = new EventTarget();
|
||||
globalThis.window = windowTarget;
|
||||
// Spread projections so the greedy screen-separation declutter accepts every
|
||||
// seeded detection; co-located fires would otherwise collide by design.
|
||||
// seeded detection; co-located fires would otherwise collide by design. The
|
||||
// engine's projector reads this when the engine is made.
|
||||
let projected = 0;
|
||||
Cesium.SceneTransforms.worldToWindowCoordinates = () => {
|
||||
projected += 1;
|
||||
return { x: 200 * projected, y: 300 };
|
||||
};
|
||||
const handlers = createFakeEventHandlers();
|
||||
const { engine, viewer, primitive, frame } = createCesiumMoversEngine({
|
||||
engineOptions: {
|
||||
createEventHandler: handlers.create,
|
||||
scheduleFrame: (run) => run(),
|
||||
},
|
||||
});
|
||||
viewer.scene.groundPrimitives = new Cesium.PrimitiveCollection();
|
||||
viewer.scene.pick = () => picked ?? undefined;
|
||||
viewer.scene.drillPick = () => (picked ? [picked] : []);
|
||||
engine.camera.setView({
|
||||
destination:
|
||||
cameraPosition ?? Cesium.Cartesian3.fromDegrees(-98, 30, 2_000_000),
|
||||
});
|
||||
|
||||
const published = [];
|
||||
let handler = null;
|
||||
const layer = createFirmsHeatmapLayer({
|
||||
...(feed ? { feed } : {}),
|
||||
id: 'firms-test',
|
||||
@@ -71,41 +96,48 @@ function harness({
|
||||
clearSource() {},
|
||||
hitTest: () => (cardHit ? { sourceId: 'firms', entryId: cardHit } : null),
|
||||
},
|
||||
screenSpaceEventHandlerFactory: () => {
|
||||
handler = { click: null, setInputAction(cb) { this.click = cb; }, destroy() {} };
|
||||
return handler;
|
||||
// The display the registry gives every engine, with image seams.
|
||||
renderer: {
|
||||
create: ({ engine: target, ...options }) =>
|
||||
createFirmsDisplay(target, {
|
||||
...options,
|
||||
loadImage: async () => ({ width: 16, height: 16 }),
|
||||
createCanvas: () => ({ getContext: () => ({ drawImage() {} }) }),
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
const viewer = {
|
||||
scene: {
|
||||
pick: () => picked,
|
||||
frameState: { mode: Cesium.SceneMode.SCENE3D },
|
||||
primitives: new Cesium.PrimitiveCollection(),
|
||||
canvas: { clientWidth: 1280, clientHeight: 800 },
|
||||
camera: cameraPosition ? { positionWC: cameraPosition } : undefined,
|
||||
globe: { ellipsoid: Cesium.Ellipsoid.WGS84 },
|
||||
},
|
||||
dataSources: { add() {}, remove() {} },
|
||||
};
|
||||
// The LOD rebuild (and with it the context-registration sweep) is inert
|
||||
// without a data source, so tests that drive a real refresh need one.
|
||||
if (withDataSource) layer.init(viewer);
|
||||
layer._bindInteractionForTest(viewer, fires);
|
||||
layer._bindInteractionForTest(engine, fires);
|
||||
|
||||
const requests = [];
|
||||
windowTarget.addEventListener(WORLD_FOCUS_REQUEST_EVENT, (e) => requests.push(e.detail));
|
||||
windowTarget.addEventListener(WORLD_FOCUS_REQUEST_EVENT, (e) =>
|
||||
requests.push(e.detail),
|
||||
);
|
||||
|
||||
return {
|
||||
layer,
|
||||
engine,
|
||||
viewer,
|
||||
frame,
|
||||
/** The glow billboards drawn (the engine's sprite set), or null. */
|
||||
markers: () => primitive('firms:firms-test') ?? null,
|
||||
windowTarget,
|
||||
requests,
|
||||
published,
|
||||
fires,
|
||||
click: () => handler.click({ position: { x: 400, y: 300 } }),
|
||||
click() {
|
||||
for (const handler of handlers.handlers)
|
||||
handler.fire(Cesium.ScreenSpaceEventType.LEFT_CLICK, {
|
||||
position: new Cesium.Cartesian2(400, 300),
|
||||
});
|
||||
},
|
||||
setHeight(height) {
|
||||
engine.camera.setView({
|
||||
destination: Cesium.Cartesian3.fromDegrees(-98, 30, height),
|
||||
});
|
||||
},
|
||||
cleanup() {
|
||||
layer.destroy();
|
||||
engine.destroy();
|
||||
Cesium.SceneTransforms.worldToWindowCoordinates = priorProjection;
|
||||
if (hadWindow) globalThis.window = priorWindow;
|
||||
else delete globalThis.window;
|
||||
@@ -113,12 +145,26 @@ function harness({
|
||||
};
|
||||
}
|
||||
|
||||
const settle = async () => {
|
||||
for (let i = 0; i < 4; i++)
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
};
|
||||
|
||||
test('fire detection key survives a refetch that renumbers the index', () => {
|
||||
const fire = makeFire();
|
||||
assert.equal(fireDetectionKey(fire), fireDetectionKey({ ...fire, index: 999 }));
|
||||
assert.equal(
|
||||
fireDetectionKey(fire),
|
||||
fireDetectionKey({ ...fire, index: 999 }),
|
||||
);
|
||||
// Different pass over the same pixel is a different detection.
|
||||
assert.notEqual(fireDetectionKey(fire), fireDetectionKey({ ...fire, acqMs: fire.acqMs + 1 }));
|
||||
assert.notEqual(fireDetectionKey(fire), fireDetectionKey({ ...fire, lat: 31.0 }));
|
||||
assert.notEqual(
|
||||
fireDetectionKey(fire),
|
||||
fireDetectionKey({ ...fire, acqMs: fire.acqMs + 1 }),
|
||||
);
|
||||
assert.notEqual(
|
||||
fireDetectionKey(fire),
|
||||
fireDetectionKey({ ...fire, lat: 31.0 }),
|
||||
);
|
||||
assert.match(fireDetectionKey({}), /^firms:x:x:0:x$/);
|
||||
});
|
||||
|
||||
@@ -133,11 +179,20 @@ test('two satellites over the same pixel at the same time stay distinct', () =>
|
||||
assert.notEqual(fireDetectionKey(base), fireDetectionKey(suomi));
|
||||
assert.notEqual(fireDetectionKey(twin), fireDetectionKey(suomi));
|
||||
// Satellite naming variants normalize to one identity, not three.
|
||||
assert.equal(fireDetectionKey(base), fireDetectionKey(makeFire({ satellite: 'NOAA-20' })));
|
||||
assert.equal(fireDetectionKey(suomi), fireDetectionKey(makeFire({ satellite: 'Suomi NPP' })));
|
||||
assert.equal(
|
||||
fireDetectionKey(base),
|
||||
fireDetectionKey(makeFire({ satellite: 'NOAA-20' })),
|
||||
);
|
||||
assert.equal(
|
||||
fireDetectionKey(suomi),
|
||||
fireDetectionKey(makeFire({ satellite: 'Suomi NPP' })),
|
||||
);
|
||||
// A record with no satellite falls back to its sensor, not to a shared blank.
|
||||
const sensorOnly = makeFire({ satellite: '', sensor: 'MODIS' });
|
||||
assert.notEqual(fireDetectionKey(sensorOnly), fireDetectionKey(makeFire({ satellite: '', sensor: 'VIIRS' })));
|
||||
assert.notEqual(
|
||||
fireDetectionKey(sensorOnly),
|
||||
fireDetectionKey(makeFire({ satellite: '', sensor: 'VIIRS' })),
|
||||
);
|
||||
});
|
||||
|
||||
test('duplicate-coordinate detections get their own cards and focus targets', () => {
|
||||
@@ -149,11 +204,21 @@ test('duplicate-coordinate detections get their own cards and focus targets', ()
|
||||
cardHit: `fire:${fireDetectionKey(n21)}`,
|
||||
});
|
||||
try {
|
||||
const cardIds = h.published.filter((e) => e.id.startsWith('fire:')).map((e) => e.id);
|
||||
assert.equal(new Set(cardIds).size, 2, 'co-located detections must not collapse to one card');
|
||||
const cardIds = h.published
|
||||
.filter((e) => e.id.startsWith('fire:'))
|
||||
.map((e) => e.id);
|
||||
assert.equal(
|
||||
new Set(cardIds).size,
|
||||
2,
|
||||
'co-located detections must not collapse to one card',
|
||||
);
|
||||
h.click();
|
||||
assert.equal(h.requests.length, 1);
|
||||
assert.equal(h.requests[0].id, fireDetectionKey(n21), 'the clicked card wins, not its twin');
|
||||
assert.equal(
|
||||
h.requests[0].id,
|
||||
fireDetectionKey(n21),
|
||||
'the clicked card wins, not its twin',
|
||||
);
|
||||
} finally {
|
||||
h.cleanup();
|
||||
}
|
||||
@@ -164,7 +229,9 @@ test('selection restoration uses the same key the cards and focus use', () => {
|
||||
// detections from different satellites — the selection could come back on
|
||||
// the wrong record. Reachable only through the 30-minute refetch, so this is
|
||||
// a source contract; the key's own behavior is proven above.
|
||||
const match = LAYER_SOURCE.match(/function findMatchingFire\(previous\) \{([\s\S]*?)\n \}\n/);
|
||||
const match = LAYER_SOURCE.match(
|
||||
/function findMatchingFire\(previous\) \{([\s\S]*?)\n \}\n/,
|
||||
);
|
||||
assert.ok(match, 'findMatchingFire is missing');
|
||||
assert.match(match[1], /fireDetectionKey\(previous\)/);
|
||||
assert.match(match[1], /fireDetectionKey\(fire\) === key/);
|
||||
@@ -177,7 +244,11 @@ test('painted detection cards are keyed by the stable detection key', () => {
|
||||
const card = h.published.find((entry) => entry.id.startsWith('fire:'));
|
||||
assert.ok(card, 'a detection card was painted');
|
||||
assert.equal(card.id, `fire:${fireDetectionKey(h.fires[0])}`);
|
||||
assert.equal(card.interactive, true, 'a detection card must publish a hit rect');
|
||||
assert.equal(
|
||||
card.interactive,
|
||||
true,
|
||||
'a detection card must publish a hit rect',
|
||||
);
|
||||
assert.match(card.accessibilityLabel, /^Focus fire detection /);
|
||||
assert.equal(card.activate(), true);
|
||||
assert.equal(h.requests.length, 1);
|
||||
@@ -189,7 +260,16 @@ test('painted detection cards are keyed by the stable detection key', () => {
|
||||
|
||||
test('an aggregated cell card is never actionable — it is not one fire', () => {
|
||||
const cell = buildCellCard(
|
||||
{ cell: { count: 14, maxFrp: 210, newestAcqMs: 0, latCell: 30, lonCell: -98 }, position: {} },
|
||||
{
|
||||
cell: {
|
||||
count: 14,
|
||||
maxFrp: 210,
|
||||
newestAcqMs: 0,
|
||||
latCell: 30,
|
||||
lonCell: -98,
|
||||
},
|
||||
position: {},
|
||||
},
|
||||
Date.now(),
|
||||
);
|
||||
assert.equal(applyFirmsOverlayPolicy(cell, 1e6).interactive, false);
|
||||
@@ -198,10 +278,16 @@ test('an aggregated cell card is never actionable — it is not one fire', () =>
|
||||
test('far-side detections cannot consume the bounded ambient-card cohort', () => {
|
||||
const front = makeFire({ index: 1, lat: 30.51, lon: -98.21, frp: 100 });
|
||||
const rear = makeFire({ index: 2, lat: -30.51, lon: 81.79, frp: 1000 });
|
||||
const cameraPosition = Cesium.Cartesian3.fromDegrees(front.lon, front.lat, 10_000_000);
|
||||
const cameraPosition = Cesium.Cartesian3.fromDegrees(
|
||||
front.lon,
|
||||
front.lat,
|
||||
10_000_000,
|
||||
);
|
||||
const h = harness({ fires: [rear, front], cameraPosition });
|
||||
try {
|
||||
const cardIds = h.published.filter((entry) => entry.id.startsWith('fire:')).map((entry) => entry.id);
|
||||
const cardIds = h.published
|
||||
.filter((entry) => entry.id.startsWith('fire:'))
|
||||
.map((entry) => entry.id);
|
||||
assert.deepEqual(cardIds, [`fire:${fireDetectionKey(front)}`]);
|
||||
} finally {
|
||||
h.cleanup();
|
||||
@@ -278,7 +364,11 @@ test('a click on neither sprite nor card clears without moving the camera', () =
|
||||
const SIBLING_PICKS = [
|
||||
['flights', 'a1b2c3', { id: 'a1b2c3' }],
|
||||
['flights', 'a1b2c3', { primitive: { id: 'a1b2c3' } }],
|
||||
['ais-live-vessels', '353136000', { id: { mmsi: '353136000', name: 'EVER GIVEN' } }],
|
||||
[
|
||||
'ais-live-vessels',
|
||||
'353136000',
|
||||
{ id: { mmsi: '353136000', name: 'EVER GIVEN' } },
|
||||
],
|
||||
['cctv', 'atx-cam-3', { id: { id: 'atx-cam-3', name: 'entity-like' } }],
|
||||
['satellites', '25544', { id: 25544 }],
|
||||
];
|
||||
@@ -294,7 +384,11 @@ for (const [layerId, ownedId, picked] of SIBLING_PICKS) {
|
||||
});
|
||||
try {
|
||||
h.click();
|
||||
assert.equal(h.requests.length, 0, `the ${layerId} layer is already acting on this click`);
|
||||
assert.equal(
|
||||
h.requests.length,
|
||||
0,
|
||||
`the ${layerId} layer is already acting on this click`,
|
||||
);
|
||||
} finally {
|
||||
h.cleanup();
|
||||
unregisterPickOwner(layerId);
|
||||
@@ -321,15 +415,20 @@ test('a refresh that drops the selected fire emits an eviction the readout can a
|
||||
// record first and the clear then fails its ownership guard silently.
|
||||
const kept = makeFire({ index: 0 });
|
||||
const dropped = makeFire({
|
||||
index: 1, lat: 31.77, lon: -99.02, acqMs: 1_753_600_100_000, satellite: 'N20',
|
||||
index: 1,
|
||||
lat: 31.77,
|
||||
lon: -99.02,
|
||||
acqMs: 1_753_600_100_000,
|
||||
satellite: 'N20',
|
||||
});
|
||||
const h = harness({
|
||||
fires: [dropped, kept],
|
||||
cardHit: `fire:${fireDetectionKey(dropped)}`,
|
||||
withDataSource: true,
|
||||
});
|
||||
const cleared = [];
|
||||
h.windowTarget.addEventListener('gev:entity-selection-cleared', (e) => cleared.push(e.detail));
|
||||
h.windowTarget.addEventListener('gev:entity-selection-cleared', (e) =>
|
||||
cleared.push(e.detail),
|
||||
);
|
||||
const priorFetch = globalThis.fetch;
|
||||
// The far band keeps the markers built under the heatmap for the hand-off
|
||||
// fade; their glow sprites need a canvas.
|
||||
@@ -340,7 +439,11 @@ test('a refresh that drops the selected fire emits an eviction the readout can a
|
||||
|
||||
try {
|
||||
h.click();
|
||||
assert.equal(h.requests.length, 1, 'the click must select the fire we are about to drop');
|
||||
assert.equal(
|
||||
h.requests.length,
|
||||
1,
|
||||
'the click must select the fire we are about to drop',
|
||||
);
|
||||
assert.equal(h.requests[0].id, fireDetectionKey(dropped));
|
||||
assert.deepEqual(cleared, [], 'selecting must not clear anything yet');
|
||||
|
||||
@@ -351,18 +454,20 @@ test('a refresh that drops the selected fire emits an eviction the readout can a
|
||||
json: async () => ({
|
||||
fetchedAt: Date.now(),
|
||||
stale: false,
|
||||
fires: [{
|
||||
lat: kept.lat,
|
||||
lon: kept.lon,
|
||||
frp: kept.frp,
|
||||
confidence: 'h',
|
||||
brightness: 330,
|
||||
daynight: 'D',
|
||||
acqDate: '2025-07-27',
|
||||
acqTime: '0412',
|
||||
instrument: 'VIIRS',
|
||||
satellite: kept.satellite,
|
||||
}],
|
||||
fires: [
|
||||
{
|
||||
lat: kept.lat,
|
||||
lon: kept.lon,
|
||||
frp: kept.frp,
|
||||
confidence: 'h',
|
||||
brightness: 330,
|
||||
daynight: 'D',
|
||||
acqDate: '2025-07-27',
|
||||
acqTime: '0412',
|
||||
instrument: 'VIIRS',
|
||||
satellite: kept.satellite,
|
||||
},
|
||||
],
|
||||
}),
|
||||
});
|
||||
await h.layer.update();
|
||||
@@ -394,9 +499,16 @@ test('a refresh that drops the selected fire emits an eviction the readout can a
|
||||
|
||||
test('disable cancels a pending source and a late response cannot repopulate the layer', async () => {
|
||||
let resolve, signal;
|
||||
const h = harness({ withDataSource: true, feed: { getSnapshot(options) {
|
||||
signal = options.signal; return new Promise(done => { resolve = done; });
|
||||
} } });
|
||||
const h = harness({
|
||||
feed: {
|
||||
getSnapshot(options) {
|
||||
signal = options.signal;
|
||||
return new Promise((done) => {
|
||||
resolve = done;
|
||||
});
|
||||
},
|
||||
},
|
||||
});
|
||||
try {
|
||||
const before = h.layer.getStats();
|
||||
const pending = h.layer.update();
|
||||
@@ -407,16 +519,20 @@ test('disable cancels a pending source and a late response cannot repopulate the
|
||||
assert.equal(h.layer.getStats().count, before.count);
|
||||
assert.equal(h.layer.getStats().lastUpdate, before.lastUpdate);
|
||||
assert.equal(h.layer.getStats().loading, false);
|
||||
} finally { h.layer.destroy(h.viewer); h.cleanup(); }
|
||||
} finally {
|
||||
h.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test('the heatmap is preloaded under the markers before the first zoom-out', (t) => {
|
||||
test('the heatmap is preloaded under the markers before the first zoom-out', async (t) => {
|
||||
t.mock.timers.enable({ apis: ['setTimeout'] });
|
||||
const priorDocument = globalThis.document;
|
||||
globalThis.document = {
|
||||
createElement: () => ({
|
||||
getContext: () => ({
|
||||
createImageData: (w, hh) => ({ data: new Uint8ClampedArray(w * hh * 4) }),
|
||||
createImageData: (w, hh) => ({
|
||||
data: new Uint8ClampedArray(w * hh * 4),
|
||||
}),
|
||||
putImageData() {},
|
||||
createRadialGradient: () => ({ addColorStop() {} }),
|
||||
fillRect() {},
|
||||
@@ -425,12 +541,8 @@ test('the heatmap is preloaded under the markers before the first zoom-out', (t)
|
||||
}),
|
||||
};
|
||||
const h = harness({
|
||||
withDataSource: true,
|
||||
cameraPosition: Cesium.Cartesian3.fromDegrees(-98, 30, 1_000_000),
|
||||
});
|
||||
h.viewer.camera = { positionCartographic: { height: 1_000_000 } };
|
||||
h.viewer.scene.primitives = { add() {}, remove() {}, raiseToTop() {}, contains: () => true };
|
||||
h.viewer.scene.frameState = { mode: Cesium.SceneMode.SCENE3D };
|
||||
const added = [];
|
||||
try {
|
||||
h.layer.attachShellServices({
|
||||
@@ -454,14 +566,13 @@ test('the heatmap is preloaded under the markers before the first zoom-out', (t)
|
||||
assert.equal(added[0].alpha, 0, 'invisible until the hand-off');
|
||||
assert.equal(added[0].show, true, 'but mapped onto the globe tiles');
|
||||
} finally {
|
||||
h.layer.destroy(h.viewer);
|
||||
h.cleanup();
|
||||
if (priorDocument === undefined) delete globalThis.document;
|
||||
else globalThis.document = priorDocument;
|
||||
}
|
||||
});
|
||||
|
||||
test('far zoom drapes one heatmap and the hand-off cross-fades it with the markers', () => {
|
||||
test('far zoom drapes one heatmap and the hand-off cross-fades it with the markers', async () => {
|
||||
// A canvas stub for the heat drape and the detection glow sprites.
|
||||
const priorDocument = globalThis.document;
|
||||
const restoreDocument = () => {
|
||||
@@ -483,26 +594,18 @@ test('far zoom drapes one heatmap and the hand-off cross-fades it with the marke
|
||||
};
|
||||
const h = harness({
|
||||
fires: [makeFire(), makeFire({ index: 8, lat: 30.6, lon: -98.3, frp: 12 })],
|
||||
withDataSource: true,
|
||||
cameraPosition: Cesium.Cartesian3.fromDegrees(-98, 30, 12_000_000),
|
||||
});
|
||||
const added = [];
|
||||
const removed = [];
|
||||
let markers = null;
|
||||
// The fade reads the camera height; the cull reads scene.camera.
|
||||
const setHeight = (height) => {
|
||||
h.viewer.camera = { positionCartographic: { height } };
|
||||
// The markers as drawn: how many the sprite set draws, and their alphas.
|
||||
const drawn = () => {
|
||||
const count =
|
||||
h.engine.movers.list().find((set) => set.id === 'firms:firms-test')
|
||||
?.count ?? 0;
|
||||
const markers = h.markers();
|
||||
return Array.from({ length: count }, (_, i) => markers.get(i).color.alpha);
|
||||
};
|
||||
setHeight(12_000_000);
|
||||
h.viewer.scene.primitives = {
|
||||
add(primitive) {
|
||||
markers = primitive;
|
||||
},
|
||||
remove() {},
|
||||
raiseToTop() {},
|
||||
contains: () => true,
|
||||
};
|
||||
h.viewer.scene.frameState = { mode: Cesium.SceneMode.SCENE3D };
|
||||
try {
|
||||
const collection = {
|
||||
addImageryProvider: (provider) => {
|
||||
@@ -517,39 +620,53 @@ test('far zoom drapes one heatmap and the hand-off cross-fades it with the marke
|
||||
imageryHost: () => ({ kind: 'globe', collection }),
|
||||
});
|
||||
h.layer._renderLodForTest('global');
|
||||
await settle();
|
||||
assert.equal(added.length, 1, 'one heat imagery layer');
|
||||
assert.equal(added[0].show, true);
|
||||
assert.equal(added[0].alpha, 1);
|
||||
assert.equal(h.layer._entityCountForTest(), 0, 'no rectangle entities');
|
||||
assert.equal(h.layer._cellCountForTest(), 0, 'no ground cells');
|
||||
assert.ok(h.published.length > 0, 'the far band still paints cards');
|
||||
assert.equal(markers.length, 2, 'the markers are built under the heatmap');
|
||||
assert.equal(markers.show, false, 'and hidden while the heatmap is whole');
|
||||
assert.deepEqual(drawn(), [], 'no marker drawn while the heatmap is whole');
|
||||
// The markers are built under it: the hand-off shows them without a rebuild.
|
||||
h.setHeight(4_500_000);
|
||||
h.layer._applyHandoffFadeForTest();
|
||||
await settle();
|
||||
assert.deepEqual(
|
||||
drawn(),
|
||||
[0.5, 0.5],
|
||||
'the markers are built under the heatmap',
|
||||
);
|
||||
h.setHeight(12_000_000);
|
||||
h.layer._applyHandoffFadeForTest();
|
||||
await settle();
|
||||
assert.deepEqual(drawn(), []);
|
||||
|
||||
h.layer._renderLodForTest('regional');
|
||||
assert.equal(added.length, 1, 'switching far bands reuses the raster');
|
||||
|
||||
setHeight(1_000_000);
|
||||
h.setHeight(1_000_000);
|
||||
h.layer._renderLodForTest('close');
|
||||
await settle();
|
||||
assert.equal(added.length, 1, 'the markers band keeps the same heat layer');
|
||||
assert.equal(added[0].show, true, 'still mapped onto the globe tiles');
|
||||
assert.equal(added[0].alpha, 0, 'faded out under the markers');
|
||||
assert.equal(markers.show, true);
|
||||
assert.equal(markers.get(0).color.alpha, 1);
|
||||
assert.deepEqual(drawn(), [1, 1]);
|
||||
|
||||
// Mid hand-off both are drawn, half each, in either band.
|
||||
setHeight(4_500_000);
|
||||
h.setHeight(4_500_000);
|
||||
h.layer._applyHandoffFadeForTest();
|
||||
await settle();
|
||||
assert.equal(added[0].alpha, 0.5);
|
||||
assert.equal(markers.show, true);
|
||||
assert.equal(markers.get(0).color.alpha, 0.5);
|
||||
assert.deepEqual(drawn(), [0.5, 0.5]);
|
||||
h.layer._renderLodForTest('regional');
|
||||
await settle();
|
||||
assert.equal(added[0].alpha, 0.5);
|
||||
assert.equal(markers.get(1).color.alpha, 0.5, 'rebuilt markers get the fade');
|
||||
assert.deepEqual(drawn(), [0.5, 0.5], 'rebuilt markers get the fade');
|
||||
|
||||
h.layer.disable();
|
||||
assert.equal(added[0].show, false, 'disable hides the heatmap');
|
||||
|
||||
h.layer.destroy(h.viewer);
|
||||
h.layer.destroy();
|
||||
assert.deepEqual(
|
||||
removed.map((entry) => [entry.layer, entry.destroy]),
|
||||
[[added[0], true]],
|
||||
|
||||
@@ -120,7 +120,8 @@ test('every scene click handler consults ownership before it picks', () => {
|
||||
// ALPR and bikeshare take the engine's click with its pick.
|
||||
['src/layers/alpr/render/display.js', 'overlay.pick(position) ||'],
|
||||
['src/layers/bikeshare/render/display.js', 'const picked = event.picked;'],
|
||||
['src/layers/firms/selection.js', 'scene.pick(click.position)'],
|
||||
// FIRMS takes the engine dispatcher's click with its pick.
|
||||
['src/layers/firms/selection.js', 'const picked = click.picked;'],
|
||||
[
|
||||
'src/layers/installations/render/cesium/selection.js',
|
||||
'viewer.scene.pick(click.position)',
|
||||
@@ -136,8 +137,8 @@ test('every scene click handler consults ownership before it picks', () => {
|
||||
'getRenderer().isTrackedPick(picked',
|
||||
],
|
||||
[
|
||||
'src/layers/submarineCables/interaction.js',
|
||||
'viewer.scene.pick(click.position)',
|
||||
'src/layers/submarineCables/render/display.js',
|
||||
'const picked = event.picked;',
|
||||
],
|
||||
// Vessels take the engine dispatcher's pick: the guard
|
||||
// comes before the click rule reads it.
|
||||
|
||||
@@ -16,7 +16,9 @@ function makePrimitives(initial = []) {
|
||||
return {
|
||||
items: [...initial],
|
||||
calls: [],
|
||||
contains(collection) { return this.items.includes(collection); },
|
||||
contains(collection) {
|
||||
return this.items.includes(collection);
|
||||
},
|
||||
raiseToTop(collection) {
|
||||
this.calls.push(collection.id);
|
||||
const index = this.items.indexOf(collection);
|
||||
@@ -31,10 +33,15 @@ function makeCollection(id, destroyed = false) {
|
||||
}
|
||||
|
||||
test('restoreSpriteOrder raises live collections bottom-to-top and skips destroyed entries', () => {
|
||||
const collections = Object.fromEntries(ORDER.map((id) => [id, makeCollection(id)]));
|
||||
const collections = Object.fromEntries(
|
||||
ORDER.map((id) => [id, makeCollection(id)]),
|
||||
);
|
||||
const destroyedFirms = makeCollection('firms', true);
|
||||
for (const id of ORDER) {
|
||||
registerSpriteCollection(id, id === 'firms' ? destroyedFirms : collections[id]);
|
||||
registerSpriteCollection(
|
||||
id,
|
||||
id === 'firms' ? destroyedFirms : collections[id],
|
||||
);
|
||||
}
|
||||
const primitives = makePrimitives([
|
||||
collections.flights,
|
||||
@@ -46,10 +53,17 @@ test('restoreSpriteOrder raises live collections bottom-to-top and skips destroy
|
||||
|
||||
restoreSpriteOrder({ scene: { primitives } });
|
||||
|
||||
assert.deepEqual(primitives.calls, ['cctv', 'bikeshare', 'ais', 'military', 'flights']);
|
||||
assert.deepEqual(primitives.items.map((item) => item.id), [
|
||||
'cctv', 'bikeshare', 'ais', 'military', 'flights',
|
||||
assert.deepEqual(primitives.calls, [
|
||||
'cctv',
|
||||
'bikeshare',
|
||||
'ais',
|
||||
'military',
|
||||
'flights',
|
||||
]);
|
||||
assert.deepEqual(
|
||||
primitives.items.map((item) => item.id),
|
||||
['cctv', 'bikeshare', 'ais', 'military', 'flights'],
|
||||
);
|
||||
|
||||
for (const id of ORDER) unregisterSpriteCollection(id);
|
||||
});
|
||||
@@ -69,7 +83,10 @@ test('late CCTV registration still restores flights above the ambient collection
|
||||
restoreSpriteOrder(viewer);
|
||||
|
||||
assert.deepEqual(primitives.calls, ['cctv', 'flights']);
|
||||
assert.deepEqual(primitives.items.map((item) => item.id), ['cctv', 'flights']);
|
||||
assert.deepEqual(
|
||||
primitives.items.map((item) => item.id),
|
||||
['cctv', 'flights'],
|
||||
);
|
||||
|
||||
unregisterSpriteCollection('cctv', cctv);
|
||||
unregisterSpriteCollection('flights', flights);
|
||||
@@ -81,7 +98,9 @@ test('restoreSpriteOrder is inert for destroyed viewers and primitive collection
|
||||
registerSpriteCollection('flights', flights);
|
||||
|
||||
restoreSpriteOrder({ isDestroyed: () => true, scene: { primitives } });
|
||||
restoreSpriteOrder({ scene: { primitives: { ...primitives, isDestroyed: () => true } } });
|
||||
restoreSpriteOrder({
|
||||
scene: { primitives: { ...primitives, isDestroyed: () => true } },
|
||||
});
|
||||
|
||||
assert.deepEqual(primitives.calls, []);
|
||||
unregisterSpriteCollection('flights', flights);
|
||||
@@ -112,32 +131,32 @@ test('flights, AIS, and FIRMS enable paths are wired through the shared sprite r
|
||||
// Flights draws through its display: enable asks the fleet to restore its
|
||||
// order; the display's sprite sets take the flights' slot as their draw
|
||||
// order on every engine (aircraftLayerDisplay).
|
||||
assert.match(flightsLayer.enable.toString(), /fleet\.restoreOrderOnEnable\(\)/);
|
||||
assert.match(
|
||||
readFileSync(new URL('../layers/aircraft/render/display.js', import.meta.url), 'utf8'),
|
||||
flightsLayer.enable.toString(),
|
||||
/fleet\.restoreOrderOnEnable\(\)/,
|
||||
);
|
||||
assert.match(
|
||||
readFileSync(
|
||||
new URL('../layers/aircraft/render/display.js', import.meta.url),
|
||||
'utf8',
|
||||
),
|
||||
/order: SPRITE_LAYER_ORDER\.indexOf\(layerId\)/,
|
||||
);
|
||||
assert.match(
|
||||
readFileSync(new URL('../layers/flights/render/display.js', import.meta.url), 'utf8'),
|
||||
readFileSync(
|
||||
new URL('../layers/flights/render/display.js', import.meta.url),
|
||||
'utf8',
|
||||
),
|
||||
/aircraftLayerDisplay\(\s*'flights',/,
|
||||
);
|
||||
assert.match(
|
||||
firmsLayer.enable.toString(),
|
||||
/renderer\.onEnable\(\)/,
|
||||
);
|
||||
// FIRMS draws through its display: its glow sprite set takes the 'firms'
|
||||
// slot as its draw order on every engine.
|
||||
assert.doesNotMatch(firmsLayer.enable.toString(), /onEnable/);
|
||||
assert.match(
|
||||
readFileSync(
|
||||
new URL('../layers/firms/render/cesium.js', import.meta.url),
|
||||
new URL('../layers/firms/render/sprites.js', import.meta.url),
|
||||
'utf8',
|
||||
),
|
||||
/restoreSpriteOrderOnEnable\('firms', viewer\)/,
|
||||
);
|
||||
assert.match(
|
||||
readFileSync(
|
||||
new URL('../layers/firms/render/cesium.js', import.meta.url),
|
||||
'utf8',
|
||||
),
|
||||
/registerSpriteCollection\('firms', sprites\);\s*spriteServices\.restoreSpriteOrder\(viewer\);/,
|
||||
'lazy FIRMS registration must restore order immediately',
|
||||
/FIRMS_SPRITE_ORDER = SPRITE_LAYER_ORDER\.indexOf\('firms'\)[\s\S]*order: FIRMS_SPRITE_ORDER/,
|
||||
);
|
||||
});
|
||||
@@ -22,9 +22,8 @@ export {
|
||||
selectCableReferenceLabelWinners,
|
||||
cableReferencePriority,
|
||||
createCableOverlayEntry,
|
||||
cableClassificationTypeForStack,
|
||||
cableClassificationTypeForScene,
|
||||
applyTranslucentMarkerBlend,
|
||||
cableDrapeForStack,
|
||||
cableDrapeForEngine,
|
||||
createCableReferenceSweepGate,
|
||||
updateCableReferenceStem,
|
||||
updateCableReferenceTip,
|
||||
} from '../layers/submarineCables/index.js';
|
||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user