mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-18 01:02:23 +00:00
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.
203 lines
5.9 KiB
JavaScript
203 lines
5.9 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import * as geo from '../../geo/index.js';
|
|
import { createFakeEngine } from '../../globe/testing/fakeEngine.js';
|
|
import { createFirmsHeatmapLayer } from './index.js';
|
|
import { createFirmsDisplay } from './render/display.js';
|
|
import { createFirmsHeatDrape } from './render/navaraHeat.js';
|
|
|
|
const settle = async () => {
|
|
for (let i = 0; i < 5; i++)
|
|
await new Promise((resolve) => setImmediate(resolve));
|
|
};
|
|
const FIRE = { lat: 38.5, lon: -121.5 };
|
|
// One cluster a few hundred metres across: one heat spot and one card from
|
|
// orbit, sprites at the fire.
|
|
const records = Array.from({ length: 9 }, (_, i) => ({
|
|
lat: FIRE.lat + (i % 3) * 0.002,
|
|
lon: FIRE.lon + Math.floor(i / 3) * 0.002,
|
|
frp: 10 + i * 7,
|
|
confidence: 'h',
|
|
brightness: 330,
|
|
daynight: 'D',
|
|
acqDate: '2026-01-01',
|
|
acqTime: '1200',
|
|
instrument: 'VIIRS',
|
|
}));
|
|
|
|
function installCanvasFakes() {
|
|
const saved = { document: globalThis.document, Image: globalThis.Image };
|
|
const context = {
|
|
createRadialGradient: () => ({ addColorStop() {} }),
|
|
fillRect() {},
|
|
drawImage() {},
|
|
};
|
|
globalThis.document = {
|
|
createElement: () => ({
|
|
width: 0,
|
|
height: 0,
|
|
getContext: () => context,
|
|
toDataURL() {
|
|
return `data:image/png;base64,${this.width}`;
|
|
},
|
|
}),
|
|
};
|
|
globalThis.Image = class {
|
|
set src(url) {
|
|
this.width = this.height = Number(url.split(',')[1]);
|
|
queueMicrotask(() => this.onload?.());
|
|
}
|
|
};
|
|
return () => Object.assign(globalThis, saved);
|
|
}
|
|
|
|
function fixture() {
|
|
const restore = installCanvasFakes();
|
|
const engine = createFakeEngine({ kind: 'navara' });
|
|
const pose = (height) =>
|
|
engine.fake.setPose({
|
|
longitude: geo.math.toRadians(FIRE.lon + 0.002),
|
|
latitude: geo.math.toRadians(FIRE.lat + 0.002),
|
|
height,
|
|
heading: 0,
|
|
pitch: -Math.PI / 2,
|
|
roll: 0,
|
|
});
|
|
pose(12_000_000);
|
|
const effects = [];
|
|
const native = {
|
|
view: {
|
|
camera: {},
|
|
registerEffect() {},
|
|
addEffect(config) {
|
|
const handle = {
|
|
config,
|
|
visible: config.visible,
|
|
deleted: false,
|
|
update(next) {
|
|
if ('visible' in next) handle.visible = next.visible;
|
|
},
|
|
delete() {
|
|
handle.deleted = true;
|
|
},
|
|
};
|
|
effects.push(handle);
|
|
return handle;
|
|
},
|
|
},
|
|
EffectDesc: class {},
|
|
NavaraEffect: class {},
|
|
};
|
|
// The heatmap draws through the Navara backend on this view.
|
|
engine.extensions = { navara: native };
|
|
const noop = () => {};
|
|
const layer = createFirmsHeatmapLayer({
|
|
id: 'local-firms',
|
|
name: 'Fires',
|
|
feed: { getSnapshot: async () => ({ fires: records }) },
|
|
services: {
|
|
render: { governorRequestRender: noop },
|
|
picking: {
|
|
registerPickOwner: noop,
|
|
unregisterPickOwner: noop,
|
|
resolvePickId: () => null,
|
|
isOwnedByOtherLayer: () => false,
|
|
},
|
|
focus: { requestWorldFocus: noop },
|
|
context: {
|
|
selectEntityContext: noop,
|
|
clearSelectedEntityContextForLayer: noop,
|
|
getContextStore: () => new Map(),
|
|
registerEntityContext: noop,
|
|
},
|
|
anchors: {
|
|
fireAnchorHeight: () => 0,
|
|
warmFireAnchorFloors: async () => false,
|
|
},
|
|
},
|
|
overlayHost: { setEntries: noop, setVisible: noop, clearSource: noop },
|
|
renderer: {
|
|
create: ({ engine: target, id }) =>
|
|
createFirmsDisplay(target, { id, navaraHeat: createFirmsHeatDrape }),
|
|
},
|
|
});
|
|
layer.init(null, { engine });
|
|
let clock = 0;
|
|
const realNow = performance.now;
|
|
performance.now = () => clock;
|
|
return {
|
|
engine,
|
|
layer,
|
|
pose,
|
|
// The heatmap as drawn: its raster's alpha at the fire, 0 when the
|
|
// drape is hidden, faded out or unpainted.
|
|
drawnHeat() {
|
|
const handle = effects.find(
|
|
(effect) => effect.config.gevFirmsHeat && !effect.deleted,
|
|
);
|
|
const owner = handle?.config.gevFirmsHeat.owner;
|
|
if (!handle?.visible || !owner?.texture || !(owner.opacity > 0)) return 0;
|
|
const { data, width, height } = owner.texture.image;
|
|
const x = Math.floor(((FIRE.lon + 180) / 360) * width);
|
|
const y = Math.floor(((90 - FIRE.lat) / 180) * height);
|
|
return (data[(y * width + x) * 4 + 3] / 255) * owner.opacity;
|
|
},
|
|
cards: () => layer.getStats().cells,
|
|
// Fire sprites actually drawn (shown instances of the engine set).
|
|
drawnSprites() {
|
|
const set = engine.fake.moverSet('firms:local-firms');
|
|
if (!set) return 0;
|
|
let shown = 0;
|
|
for (let i = 0; i < set.store.count; i++) shown += set.store.shows[i];
|
|
return shown;
|
|
},
|
|
async step() {
|
|
clock += 1000; // past the LOD throttle
|
|
engine.fake.frame();
|
|
await settle();
|
|
},
|
|
cleanup() {
|
|
layer.destroy();
|
|
performance.now = realNow;
|
|
restore();
|
|
},
|
|
};
|
|
}
|
|
|
|
test('edge:local-firms: orbit to the fire hands over between heatmap and markers and never shows both', async () => {
|
|
const f = fixture();
|
|
try {
|
|
await f.layer.enable();
|
|
await f.step();
|
|
assert.ok(f.drawnHeat() > 0, 'orbit: the heatmap glows at the fire');
|
|
assert.equal(f.cards(), 1, 'orbit: one card holds the cluster');
|
|
assert.equal(f.drawnSprites(), 0);
|
|
for (const round of [1, 2]) {
|
|
// Down to the fire: markers replace the heatmap, one per observation.
|
|
f.pose(20_000);
|
|
await f.step();
|
|
assert.equal(
|
|
f.drawnSprites(),
|
|
records.length,
|
|
`round ${round} at the fire`,
|
|
);
|
|
assert.equal(
|
|
f.drawnHeat(),
|
|
0,
|
|
`round ${round}: no heat under the markers`,
|
|
);
|
|
// Back to orbit: the heatmap returns, the markers go.
|
|
f.pose(12_000_000);
|
|
await f.step();
|
|
assert.ok(f.drawnHeat() > 0, `round ${round} in orbit`);
|
|
assert.equal(
|
|
f.drawnSprites(),
|
|
0,
|
|
`round ${round}: no marker over the heatmap`,
|
|
);
|
|
}
|
|
} finally {
|
|
f.cleanup();
|
|
}
|
|
});
|