mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-22 03:02:20 +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
@@ -1,5 +1,5 @@
|
||||
import { createGnssCesiumRenderer } from './render/cesium.js';
|
||||
export { defaultGnssViewAnchor } from './render/cesium.js';
|
||||
import { createGnssDisplay } from './render/display.js';
|
||||
export { defaultGnssViewAnchor } from './render/display.js';
|
||||
import { formatNumber, msg, t } from '../../i18n/index.js';
|
||||
import { translateFeedError } from '../../ui/statusText.js';
|
||||
import {
|
||||
@@ -30,7 +30,8 @@ const LEVEL_LABELS = Object.freeze({
|
||||
export function createGnssIntegrityLayer({
|
||||
source,
|
||||
viewAnchor,
|
||||
createRenderer = createGnssCesiumRenderer,
|
||||
createRenderer = ({ engine, viewAnchor: anchor }) =>
|
||||
createGnssDisplay(engine, { viewAnchor: anchor }),
|
||||
now = () => Date.now(),
|
||||
monotonicNow = () => performance.now(),
|
||||
windowMs: requestedWindowMs,
|
||||
@@ -160,7 +161,7 @@ export function createGnssIntegrityLayer({
|
||||
throw new Error('GNSS integrity layer is already initialized');
|
||||
initialized = true;
|
||||
try {
|
||||
if (viewer || engine) this.attachRenderer(viewer, { engine });
|
||||
if (engine) this.attachRenderer(viewer, { engine });
|
||||
} catch (error) {
|
||||
this.destroy();
|
||||
throw error;
|
||||
@@ -170,7 +171,7 @@ export function createGnssIntegrityLayer({
|
||||
attachRenderer(viewer, { engine = null } = {}) {
|
||||
if (!initialized || renderer)
|
||||
throw new Error('Invalid GNSS scene attachment');
|
||||
renderer = createRenderer({ viewer, engine, viewAnchor });
|
||||
renderer = createRenderer({ engine, viewAnchor });
|
||||
_removeCameraEnd = renderer.camera?.moveEnd?.addEventListener(
|
||||
scheduleCameraRefresh,
|
||||
);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import * as Cesium from 'cesium';
|
||||
import * as geo from '../../geo/index.js';
|
||||
import { createFakeGroundHarness } from '../../testSupport/groundDisplayEngines.mjs';
|
||||
import { rgbaFromCss } from '../shared/color.js';
|
||||
import { createGnssIntegrityLayer, defaultGnssViewAnchor } from './index.js';
|
||||
import { LayerLifecycle } from '../../data/lifecycle.js';
|
||||
import { layerFeedState } from '../../data/feedState.js';
|
||||
@@ -23,22 +25,10 @@ function harness(
|
||||
} = {},
|
||||
) {
|
||||
let anchor = initialAnchor;
|
||||
const sources = [];
|
||||
const viewer = {
|
||||
camera: { moveEnd: new Cesium.Event(), changed: new Cesium.Event() },
|
||||
scene: {
|
||||
globe: { show: true },
|
||||
groundPrimitives: {
|
||||
add(value) {
|
||||
sources.push(value);
|
||||
},
|
||||
remove(value) {
|
||||
sources.splice(sources.indexOf(value), 1);
|
||||
value.destroy();
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const ground = createFakeGroundHarness();
|
||||
const { engine } = ground;
|
||||
// What the manager's lifecycle reads of a scene besides the engine.
|
||||
const viewer = { scene: { globe: { show: true } } };
|
||||
let clock = 1_000;
|
||||
const anchors = [];
|
||||
const layer = createGnssIntegrityLayer({
|
||||
@@ -56,10 +46,16 @@ function harness(
|
||||
now: () => clock,
|
||||
monotonicNow: () => clock,
|
||||
});
|
||||
if (initialize) layer.init(viewer);
|
||||
if (initialize) layer.init(null, { engine });
|
||||
return {
|
||||
layer,
|
||||
sources,
|
||||
ground,
|
||||
engine,
|
||||
camera: engine.camera,
|
||||
/** The drawn cells' ground set (undefined once released). */
|
||||
cells: () => ground.set('gnss-integrity'),
|
||||
/** How many cells are drawn. */
|
||||
drawn: () => ground.set('gnss-integrity')?.items.length ?? 0,
|
||||
anchors,
|
||||
viewer,
|
||||
advance(ms) {
|
||||
@@ -83,16 +79,13 @@ const flush = () => new Promise((resolve) => setImmediate(resolve));
|
||||
|
||||
test('a globe-wide rectangle uses the visible screen centre as the query anchor', () => {
|
||||
const anchor = defaultGnssViewAnchor({
|
||||
scene: {
|
||||
canvas: { clientWidth: 1000, clientHeight: 800 },
|
||||
globe: { ellipsoid: Cesium.Ellipsoid.WGS84 },
|
||||
},
|
||||
host: { size: () => ({ width: 1000, height: 800 }) },
|
||||
camera: {
|
||||
pickEllipsoid(pixel) {
|
||||
assert.deepEqual(pixel, new Cesium.Cartesian2(500, 400));
|
||||
return Cesium.Cartesian3.fromDegrees(-97, 30);
|
||||
assert.deepEqual(pixel, { x: 500, y: 400 });
|
||||
return geo.cartesian3.fromDegrees(-97, 30);
|
||||
},
|
||||
computeViewRectangle: () => {
|
||||
viewRectangle: () => {
|
||||
throw new Error('centre hit must not compute a rectangle');
|
||||
},
|
||||
},
|
||||
@@ -111,16 +104,16 @@ test('pan and zoom refresh through the manager without toggling; nearby changes
|
||||
},
|
||||
{ initialize: false },
|
||||
);
|
||||
const manager = new LayerLifecycle(h.viewer);
|
||||
const manager = new LayerLifecycle(h.viewer, { engine: h.engine });
|
||||
manager.register(h.layer);
|
||||
h.layer.attachDataManager(manager);
|
||||
const changes = [];
|
||||
manager.subscribe((change) => changes.push(change.type));
|
||||
await manager.setEnabled(h.layer.id, true);
|
||||
h.setAnchor({ latitude: 54, longitude: 19 });
|
||||
h.viewer.camera.changed.raiseEvent();
|
||||
h.camera.changed.raiseEvent();
|
||||
h.setAnchor({ latitude: 55, longitude: 20 });
|
||||
h.viewer.camera.moveEnd.raiseEvent();
|
||||
h.camera.moveEnd.raiseEvent();
|
||||
h.advance(2500);
|
||||
t.mock.timers.tick(2500);
|
||||
await flush();
|
||||
@@ -137,14 +130,14 @@ test('pan and zoom refresh through the manager without toggling; nearby changes
|
||||
});
|
||||
assert.match(h.layer.getRowControls().info, /Regional sample.*250 nm radius/);
|
||||
h.setAnchor({ latitude: 55.1, longitude: 20.1 });
|
||||
h.viewer.camera.changed.raiseEvent();
|
||||
h.camera.changed.raiseEvent();
|
||||
h.advance(5000);
|
||||
t.mock.timers.tick(5000);
|
||||
await flush();
|
||||
assert.equal(calls, 2, 'nearby views reuse the same query region');
|
||||
await manager.destroyAll();
|
||||
assert.equal(h.viewer.camera.moveEnd.numberOfListeners, 0);
|
||||
assert.equal(h.viewer.camera.changed.numberOfListeners, 0);
|
||||
assert.equal(h.camera.moveEnd.numberOfListeners, 0);
|
||||
assert.equal(h.camera.changed.numberOfListeners, 0);
|
||||
});
|
||||
|
||||
test('movement during a pending refresh follows up at the newest view; disable cancels queued work', async (t) => {
|
||||
@@ -162,12 +155,12 @@ test('movement during a pending refresh follows up at the newest view; disable c
|
||||
h.layer.enable();
|
||||
await h.layer.update();
|
||||
h.setAnchor({ latitude: 54, longitude: 19 });
|
||||
h.viewer.camera.moveEnd.raiseEvent();
|
||||
h.camera.moveEnd.raiseEvent();
|
||||
h.advance(2500);
|
||||
t.mock.timers.tick(2500);
|
||||
await flush();
|
||||
h.setAnchor({ latitude: 35, longitude: 140 });
|
||||
h.viewer.camera.changed.raiseEvent();
|
||||
h.camera.changed.raiseEvent();
|
||||
h.advance(2500);
|
||||
t.mock.timers.tick(2500);
|
||||
await flush();
|
||||
@@ -180,7 +173,7 @@ test('movement during a pending refresh follows up at the newest view; disable c
|
||||
assert.equal(calls.length, 3);
|
||||
assert.deepEqual(calls.at(-1), { latitude: 35, longitude: 140 });
|
||||
h.setAnchor({ latitude: 10, longitude: 10 });
|
||||
h.viewer.camera.moveEnd.raiseEvent();
|
||||
h.camera.moveEnd.raiseEvent();
|
||||
h.layer.disable();
|
||||
h.advance(5000);
|
||||
t.mock.timers.tick(5000);
|
||||
@@ -192,11 +185,11 @@ test('movement during a pending refresh follows up at the newest view; disable c
|
||||
test('the layer requires a snapshot source and cannot be initialized twice', () => {
|
||||
assert.throws(() => createGnssIntegrityLayer({}), TypeError);
|
||||
const { layer } = harness(async () => ({ rows: [] }));
|
||||
assert.throws(() => layer.init({ dataSources: { add() {} } }), /already/);
|
||||
assert.throws(() => layer.init(null, { engine: {} }), /already/);
|
||||
});
|
||||
|
||||
test('an enabled refresh bins the snapshot into coloured ground cells', async () => {
|
||||
const { layer, sources, anchors } = harness(async (anchor, { signal }) => {
|
||||
const { layer, cells, anchors } = harness(async (anchor, { signal }) => {
|
||||
assert.deepEqual(anchor, { latitude: 50, longitude: 30 });
|
||||
assert.ok(signal instanceof AbortSignal);
|
||||
return {
|
||||
@@ -213,13 +206,21 @@ test('an enabled refresh bins the snapshot into coloured ground cells', async ()
|
||||
assert.equal(await layer.update(), false, 'disabled layers do not fetch');
|
||||
assert.equal(anchors.length, 0);
|
||||
layer.enable();
|
||||
assert.equal(sources[0].show, true);
|
||||
assert.equal(cells().shown, true);
|
||||
assert.equal(await layer.update(), true);
|
||||
const entities = sources[0].get(0).geometryInstances;
|
||||
assert.equal(entities.length, 1, 'the one-aircraft cell is withheld');
|
||||
assert.equal(entities[0].id, 'gnss-integrity:280:420');
|
||||
assert.ok(entities[0].geometry instanceof Cesium.RectangleGeometry);
|
||||
assert.equal(sources[0].get(0).allowPicking, false);
|
||||
const { items, options } = cells();
|
||||
assert.equal(items.length, 1, 'the one-aircraft cell is withheld');
|
||||
// Cell 280:420, half a degree from 50° N, 30° E, at the high level.
|
||||
assert.deepEqual(
|
||||
{ ...items[0], fill: undefined },
|
||||
{ west: 30, south: 50, east: 30.5, north: 50.5, fill: undefined },
|
||||
);
|
||||
assert.deepEqual(
|
||||
items[0].fill,
|
||||
rgbaFromCss('#f85149').withAlpha(0.55).rgba(),
|
||||
);
|
||||
assert.equal(options.kind, 'cell');
|
||||
assert.equal(options.pickable, false);
|
||||
const stats = layer.getStats();
|
||||
assert.equal(stats.count, 1);
|
||||
assert.equal(stats.error, null);
|
||||
@@ -272,7 +273,7 @@ test('the visible layer leads with low navigation accuracy and exposes its prove
|
||||
|
||||
test('a failed refresh keeps the last cells and reports the error', async () => {
|
||||
let fail = false;
|
||||
const { layer, sources } = harness(async () => {
|
||||
const { layer, drawn } = harness(async () => {
|
||||
if (fail) throw new Error('adsb.lol HTTP 502');
|
||||
return {
|
||||
rows: [
|
||||
@@ -288,14 +289,14 @@ test('a failed refresh keeps the last cells and reports the error', async () =>
|
||||
assert.equal(layer.getStats().stale, true);
|
||||
fail = true;
|
||||
assert.equal(await layer.update(), true);
|
||||
assert.equal(sources[0].get(0)?.geometryInstances.length ?? 0, 1);
|
||||
assert.equal(drawn(), 1);
|
||||
assert.equal(layer.getStats().error, 'adsb.lol HTTP 502');
|
||||
assert.equal(layer.getStats().count, 1);
|
||||
});
|
||||
|
||||
test('observations expire with the window, and disable aborts the request in flight', async () => {
|
||||
let pending;
|
||||
const { layer, sources, advance } = harness(
|
||||
const { layer, drawn, cells, advance } = harness(
|
||||
(anchor, { signal }) =>
|
||||
new Promise((resolve, reject) => {
|
||||
pending = { resolve };
|
||||
@@ -315,17 +316,17 @@ test('observations expire with the window, and disable aborts the request in fli
|
||||
pending.resolve({ rows: [] });
|
||||
assert.equal(await result, true);
|
||||
assert.equal(layer.getStats().count, 0);
|
||||
assert.equal(sources[0].get(0)?.geometryInstances.length ?? 0, 0);
|
||||
assert.equal(drawn(), 0);
|
||||
|
||||
result = layer.update();
|
||||
layer.disable();
|
||||
assert.equal(await result, false);
|
||||
assert.equal(sources[0].show, false);
|
||||
assert.equal(cells().shown, false);
|
||||
});
|
||||
|
||||
test('no view anchor means no request, and destroy releases the data source', async () => {
|
||||
test('no view anchor means no request, and destroy releases the ground set', async () => {
|
||||
let calls = 0;
|
||||
const { layer, sources } = harness(
|
||||
const { layer, ground } = harness(
|
||||
async () => {
|
||||
calls += 1;
|
||||
return { rows: [] };
|
||||
@@ -341,13 +342,13 @@ test('no view anchor means no request, and destroy releases the data source', as
|
||||
assert.equal(calls, 0);
|
||||
assert.equal(layer.getStats().error, null);
|
||||
layer.destroy();
|
||||
assert.equal(sources.length, 0);
|
||||
assert.equal(ground.sets(), 0);
|
||||
assert.equal(layer.getStats().count, 0);
|
||||
});
|
||||
|
||||
test('a replayed stale snapshot keeps its observation age and expires on time', async () => {
|
||||
// The proxy keeps answering with the snapshot it observed at t=1000.
|
||||
const { layer, sources, advance, now } = harness(async () => ({
|
||||
const { layer, drawn, advance, now } = harness(async () => ({
|
||||
rows: threeHealthy(),
|
||||
ageMs: now() - 1_000,
|
||||
stale: true,
|
||||
@@ -369,12 +370,12 @@ test('a replayed stale snapshot keeps its observation age and expires on time',
|
||||
0,
|
||||
'the replay did not restart the window',
|
||||
);
|
||||
assert.equal(sources[0].get(0)?.geometryInstances.length ?? 0, 0);
|
||||
assert.equal(drawn(), 0);
|
||||
});
|
||||
|
||||
test('cells expire during prolonged fetch failures', async () => {
|
||||
let fail = false;
|
||||
const { layer, sources, advance } = harness(async () => {
|
||||
const { layer, drawn, advance } = harness(async () => {
|
||||
if (fail) throw new Error('adsb.lol HTTP 502');
|
||||
return { rows: threeHealthy() };
|
||||
});
|
||||
@@ -387,13 +388,13 @@ test('cells expire during prolonged fetch failures', async () => {
|
||||
advance(11 * MIN);
|
||||
assert.equal(await layer.update(), true);
|
||||
assert.equal(layer.getStats().count, 0);
|
||||
assert.equal(sources[0].get(0)?.geometryInstances.length ?? 0, 0);
|
||||
assert.equal(drawn(), 0);
|
||||
assert.equal(layer.getStats().error, 'adsb.lol HTTP 502');
|
||||
});
|
||||
|
||||
test('cells expire while no view anchor is available', async () => {
|
||||
let calls = 0;
|
||||
const { layer, sources, advance, setAnchor } = harness(async () => {
|
||||
const { layer, drawn, advance, setAnchor } = harness(async () => {
|
||||
calls += 1;
|
||||
return { rows: threeHealthy() };
|
||||
});
|
||||
@@ -407,36 +408,37 @@ test('cells expire while no view anchor is available', async () => {
|
||||
assert.equal(await layer.update(), true);
|
||||
assert.equal(calls, 1, 'no anchor means no request');
|
||||
assert.equal(layer.getStats().count, 0);
|
||||
assert.equal(sources[0].get(0)?.geometryInstances.length ?? 0, 0);
|
||||
assert.equal(drawn(), 0);
|
||||
assert.equal(layer.getStats().error, null);
|
||||
});
|
||||
|
||||
test('re-enabling after a long disable does not show cells past the window', async () => {
|
||||
const { layer, sources, advance } = harness(async () => ({
|
||||
const { layer, drawn, advance } = harness(async () => ({
|
||||
rows: threeHealthy(),
|
||||
}));
|
||||
layer.enable();
|
||||
await layer.update();
|
||||
assert.equal(sources[0].get(0)?.geometryInstances.length ?? 0, 1);
|
||||
assert.equal(drawn(), 1);
|
||||
layer.disable();
|
||||
advance(31 * MIN);
|
||||
layer.enable();
|
||||
assert.equal(layer.getStats().count, 0);
|
||||
assert.equal(sources[0].get(0)?.geometryInstances.length ?? 0, 0);
|
||||
assert.equal(drawn(), 0);
|
||||
});
|
||||
|
||||
const threeCells = () => ({
|
||||
rows: [row('a1', 50.1, true), row('a2', 50.1, true), row('a3', 50.2, false)],
|
||||
});
|
||||
|
||||
test('an identical snapshot leaves the drawn entities untouched', async () => {
|
||||
const { layer, sources } = harness(async () => threeCells());
|
||||
test('an identical snapshot leaves the drawn cells untouched', async () => {
|
||||
const { layer, drawn, cells } = harness(async () => threeCells());
|
||||
layer.enable();
|
||||
await layer.update();
|
||||
const first = sources[0].get(0);
|
||||
const first = cells();
|
||||
await layer.update();
|
||||
assert.equal(sources[0].get(0)?.geometryInstances.length ?? 0, 1);
|
||||
assert.equal(sources[0].get(0), first);
|
||||
assert.equal(drawn(), 1);
|
||||
assert.equal(cells().commits, first.commits);
|
||||
assert.equal(cells().items, first.items);
|
||||
});
|
||||
|
||||
test('an initial feed failure stays enabled, reports unavailable, and recovers automatically', async (t) => {
|
||||
@@ -450,7 +452,7 @@ test('an initial feed failure stays enabled, reports unavailable, and recovers a
|
||||
},
|
||||
{ initialize: false },
|
||||
);
|
||||
const manager = new LayerLifecycle(h.viewer);
|
||||
const manager = new LayerLifecycle(h.viewer, { engine: h.engine });
|
||||
manager.register(h.layer);
|
||||
h.layer.attachDataManager(manager);
|
||||
const changes = [];
|
||||
@@ -496,7 +498,7 @@ test('provider cooldown is preserved across movement and toggling; disable cance
|
||||
h.layer.enable();
|
||||
await h.layer.update();
|
||||
h.setAnchor({ latitude: 10, longitude: 20 });
|
||||
h.viewer.camera.moveEnd.raiseEvent();
|
||||
h.camera.moveEnd.raiseEvent();
|
||||
h.advance(30000);
|
||||
t.mock.timers.tick(30000);
|
||||
await flush();
|
||||
@@ -583,7 +585,7 @@ test('GERMAN: camera debounce and minimum request gap are pinned', async (t) =>
|
||||
h.layer.enable();
|
||||
await h.layer.update();
|
||||
h.setAnchor({ latitude: 51, longitude: 31 });
|
||||
h.viewer.camera.changed.raiseEvent();
|
||||
h.camera.changed.raiseEvent();
|
||||
h.advance(2499);
|
||||
t.mock.timers.tick(2499);
|
||||
await flush();
|
||||
@@ -594,7 +596,7 @@ test('GERMAN: camera debounce and minimum request gap are pinned', async (t) =>
|
||||
assert.equal(calls, 2);
|
||||
h.advance(3000);
|
||||
h.setAnchor({ latitude: 52, longitude: 32 });
|
||||
h.viewer.camera.changed.raiseEvent();
|
||||
h.camera.changed.raiseEvent();
|
||||
h.advance(599);
|
||||
t.mock.timers.tick(599);
|
||||
await flush();
|
||||
@@ -619,7 +621,7 @@ test('camera movement during initial activation waits for acquisition before fol
|
||||
h.layer.enable();
|
||||
const initial = h.layer.update();
|
||||
h.setAnchor({ latitude: 51, longitude: 31 });
|
||||
h.viewer.camera.changed.raiseEvent();
|
||||
h.camera.changed.raiseEvent();
|
||||
h.advance(2500);
|
||||
t.mock.timers.tick(2500);
|
||||
await flush();
|
||||
@@ -652,13 +654,13 @@ test('monotonic camera scheduling is unaffected by wall-clock rollback', async (
|
||||
now: () => wall,
|
||||
monotonicNow: () => mono,
|
||||
});
|
||||
layer.init(h.viewer);
|
||||
layer.init(null, { engine: h.engine });
|
||||
layer.enable();
|
||||
await layer.update();
|
||||
wall -= 3600000;
|
||||
mono = 3000;
|
||||
anchor = { latitude: 51, longitude: 31 };
|
||||
h.viewer.camera.changed.raiseEvent();
|
||||
h.camera.changed.raiseEvent();
|
||||
mono += 600;
|
||||
t.mock.timers.tick(600);
|
||||
await flush();
|
||||
@@ -666,37 +668,58 @@ test('monotonic camera scheduling is unaffected by wall-clock rollback', async (
|
||||
layer.destroy();
|
||||
});
|
||||
|
||||
test('GNSS fill emits no pick-pass commands but keeps normal rendering', async (t) => {
|
||||
test('the cells stay out of picks', async () => {
|
||||
const h = harness(async () => ({ rows: threeHealthy() }));
|
||||
h.layer.enable();
|
||||
await h.layer.update();
|
||||
const fill = h.sources[0].get(0);
|
||||
let updates = 0;
|
||||
t.mock.method(Cesium.GroundPrimitive.prototype, 'update', () => updates++);
|
||||
fill.update({ passes: { pick: true } });
|
||||
assert.equal(updates, 0);
|
||||
fill.update({ passes: { render: true, pick: false } });
|
||||
assert.equal(updates, 1);
|
||||
assert.equal(h.cells().options.pickable, false);
|
||||
// A pick at the drawn cell (1° N, 30.2° E) finds nothing of the layer.
|
||||
h.engine.camera.setView({
|
||||
destination: geo.cartesian3.fromDegrees(30.2, 1.2, 100_000),
|
||||
});
|
||||
const { width, height } = h.engine.host.size();
|
||||
assert.equal(
|
||||
h.engine.picker.pick({ x: width / 2, y: height / 2 }),
|
||||
undefined,
|
||||
);
|
||||
h.layer.destroy();
|
||||
assert.equal(fill.isDestroyed(), true);
|
||||
assert.equal(h.ground.sets(), 0);
|
||||
});
|
||||
|
||||
test('view anchor falls back to rectangle, then nadir, then no camera', () => {
|
||||
assert.equal(defaultGnssViewAnchor({}), null);
|
||||
const viewer = {
|
||||
const radians = geo.math.toRadians;
|
||||
const engine = {
|
||||
host: { size: () => ({ width: 1000, height: 800 }) },
|
||||
camera: {
|
||||
computeViewRectangle: () => Cesium.Rectangle.fromDegrees(20, 40, 22, 42),
|
||||
pickEllipsoid: () => undefined,
|
||||
viewRectangle: () => ({
|
||||
west: radians(20),
|
||||
south: radians(40),
|
||||
east: radians(22),
|
||||
north: radians(42),
|
||||
}),
|
||||
pose: () => assert.fail('a rectangle must not read the pose'),
|
||||
},
|
||||
};
|
||||
const rectangleAnchor = defaultGnssViewAnchor(viewer);
|
||||
const rectangleAnchor = defaultGnssViewAnchor(engine);
|
||||
assert.ok(Math.abs(rectangleAnchor.latitude - 41) < 1e-10);
|
||||
assert.ok(Math.abs(rectangleAnchor.longitude - 21) < 1e-10);
|
||||
viewer.camera = {
|
||||
positionCartographic: Cesium.Cartographic.fromDegrees(21, 41),
|
||||
engine.camera = {
|
||||
pickEllipsoid: () => assert.fail('an empty canvas has no centre'),
|
||||
viewRectangle: () => undefined,
|
||||
pose: () => ({
|
||||
cartographic: { longitude: radians(21), latitude: radians(41) },
|
||||
}),
|
||||
};
|
||||
const nadirAnchor = defaultGnssViewAnchor(viewer);
|
||||
engine.host = { size: () => ({ width: 0, height: 0 }) };
|
||||
const nadirAnchor = defaultGnssViewAnchor(engine);
|
||||
assert.ok(Math.abs(nadirAnchor.latitude - 41) < 1e-10);
|
||||
assert.ok(Math.abs(nadirAnchor.longitude - 21) < 1e-10);
|
||||
engine.camera.pose = () => ({
|
||||
cartographic: { longitude: Number.NaN, latitude: 0 },
|
||||
});
|
||||
assert.equal(defaultGnssViewAnchor(engine), null);
|
||||
});
|
||||
|
||||
test('an in-flight regional response supplies the next renderer without a new request', async () => {
|
||||
@@ -712,15 +735,15 @@ test('an in-flight regional response supplies the next renderer without a new re
|
||||
h.layer.enable();
|
||||
const pending = h.layer.update();
|
||||
h.layer.detachRenderer();
|
||||
assert.equal(h.viewer.camera.changed.numberOfListeners, 0);
|
||||
assert.equal(h.camera.changed.numberOfListeners, 0);
|
||||
resolve({ rows: threeHealthy() });
|
||||
assert.equal(await pending, true);
|
||||
assert.equal(h.sources.length, 0);
|
||||
assert.equal(h.ground.sets(), 0);
|
||||
assert.equal(h.layer.getStats().levels.low, 1);
|
||||
h.layer.attachRenderer(h.viewer);
|
||||
assert.equal(h.sources[0].length, 1);
|
||||
h.layer.attachRenderer(null, { engine: h.engine });
|
||||
assert.equal(h.drawn(), 1);
|
||||
assert.equal(calls, 1);
|
||||
assert.equal(h.viewer.camera.changed.numberOfListeners, 1);
|
||||
assert.equal(h.camera.changed.numberOfListeners, 1);
|
||||
} finally {
|
||||
h.layer.destroy();
|
||||
}
|
||||
|
||||
@@ -1,99 +0,0 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { GNSS_LEVEL_COLORS } from '../records.js';
|
||||
|
||||
/** Degrees at the centre of the current view, or null before the camera settles. */
|
||||
export function defaultGnssViewAnchor(viewer) {
|
||||
const canvas = viewer?.scene?.canvas;
|
||||
const ellipsoid = viewer?.scene?.globe?.ellipsoid;
|
||||
// At globe scale the visible rectangle can be the whole world, whose
|
||||
// midpoint is unrelated to the place under the screen centre.
|
||||
const centre =
|
||||
canvas?.clientWidth > 0 &&
|
||||
canvas.clientHeight > 0 &&
|
||||
viewer.camera?.pickEllipsoid?.(
|
||||
new Cesium.Cartesian2(canvas.clientWidth / 2, canvas.clientHeight / 2),
|
||||
ellipsoid,
|
||||
);
|
||||
const rectangle =
|
||||
!centre && viewer?.camera?.computeViewRectangle?.(ellipsoid);
|
||||
const carto = centre
|
||||
? (ellipsoid || Cesium.Ellipsoid.WGS84).cartesianToCartographic(centre)
|
||||
: rectangle
|
||||
? Cesium.Rectangle.center(rectangle)
|
||||
: viewer?.camera?.positionCartographic;
|
||||
if (!carto) return null;
|
||||
const latitude = Cesium.Math.toDegrees(carto.latitude);
|
||||
const longitude = Cesium.Math.toDegrees(carto.longitude);
|
||||
return Number.isFinite(latitude) && Number.isFinite(longitude)
|
||||
? { latitude, longitude }
|
||||
: null;
|
||||
}
|
||||
|
||||
export function createGnssCesiumRenderer({
|
||||
viewer,
|
||||
viewAnchor = defaultGnssViewAnchor,
|
||||
}) {
|
||||
// GroundPrimitive allowPicking:false still submits stencil commands in
|
||||
// the pick pass. Keep this fill from erasing overlapping geometry's picks.
|
||||
class GnssGroundFill extends Cesium.GroundPrimitive {
|
||||
update(frameState) {
|
||||
if (!frameState.passes.pick) super.update(frameState);
|
||||
}
|
||||
}
|
||||
|
||||
const primitives = new Cesium.PrimitiveCollection();
|
||||
primitives.id = 'gnss-integrity';
|
||||
primitives.show = false;
|
||||
viewer.scene.groundPrimitives.add(primitives);
|
||||
return {
|
||||
camera: viewer.camera,
|
||||
anchor: () => viewAnchor(viewer),
|
||||
setVisible(show) {
|
||||
primitives.show = show;
|
||||
},
|
||||
replace(cells, alpha) {
|
||||
primitives.removeAll();
|
||||
if (cells.length) {
|
||||
primitives.add(
|
||||
new GnssGroundFill({
|
||||
geometryInstances: cells.map(
|
||||
(cell) =>
|
||||
new Cesium.GeometryInstance({
|
||||
id: `gnss-integrity:${cell.id}`,
|
||||
geometry: new Cesium.RectangleGeometry({
|
||||
rectangle: Cesium.Rectangle.fromDegrees(
|
||||
cell.west,
|
||||
cell.south,
|
||||
cell.east,
|
||||
cell.north,
|
||||
),
|
||||
vertexFormat:
|
||||
Cesium.PerInstanceColorAppearance.VERTEX_FORMAT,
|
||||
}),
|
||||
attributes: {
|
||||
color: Cesium.ColorGeometryInstanceAttribute.fromColor(
|
||||
Cesium.Color.fromCssColorString(
|
||||
GNSS_LEVEL_COLORS[cell.level],
|
||||
).withAlpha(alpha[cell.level]),
|
||||
),
|
||||
},
|
||||
}),
|
||||
),
|
||||
appearance: new Cesium.PerInstanceColorAppearance({
|
||||
flat: true,
|
||||
translucent: true,
|
||||
}),
|
||||
classificationType: Cesium.ClassificationType.BOTH,
|
||||
allowPicking: false,
|
||||
// Retain the compact rectangle descriptors for inspection, not Entity visualizers.
|
||||
releaseGeometryInstances: false,
|
||||
}),
|
||||
);
|
||||
}
|
||||
viewer?.scene?.requestRender?.();
|
||||
},
|
||||
destroy() {
|
||||
viewer.scene.groundPrimitives.remove(primitives);
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
// The GNSS integrity cells on the globe contract (engine.ground,
|
||||
// engine.camera), the same on every engine: one ground cell per binned
|
||||
// cell, filled in its level's colour at the layer's alpha for that level,
|
||||
// without an outline. The set is not pickable, so the cells never hide
|
||||
// what lies under them from a pick.
|
||||
|
||||
import * as geo from '../../../geo/index.js';
|
||||
import { rgbaFromCss } from '../../shared/color.js';
|
||||
import { viewRectangleCenter } from '../../shared/viewRectangle.js';
|
||||
import { GNSS_LEVEL_COLORS } from '../records.js';
|
||||
|
||||
const SET_ID = 'gnss-integrity';
|
||||
|
||||
/**
|
||||
* Degrees at the centre of the current view: the ellipsoid under the screen
|
||||
* centre, else the view rectangle's centre (at globe scale the rectangle can
|
||||
* be the whole world, whose midpoint is unrelated to the place under the
|
||||
* screen centre), else under the camera; null when none is finite.
|
||||
* @param {import('../../../globe/contract.js').GlobeEngine} engine
|
||||
* @returns {{ latitude: number, longitude: number } | null}
|
||||
*/
|
||||
export function defaultGnssViewAnchor(engine) {
|
||||
const camera = engine?.camera;
|
||||
if (!camera) return null;
|
||||
const { width, height } = engine.host?.size?.() ?? {};
|
||||
const centre =
|
||||
width > 0 &&
|
||||
height > 0 &&
|
||||
camera.pickEllipsoid({ x: width / 2, y: height / 2 });
|
||||
let place = centre ? geo.cartographic.fromCartesian(centre) : undefined;
|
||||
if (!place) {
|
||||
const rectangle = camera.viewRectangle();
|
||||
place = rectangle
|
||||
? viewRectangleCenter(rectangle)
|
||||
: camera.pose()?.cartographic;
|
||||
}
|
||||
if (!place) return null;
|
||||
const latitude = geo.math.toDegrees(place.latitude);
|
||||
const longitude = geo.math.toDegrees(place.longitude);
|
||||
return Number.isFinite(latitude) && Number.isFinite(longitude)
|
||||
? { latitude, longitude }
|
||||
: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The cells: `{ camera, anchor, setVisible, replace(cells, alpha), destroy }`.
|
||||
* `camera` is the engine's (its moveEnd and changed events); `anchor()` is
|
||||
* `viewAnchor(engine)`. A cell is `{ west, south, east, north, level }` in
|
||||
* degrees; `alpha` maps a level to its fill alpha.
|
||||
* @param {import('../../../globe/contract.js').GlobeEngine} engine
|
||||
* @param {{ viewAnchor?: (engine: object) => ({ latitude: number, longitude: number } | null) }} [options]
|
||||
*/
|
||||
export function createGnssDisplay(
|
||||
engine,
|
||||
{ viewAnchor = defaultGnssViewAnchor } = {},
|
||||
) {
|
||||
if (!engine?.ground)
|
||||
throw new TypeError('The GNSS display needs a globe engine');
|
||||
const set = engine.ground.createSet({ id: SET_ID, kind: 'cell' });
|
||||
set.show(false);
|
||||
let destroyed = false;
|
||||
return {
|
||||
camera: engine.camera,
|
||||
anchor: () => viewAnchor(engine),
|
||||
setVisible(show) {
|
||||
if (!destroyed) set.show(show);
|
||||
},
|
||||
replace(cells, alpha) {
|
||||
if (destroyed) return;
|
||||
set.replace(
|
||||
cells.map(({ west, south, east, north, level }) => ({
|
||||
west,
|
||||
south,
|
||||
east,
|
||||
north,
|
||||
fill: rgbaFromCss(GNSS_LEVEL_COLORS[level])
|
||||
.withAlpha(alpha[level])
|
||||
.rgba(),
|
||||
})),
|
||||
);
|
||||
set.commit();
|
||||
},
|
||||
destroy() {
|
||||
if (destroyed) return;
|
||||
destroyed = true;
|
||||
set.destroy();
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
// The GNSS integrity cells on the engine contract, on the fake engine and
|
||||
// on the Cesium engine (its ground batches over fake primitives, and once
|
||||
// over Cesium's own GroundPrimitive): one unpicked cell per bin in its
|
||||
// level's colour and alpha, no outline, the camera and view anchor the
|
||||
// layer reads, visibility and teardown.
|
||||
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import * as Cesium from 'cesium';
|
||||
import * as geo from '../../../geo/index.js';
|
||||
import {
|
||||
GROUND_HARNESSES,
|
||||
createCesiumGroundHarness,
|
||||
createFakeGroundHarness,
|
||||
instanceColor,
|
||||
} from '../../../testSupport/groundDisplayEngines.mjs';
|
||||
import { rgbaFromCss } from '../../shared/color.js';
|
||||
import { GNSS_LEVEL_COLORS } from '../records.js';
|
||||
import { createGnssDisplay, defaultGnssViewAnchor } from './display.js';
|
||||
|
||||
const ALPHA = Object.freeze({ low: 0.3, medium: 0.42, high: 0.55 });
|
||||
const cells = [
|
||||
{ id: '280:420', west: 30, south: 50, east: 30.5, north: 50.5, level: 'low' },
|
||||
{
|
||||
id: '280:421',
|
||||
west: 30.5,
|
||||
south: 50,
|
||||
east: 31,
|
||||
north: 50.5,
|
||||
level: 'medium',
|
||||
},
|
||||
{
|
||||
id: '281:420',
|
||||
west: 30,
|
||||
south: 50.5,
|
||||
east: 30.5,
|
||||
north: 51,
|
||||
level: 'high',
|
||||
},
|
||||
];
|
||||
const fillOf = (level) =>
|
||||
rgbaFromCss(GNSS_LEVEL_COLORS[level]).withAlpha(ALPHA[level]).rgba();
|
||||
|
||||
const near = (actual, expected, label, tolerance = 1e-9) =>
|
||||
assert.ok(
|
||||
Math.abs(actual - expected) < tolerance,
|
||||
`${label}: ${actual} vs ${expected}`,
|
||||
);
|
||||
|
||||
test('the display needs a globe engine', () => {
|
||||
assert.throws(() => createGnssDisplay(null), TypeError);
|
||||
});
|
||||
|
||||
for (const makeHarness of GROUND_HARNESSES) {
|
||||
const { name } = makeHarness();
|
||||
|
||||
test(`each cell is an unpicked ground cell in its level's colour and alpha (${name})`, () => {
|
||||
const h = makeHarness();
|
||||
const display = createGnssDisplay(h.engine);
|
||||
try {
|
||||
assert.equal(h.set('gnss-integrity').shown, false, 'hidden until shown');
|
||||
display.setVisible(true);
|
||||
display.replace(cells, ALPHA);
|
||||
const set = h.set('gnss-integrity');
|
||||
assert.equal(set.options.kind, 'cell');
|
||||
assert.equal(set.options.pickable, false);
|
||||
assert.equal(set.shown, true);
|
||||
assert.deepEqual(
|
||||
set.items,
|
||||
cells.map(({ west, south, east, north, level }) => ({
|
||||
west,
|
||||
south,
|
||||
east,
|
||||
north,
|
||||
fill: fillOf(level),
|
||||
})),
|
||||
);
|
||||
if (h.cesium) {
|
||||
const { fills, lines } = h.primitives('gnss-integrity');
|
||||
assert.equal(fills.length, 1, 'one ground batch');
|
||||
assert.equal(lines.length, 0, 'no outline batch');
|
||||
const { geometryInstances, classificationType, allowPicking } =
|
||||
fills[0].options;
|
||||
assert.equal(classificationType, Cesium.ClassificationType.BOTH);
|
||||
assert.equal(allowPicking, false);
|
||||
geometryInstances.forEach((instance, index) => {
|
||||
const cell = cells[index];
|
||||
assert.ok(instance.geometry instanceof Cesium.RectangleGeometry);
|
||||
const rectangle = instance.geometry._rectangle;
|
||||
near(rectangle.west, geo.math.toRadians(cell.west), 'west');
|
||||
near(rectangle.south, geo.math.toRadians(cell.south), 'south');
|
||||
near(rectangle.east, geo.math.toRadians(cell.east), 'east');
|
||||
near(rectangle.north, geo.math.toRadians(cell.north), 'north');
|
||||
instanceColor(instance).forEach((channel, at) =>
|
||||
near(
|
||||
channel,
|
||||
fillOf(cell.level)[at],
|
||||
`colour ${index}.${at}`,
|
||||
0.5 / 255,
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
display.setVisible(false);
|
||||
assert.equal(h.set('gnss-integrity').shown, false);
|
||||
if (h.cesium) assert.equal(h.collectionShown('gnss-integrity'), false);
|
||||
display.replace([], ALPHA);
|
||||
assert.equal(h.set('gnss-integrity').items.length, 0);
|
||||
if (h.cesium)
|
||||
assert.equal(h.primitives('gnss-integrity').fills.length, 0);
|
||||
} finally {
|
||||
display.destroy();
|
||||
display.destroy();
|
||||
}
|
||||
assert.equal(h.sets(), 0);
|
||||
display.replace(cells, ALPHA);
|
||||
display.setVisible(true);
|
||||
h.destroy();
|
||||
});
|
||||
|
||||
test(`the camera and the view anchor are the engine's (${name})`, () => {
|
||||
const h = makeHarness();
|
||||
h.engine.camera.setView({
|
||||
destination: geo.cartesian3.fromDegrees(30.2, 50.2, 400_000),
|
||||
});
|
||||
const display = createGnssDisplay(h.engine);
|
||||
assert.equal(display.camera, h.engine.camera);
|
||||
const anchor = display.anchor();
|
||||
near(anchor.latitude, 50.2, 'latitude', 0.01);
|
||||
near(anchor.longitude, 30.2, 'longitude', 0.01);
|
||||
display.destroy();
|
||||
const seen = [];
|
||||
const custom = createGnssDisplay(h.engine, {
|
||||
viewAnchor: (engine) => {
|
||||
seen.push(engine);
|
||||
return { latitude: 1, longitude: 2 };
|
||||
},
|
||||
});
|
||||
assert.deepEqual(custom.anchor(), { latitude: 1, longitude: 2 });
|
||||
assert.deepEqual(seen, [h.engine]);
|
||||
custom.destroy();
|
||||
h.destroy();
|
||||
});
|
||||
}
|
||||
|
||||
test('the anchor under a globe-wide view is the screen centre (the fake engine)', () => {
|
||||
const h = createFakeGroundHarness();
|
||||
h.engine.camera.setView({
|
||||
destination: geo.cartesian3.fromDegrees(-97, 30, 20_000_000),
|
||||
});
|
||||
const anchor = defaultGnssViewAnchor(h.engine);
|
||||
near(anchor.latitude, 30, 'latitude', 0.5);
|
||||
near(anchor.longitude, -97, 'longitude', 0.01);
|
||||
h.destroy();
|
||||
});
|
||||
|
||||
test("Cesium's ground fill emits no pick-pass commands but keeps normal rendering", (t) => {
|
||||
const h = createCesiumGroundHarness({ realFills: true });
|
||||
const display = createGnssDisplay(h.engine);
|
||||
display.setVisible(true);
|
||||
display.replace(cells, ALPHA);
|
||||
const [fill] = h.primitives('gnss-integrity').fills;
|
||||
assert.ok(fill instanceof Cesium.GroundPrimitive);
|
||||
let updates = 0;
|
||||
t.mock.method(Cesium.GroundPrimitive.prototype, 'update', () => updates++);
|
||||
fill.update({ passes: { pick: true } });
|
||||
assert.equal(updates, 0);
|
||||
fill.update({ passes: { render: true, pick: false } });
|
||||
assert.equal(updates, 1);
|
||||
display.destroy();
|
||||
assert.equal(fill.isDestroyed(), true);
|
||||
h.destroy();
|
||||
});
|
||||
@@ -1,40 +0,0 @@
|
||||
import * as geo from '../../../geo/index.js';
|
||||
import { GNSS_LEVEL_COLORS } from '../records.js';
|
||||
import { rgbaFromCss } from '../../shared/color.js';
|
||||
import { viewRectangleCenter } from '../../shared/viewRectangle.js';
|
||||
import { createGroundCellDisplay } from '../../shared/render/navaraGroundCells.js';
|
||||
|
||||
export function createGnssNavaraRenderer(engine, options) {
|
||||
const cells = createGroundCellDisplay(engine, options, 0);
|
||||
const { camera } = engine;
|
||||
function anchor() {
|
||||
const { width, height } = engine.host.size();
|
||||
const centre =
|
||||
width && height && camera.pickEllipsoid({ x: width / 2, y: height / 2 });
|
||||
let position = centre && geo.cartographic.fromCartesian(centre);
|
||||
if (!position) {
|
||||
const rect = camera.viewRectangle();
|
||||
position = rect ? viewRectangleCenter(rect) : camera.pose().cartographic;
|
||||
}
|
||||
return {
|
||||
latitude: geo.math.toDegrees(position.latitude),
|
||||
longitude: geo.math.toDegrees(position.longitude),
|
||||
};
|
||||
}
|
||||
return {
|
||||
camera,
|
||||
anchor,
|
||||
setVisible: cells.setVisible,
|
||||
destroy: cells.destroy,
|
||||
replace(rows, alpha) {
|
||||
cells.replace(
|
||||
rows.map((row) => ({
|
||||
...row,
|
||||
color: rgbaFromCss(GNSS_LEVEL_COLORS[row.level]).withAlpha(
|
||||
alpha[row.level],
|
||||
),
|
||||
})),
|
||||
);
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
// card's info line shows them in the UI language, the HTTP form included.
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import * as Cesium from 'cesium';
|
||||
import { createFakeEngine } from '../../globe/testing/fakeEngine.js';
|
||||
import { setLocale } from '../../i18n/index.js';
|
||||
import { createGnssIntegrityLayer } from './index.js';
|
||||
|
||||
@@ -20,13 +20,7 @@ async function failedLayer(message) {
|
||||
now: () => 1_000,
|
||||
monotonicNow: () => 1_000,
|
||||
});
|
||||
layer.init({
|
||||
camera: { moveEnd: new Cesium.Event(), changed: new Cesium.Event() },
|
||||
scene: {
|
||||
globe: { show: true },
|
||||
groundPrimitives: { add() {}, remove() {} },
|
||||
},
|
||||
});
|
||||
layer.init(null, { engine: createFakeEngine() });
|
||||
layer.enable();
|
||||
await layer.update();
|
||||
return layer;
|
||||
|
||||
Reference in new issue
Block a user