mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 09:42:21 +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
@@ -0,0 +1,763 @@
|
||||
// The cables display on the engine contract, on the fake engine and on the
|
||||
// Cesium engine: cable paths and their colours, widths, picks and drape per
|
||||
// map stack; landing markers; the reference sweep (tips, horizon, labels,
|
||||
// the publish skip, the winners' stems, the moveEnd and motion cadence);
|
||||
// clicks that fly to a reference; hide, show and destroy; and the
|
||||
// antimeridian edge cases. Each harness records what the ground sets were
|
||||
// given and the flights asked for, drives preRender and moveEnd by hand, and
|
||||
// clicks with a pick of a ground item, a mover instance or a line.
|
||||
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import * as Cesium from 'cesium';
|
||||
import * as geo from '../../../geo/index.js';
|
||||
import { createFakeEngine } from '../../../globe/testing/fakeEngine.js';
|
||||
import { createFakeEventHandlers } from '../../../globe/cesium/testing/fakeViewer.mjs';
|
||||
import { createCesiumMoversEngine } from '../../../testSupport/cesiumMoversEngine.mjs';
|
||||
import { claimPointer, releasePointer } from '../../../data/inputOwnership.js';
|
||||
import { rgbaFromCss } from '../../shared/color.js';
|
||||
import {
|
||||
BASE_CABLE_COLOR,
|
||||
BASE_LANDING_COLOR,
|
||||
CABLE_OVERLAY_COLLISION_CAPACITY,
|
||||
CABLE_OVERLAY_SOURCE_ID,
|
||||
CABLE_REFERENCE_LABEL_WINNER_CAP,
|
||||
CABLE_SWEEP_MOTION_PROBE_INTERVAL_MS,
|
||||
} from '../policy.js';
|
||||
import { createCablesDisplay } from './display.js';
|
||||
|
||||
// GroundPolylinePrimitive checks its render state's line width against the
|
||||
// context's limits, which a stub scene has none of.
|
||||
Cesium.ContextLimits._minimumAliasedLineWidth = 1;
|
||||
Cesium.ContextLimits._maximumAliasedLineWidth = 10;
|
||||
|
||||
function watch(engine) {
|
||||
const sets = new Map();
|
||||
const createSet = engine.ground.createSet.bind(engine.ground);
|
||||
engine.ground.createSet = (options) => {
|
||||
const set = createSet(options);
|
||||
const record = { options, pending: [], items: [], commits: 0 };
|
||||
const { replace, commit } = set;
|
||||
set.replace = (items) => {
|
||||
replace(items);
|
||||
record.pending = items;
|
||||
};
|
||||
set.commit = () => {
|
||||
commit();
|
||||
record.items = record.pending;
|
||||
record.commits++;
|
||||
};
|
||||
sets.set(options.id, record);
|
||||
return set;
|
||||
};
|
||||
const positionsSet = new Map();
|
||||
const createLine = engine.lines.createLine.bind(engine.lines);
|
||||
engine.lines.createLine = (options) => {
|
||||
const line = createLine(options);
|
||||
const { setPositions } = line;
|
||||
positionsSet.set(options.id, 0);
|
||||
line.setPositions = (positions) => {
|
||||
positionsSet.set(options.id, positionsSet.get(options.id) + 1);
|
||||
setPositions(positions);
|
||||
};
|
||||
return line;
|
||||
};
|
||||
const flights = [];
|
||||
engine.camera.flyTo = (options) => flights.push(options);
|
||||
return {
|
||||
/** A live ground set: its options and last committed items. */
|
||||
groundSet(id) {
|
||||
const listed = engine.ground.list().find((entry) => entry.id === id);
|
||||
return listed ? sets.get(id) : undefined;
|
||||
},
|
||||
/** How often a line's positions were set. */
|
||||
positionsSet: (id) => positionsSet.get(id) ?? 0,
|
||||
flights,
|
||||
lineIds: () => engine.lines.list().map(({ id }) => id),
|
||||
look(lon, lat, height) {
|
||||
engine.camera.setView({
|
||||
destination: geo.cartesian3.fromDegrees(lon, lat, height),
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function fakeHarness() {
|
||||
const engine = createFakeEngine();
|
||||
const watched = watch(engine);
|
||||
return {
|
||||
name: 'the fake engine',
|
||||
engine,
|
||||
...watched,
|
||||
preRender: () => engine.fake.emit('frames.preRender', 0),
|
||||
moveEnd: () => engine.fake.emit('camera.moveEnd'),
|
||||
/** A mover set's instance: shown, colour, size and pickId. */
|
||||
point(id, index) {
|
||||
const entry = engine.fake.moverSet(id);
|
||||
if (!entry || index >= entry.store.count) return undefined;
|
||||
const { store, options } = entry;
|
||||
return {
|
||||
shown: store.shows[index] === 1,
|
||||
color: [...store.colors.slice(index * 4, index * 4 + 4)],
|
||||
sizePx: options.point.sizePx,
|
||||
outlinePx: options.point.outlinePx,
|
||||
id: store.pickIds[index],
|
||||
position: {
|
||||
x: store.positions[index * 3],
|
||||
y: store.positions[index * 3 + 1],
|
||||
z: store.positions[index * 3 + 2],
|
||||
},
|
||||
};
|
||||
},
|
||||
line(id) {
|
||||
const line = engine.fake.line(id);
|
||||
return line && { positions: line.positions, color: line.color };
|
||||
},
|
||||
click(target) {
|
||||
const picked =
|
||||
target?.ground !== undefined
|
||||
? {
|
||||
id: watched.groundSet(target.ground).items[target.instance]
|
||||
.pickId,
|
||||
owner: target.ground,
|
||||
instance: target.instance,
|
||||
}
|
||||
: target?.mover !== undefined
|
||||
? {
|
||||
id: engine.fake.moverSet(target.mover).store.pickIds[
|
||||
target.instance
|
||||
],
|
||||
owner: target.mover,
|
||||
instance: target.instance,
|
||||
}
|
||||
: target?.line !== undefined
|
||||
? {
|
||||
id: engine.fake.line(target.line).options.pickId,
|
||||
owner: target.line,
|
||||
}
|
||||
: target;
|
||||
engine.fake.script('pick', picked);
|
||||
engine.fake.input('click', { position: { x: 100, y: 100 } });
|
||||
engine.fake.unscript('pick');
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function cesiumHarness() {
|
||||
const handlers = createFakeEventHandlers();
|
||||
const { engine, viewer, primitive } = createCesiumMoversEngine({
|
||||
engineOptions: {
|
||||
createEventHandler: handlers.create,
|
||||
scheduleFrame: (run) => run(),
|
||||
},
|
||||
});
|
||||
viewer.scene.groundPrimitives = new Cesium.PrimitiveCollection();
|
||||
let native;
|
||||
viewer.scene.pick = () => native;
|
||||
viewer.scene.drillPick = () => (native ? [native] : []);
|
||||
const watched = watch(engine);
|
||||
const count = (id) => engine.movers.list().find((set) => set.id === id).count;
|
||||
return {
|
||||
name: 'the Cesium engine',
|
||||
cesium: true,
|
||||
engine,
|
||||
viewer,
|
||||
...watched,
|
||||
preRender: () => viewer.scene.preRender.raiseEvent(viewer.scene),
|
||||
moveEnd: () => viewer.camera.moveEnd.raiseEvent(),
|
||||
/** The Cesium ground primitives a set drew, in its slot. */
|
||||
groundPrimitives(id) {
|
||||
const root = viewer.scene.groundPrimitives.get(0);
|
||||
const found = [];
|
||||
for (let index = 0; index < (root?.length ?? 0); index++) {
|
||||
const slot = root.get(index);
|
||||
for (let at = 0; at < slot.length; at++)
|
||||
if (slot.get(at).gevGroundSet === id) found.push(slot.get(at));
|
||||
}
|
||||
return found;
|
||||
},
|
||||
point(id, index) {
|
||||
const collection = primitive(id);
|
||||
if (!collection || index >= count(id)) return undefined;
|
||||
const item = collection.get(index);
|
||||
return {
|
||||
shown: item.show,
|
||||
color: [
|
||||
item.color.red,
|
||||
item.color.green,
|
||||
item.color.blue,
|
||||
item.color.alpha,
|
||||
],
|
||||
sizePx: item.pixelSize,
|
||||
outlinePx: item.outlineWidth,
|
||||
outlineColor: item.outlineColor,
|
||||
id: item.id,
|
||||
position: item.position,
|
||||
native: item,
|
||||
};
|
||||
},
|
||||
line(id) {
|
||||
return primitive(id) && { primitive: primitive(id) };
|
||||
},
|
||||
click(target) {
|
||||
native =
|
||||
target?.ground !== undefined
|
||||
? { id: { gevGroundSet: target.ground, instance: target.instance } }
|
||||
: target?.mover !== undefined
|
||||
? { primitive: primitive(target.mover).get(target.instance) }
|
||||
: target?.line !== undefined
|
||||
? { primitive: primitive(target.line) }
|
||||
: target;
|
||||
for (const handler of handlers.handlers)
|
||||
handler.fire(Cesium.ScreenSpaceEventType.LEFT_CLICK, {
|
||||
position: new Cesium.Cartesian2(100, 100),
|
||||
});
|
||||
native = undefined;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const HARNESSES = [fakeHarness, cesiumHarness];
|
||||
|
||||
const PATHS = `${CABLE_OVERLAY_SOURCE_ID}-paths`;
|
||||
const MARKERS = `${CABLE_OVERLAY_SOURCE_ID}-markers`;
|
||||
const CABLE_TIPS = `${CABLE_OVERLAY_SOURCE_ID}-cable-tips`;
|
||||
const LANDING_TIPS = `${CABLE_OVERLAY_SOURCE_ID}-landing-point-tips`;
|
||||
const rgba = (css, alpha) => [...rgbaFromCss(css).rgba().slice(0, 3), alpha];
|
||||
const near = (actual, expected, label) =>
|
||||
actual.forEach((value, index) =>
|
||||
assert.ok(
|
||||
Math.abs(value - expected[index]) < 1e-6,
|
||||
`${label}: ${actual} vs ${expected}`,
|
||||
),
|
||||
);
|
||||
|
||||
const alpha = {
|
||||
type: 'Feature',
|
||||
properties: {
|
||||
id: 'alpha',
|
||||
name: 'Alpha cable',
|
||||
color: '#ff0000',
|
||||
coordinates: [-40, 35],
|
||||
},
|
||||
geometry: {
|
||||
type: 'MultiLineString',
|
||||
coordinates: [
|
||||
[
|
||||
[-40, 35],
|
||||
[-39, 36],
|
||||
],
|
||||
[
|
||||
[-38, 37],
|
||||
[-37, 38],
|
||||
],
|
||||
],
|
||||
},
|
||||
};
|
||||
// No colour of its own and no reference coordinates: the base colour and a
|
||||
// reference averaged from its path.
|
||||
const beta = {
|
||||
type: 'Feature',
|
||||
properties: { id: 'beta', name: 'Beta cable' },
|
||||
geometry: {
|
||||
type: 'LineString',
|
||||
coordinates: [
|
||||
[140, -35],
|
||||
[141, -34],
|
||||
],
|
||||
},
|
||||
};
|
||||
const lisbon = {
|
||||
type: 'Feature',
|
||||
properties: { id: 'lisbon', name: 'Lisbon, Portugal', is_tbd: false },
|
||||
geometry: { type: 'Point', coordinates: [-9.1, 38.7] },
|
||||
};
|
||||
const dataset = (cables = [alpha, beta], landings = [lisbon]) => ({
|
||||
cables: { type: 'FeatureCollection', features: cables },
|
||||
landingPoints: { type: 'FeatureCollection', features: landings },
|
||||
});
|
||||
|
||||
function stackTarget() {
|
||||
const listeners = new Map();
|
||||
return {
|
||||
listeners,
|
||||
addEventListener: (name, fn) => listeners.set(name, fn),
|
||||
removeEventListener: (name, fn) => {
|
||||
if (listeners.get(name) === fn) listeners.delete(name);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function fixture(t, makeHarness, options = {}) {
|
||||
const harness = makeHarness();
|
||||
const hostCalls = [];
|
||||
let clock = 0;
|
||||
const display = createCablesDisplay(harness.engine, {
|
||||
overlayHost: {
|
||||
setVisible: (...args) => hostCalls.push(['visible', ...args]),
|
||||
setEntries: (...args) => hostCalls.push(['entries', ...args]),
|
||||
clearSource: (...args) => hostCalls.push(['clear', ...args]),
|
||||
},
|
||||
sweepClock: () => clock,
|
||||
...options,
|
||||
});
|
||||
t.after(() => {
|
||||
display.destroy();
|
||||
harness.engine.destroy();
|
||||
});
|
||||
return {
|
||||
...harness,
|
||||
display,
|
||||
hostCalls,
|
||||
publishes: () => hostCalls.filter(([type]) => type === 'entries'),
|
||||
advance(ms) {
|
||||
clock += ms;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
for (const makeHarness of HARNESSES) {
|
||||
const { name } = makeHarness();
|
||||
|
||||
test(`cable paths draw as one pixel corridor set in their colours, one item per path (${name})`, (t) => {
|
||||
const f = fixture(t, makeHarness);
|
||||
f.display.show(dataset());
|
||||
const set = f.groundSet(PATHS);
|
||||
assert.equal(set.options.kind, 'corridor');
|
||||
assert.equal(set.options.pickable, true);
|
||||
assert.equal(set.options.drape, 'terrain', 'no photoreal tiles: terrain');
|
||||
assert.equal(set.items.length, 3, 'every path of a multipart cable');
|
||||
assert.deepEqual(
|
||||
set.items.map((item) => item.widthPx),
|
||||
[2.5, 2.5, 2.5],
|
||||
);
|
||||
near(set.items[0].color, rgba('#ff0000', 0.92), 'own colour at 0.92');
|
||||
near(set.items[1].color, rgba('#ff0000', 0.92), 'every segment');
|
||||
near(set.items[2].color, rgba(BASE_CABLE_COLOR, 0.92), 'base colour');
|
||||
assert.equal(set.items[0].pickId, set.items[1].pickId);
|
||||
assert.notEqual(set.items[0].pickId, set.items[2].pickId);
|
||||
assert.deepEqual(set.items[0].positions, alpha.geometry.coordinates[0]);
|
||||
if (f.cesium) {
|
||||
const [batch] = f.groundPrimitives(PATHS);
|
||||
assert.ok(batch instanceof Cesium.GroundPolylinePrimitive);
|
||||
assert.equal(batch.geometryInstances.length, 3);
|
||||
assert.equal(batch.geometryInstances[0].geometry.width, 2.5);
|
||||
assert.equal(batch.classificationType, Cesium.ClassificationType.TERRAIN);
|
||||
assert.deepEqual(
|
||||
[...batch.geometryInstances[0].attributes.color.value],
|
||||
[255, 0, 0, Math.round(0.92 * 255)],
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test(`the paths drape on the active map stack's surface and follow its changes (${name})`, (t) => {
|
||||
const target = stackTarget();
|
||||
const f = fixture(t, makeHarness, { mapStackEventTarget: target });
|
||||
f.display.show(dataset());
|
||||
const listener = target.listeners.get('gev:map-stack-changed');
|
||||
assert.equal(typeof listener, 'function');
|
||||
listener({ detail: { activeId: 'photoreal', status: 'ready' } });
|
||||
assert.equal(f.groundSet(PATHS).options.drape, 'tiles');
|
||||
assert.equal(f.groundSet(PATHS).items.length, 3, 'rebuilt whole');
|
||||
if (f.cesium)
|
||||
assert.equal(
|
||||
f.groundPrimitives(PATHS)[0].classificationType,
|
||||
Cesium.ClassificationType.CESIUM_3D_TILE,
|
||||
);
|
||||
listener({ detail: { activeId: 'osm', status: 'ready' } });
|
||||
assert.equal(f.groundSet(PATHS).options.drape, 'terrain');
|
||||
listener({ detail: { activeId: 'some-future-stack' } });
|
||||
assert.equal(f.groundSet(PATHS).options.drape, 'both');
|
||||
assert.equal(
|
||||
f.engine.ground.list().length,
|
||||
1,
|
||||
'one set at a time: the old one goes',
|
||||
);
|
||||
f.display.hide();
|
||||
listener({ detail: { activeId: 'photoreal' } });
|
||||
assert.equal(f.display.drape(), 'tiles', 'kept for the next show');
|
||||
f.display.show(dataset());
|
||||
assert.equal(f.groundSet(PATHS).options.drape, 'tiles');
|
||||
f.display.destroy();
|
||||
assert.equal(
|
||||
target.listeners.has('gev:map-stack-changed'),
|
||||
false,
|
||||
'destroy detaches the stack listener',
|
||||
);
|
||||
});
|
||||
|
||||
test(`landing points are small ground markers, horizon-culled on the sweep (${name})`, (t) => {
|
||||
const f = fixture(t, makeHarness);
|
||||
f.display.show(dataset());
|
||||
const marker = f.point(MARKERS, 0);
|
||||
assert.equal(marker.sizePx, 4, "the 6 px GeoJSON pin's width");
|
||||
assert.equal(marker.outlinePx, 0);
|
||||
near(marker.color, rgba(BASE_LANDING_COLOR, 1), 'the marker colour');
|
||||
assert.equal(marker.shown, true);
|
||||
assert.equal(marker.id, `landing-point-reference-2-lisbon`);
|
||||
// The far side of the planet from Lisbon.
|
||||
f.look(170.9, -38.7, 4_500_000);
|
||||
f.preRender();
|
||||
assert.equal(f.point(MARKERS, 0).shown, false);
|
||||
f.look(-9.1, 38.7, 4_500_000);
|
||||
f.moveEnd();
|
||||
f.preRender();
|
||||
assert.equal(f.point(MARKERS, 0).shown, true);
|
||||
});
|
||||
|
||||
test(`the sweep shows visible tips, publishes their labels once and stems the winners (${name})`, (t) => {
|
||||
const f = fixture(t, makeHarness);
|
||||
f.look(-40, 35, 4_500_000);
|
||||
f.display.show(dataset());
|
||||
assert.equal(f.point(CABLE_TIPS, 0).shown, false, 'hidden until a sweep');
|
||||
f.preRender();
|
||||
const alphaTip = f.point(CABLE_TIPS, 0);
|
||||
assert.equal(alphaTip.shown, true);
|
||||
assert.equal(alphaTip.sizePx, 7);
|
||||
assert.equal(alphaTip.outlinePx, 1);
|
||||
near(alphaTip.color, rgba(BASE_CABLE_COLOR, 0.84), 'cable tip');
|
||||
assert.equal(alphaTip.id, 'cable-reference-0-alpha');
|
||||
assert.equal(f.point(CABLE_TIPS, 1).shown, false, 'beyond the horizon');
|
||||
const landingTip = f.point(LANDING_TIPS, 0);
|
||||
assert.equal(landingTip.sizePx, 8);
|
||||
near(landingTip.color, rgba(BASE_LANDING_COLOR, 0.94), 'landing tip');
|
||||
if (f.cesium) {
|
||||
assert.equal(alphaTip.native.disableDepthTestDistance, 0, 'depth-tested');
|
||||
near(
|
||||
[
|
||||
alphaTip.outlineColor.red,
|
||||
alphaTip.outlineColor.green,
|
||||
alphaTip.outlineColor.blue,
|
||||
alphaTip.outlineColor.alpha,
|
||||
],
|
||||
[0, 0, 0, 0.65],
|
||||
'tip outline',
|
||||
);
|
||||
}
|
||||
const tipHeight = geo.cartographic.fromCartesian(alphaTip.position).height;
|
||||
assert.ok(tipHeight >= 700 && tipHeight <= 85_000, `tip ${tipHeight} m`);
|
||||
|
||||
const [publish] = f.publishes();
|
||||
assert.equal(f.publishes().length, 1);
|
||||
const [, sourceId, entries, options] = publish;
|
||||
assert.equal(sourceId, CABLE_OVERLAY_SOURCE_ID);
|
||||
assert.deepEqual(
|
||||
entries.map((entry) => entry.title),
|
||||
['Alpha cable', 'Lisbon, Portugal'],
|
||||
'the visible references, nearest first',
|
||||
);
|
||||
assert.ok(
|
||||
geo.cartesian3.equalsEpsilon(
|
||||
entries[0].position,
|
||||
alphaTip.position,
|
||||
0,
|
||||
1e-3,
|
||||
),
|
||||
'the label sits at the tip',
|
||||
);
|
||||
assert.deepEqual(options, {
|
||||
cohortLimit: CABLE_REFERENCE_LABEL_WINNER_CAP,
|
||||
collisionCapacity: CABLE_OVERLAY_COLLISION_CAPACITY,
|
||||
moving: false,
|
||||
});
|
||||
assert.equal(f.display.stats().referenceLabelCount, 2);
|
||||
|
||||
const stems = f.lineIds();
|
||||
assert.deepEqual(stems, [
|
||||
`${CABLE_OVERLAY_SOURCE_ID}-stem-cable-reference-0-alpha`,
|
||||
`${CABLE_OVERLAY_SOURCE_ID}-stem-landing-point-reference-2-lisbon`,
|
||||
]);
|
||||
assert.ok(
|
||||
stems.every((id) => f.line(id)),
|
||||
'each stem is drawn',
|
||||
);
|
||||
if (!f.cesium) {
|
||||
const cableStem = f.engine.fake.line(stems[0]);
|
||||
assert.equal(cableStem.options.widthPx, 2);
|
||||
near(cableStem.color, rgba(BASE_CABLE_COLOR, 0.58), 'cable stem');
|
||||
assert.equal(cableStem.positions.length, 6, 'base and tip');
|
||||
const landingStem = f.engine.fake.line(stems[1]);
|
||||
assert.equal(landingStem.options.widthPx, 2.4);
|
||||
near(landingStem.color, rgba(BASE_LANDING_COLOR, 0.68), 'landing stem');
|
||||
}
|
||||
|
||||
// A moveEnd at an unchanged camera re-runs the sweep; the identical
|
||||
// cohort is not published again.
|
||||
f.moveEnd();
|
||||
f.preRender();
|
||||
f.preRender();
|
||||
assert.equal(f.publishes().length, 1, 'identical cohorts are skipped');
|
||||
// A move past the 50 km priority quantum publishes.
|
||||
f.look(-40, 35, 6_500_000);
|
||||
f.moveEnd();
|
||||
f.preRender();
|
||||
assert.equal(f.publishes().length, 2, 'a changed cohort publishes');
|
||||
});
|
||||
|
||||
test(`stems re-size only on moveEnd or the motion probe, never mid-drag (${name})`, (t) => {
|
||||
const f = fixture(t, makeHarness);
|
||||
f.look(-35, 37.5, 400_000);
|
||||
f.display.show(dataset());
|
||||
f.preRender();
|
||||
const stem = `${CABLE_OVERLAY_SOURCE_ID}-stem-cable-reference-0-alpha`;
|
||||
assert.equal(f.positionsSet(stem), 1);
|
||||
// A drag: the camera moves every frame, no moveEnd, the probe window
|
||||
// stays closed.
|
||||
for (let tick = 0; tick < 30; tick++) {
|
||||
f.look(-35, 37.5, 400_000 + 2_000 * (tick + 1));
|
||||
f.advance(10);
|
||||
f.preRender();
|
||||
}
|
||||
assert.equal(f.positionsSet(stem), 1, 'no re-size mid-drag');
|
||||
f.moveEnd();
|
||||
f.preRender();
|
||||
assert.equal(f.positionsSet(stem), 2, 'moveEnd re-sizes once');
|
||||
f.preRender();
|
||||
assert.equal(f.positionsSet(stem), 2, 'the next frame does not');
|
||||
// A follow camera never raises moveEnd: past the probe window, moved
|
||||
// past the motion epsilon, one sweep.
|
||||
f.look(-35, 37.5, 300_000);
|
||||
f.advance(CABLE_SWEEP_MOTION_PROBE_INTERVAL_MS + 1);
|
||||
f.preRender();
|
||||
assert.equal(f.positionsSet(stem), 3, 'the motion fallback sweeps');
|
||||
f.advance(CABLE_SWEEP_MOTION_PROBE_INTERVAL_MS + 1);
|
||||
f.preRender();
|
||||
assert.equal(f.positionsSet(stem), 3, 'a parked camera never sweeps');
|
||||
});
|
||||
|
||||
test(`a click on a path, marker, tip or stem flies to its reference (${name})`, (t) => {
|
||||
const f = fixture(t, makeHarness);
|
||||
f.look(-40, 35, 4_500_000);
|
||||
f.display.show(dataset());
|
||||
f.preRender();
|
||||
const stem = `${CABLE_OVERLAY_SOURCE_ID}-stem-landing-point-reference-2-lisbon`;
|
||||
for (const target of [
|
||||
{ ground: PATHS, instance: 1 },
|
||||
{ mover: MARKERS, instance: 0 },
|
||||
{ mover: CABLE_TIPS, instance: 0 },
|
||||
{ line: stem },
|
||||
])
|
||||
f.click(target);
|
||||
assert.equal(f.flights.length, 4);
|
||||
const [path, marker, tip, stemFlight] = f.flights;
|
||||
const at = (flight) => {
|
||||
const place = geo.cartographic.fromCartesian(flight.destination);
|
||||
return [
|
||||
geo.math.toDegrees(place.longitude),
|
||||
geo.math.toDegrees(place.latitude),
|
||||
place.height,
|
||||
];
|
||||
};
|
||||
near(at(path), [-40, 35, 6500], 'the cable reference');
|
||||
near(at(marker), [-9.1, 38.7, 6500], 'the landing point');
|
||||
near(at(tip), [-40, 35, 6500], 'the tip');
|
||||
near(at(stemFlight), [-9.1, 38.7, 6500], 'the stem');
|
||||
assert.equal(path.duration, 1.35);
|
||||
assert.equal(path.easing, 'cubicInOut');
|
||||
assert.ok(
|
||||
Math.abs(path.orientation.pitch - geo.math.toRadians(-52)) < 1e-12,
|
||||
);
|
||||
assert.equal(path.orientation.roll, 0);
|
||||
assert.ok(
|
||||
Math.abs(path.orientation.heading - f.engine.camera.pose().heading) <
|
||||
1e-9,
|
||||
'keeps the heading',
|
||||
);
|
||||
|
||||
// A tool owns the pointer: the click is the tool's.
|
||||
const lease = claimPointer('draw');
|
||||
try {
|
||||
f.click({ ground: PATHS, instance: 0 });
|
||||
} finally {
|
||||
releasePointer(lease);
|
||||
}
|
||||
// Nothing, the map, or another layer's object.
|
||||
f.click(undefined);
|
||||
f.click({ id: 'cable-reference-0-alpha', owner: 'someone-else' });
|
||||
assert.equal(f.flights.length, 4);
|
||||
f.display.hide();
|
||||
if (!f.cesium) {
|
||||
f.engine.fake.script('pick', {
|
||||
id: 'cable-reference-0-alpha',
|
||||
owner: PATHS,
|
||||
});
|
||||
f.engine.fake.input('click', { position: { x: 1, y: 1 } });
|
||||
f.engine.fake.unscript('pick');
|
||||
assert.equal(f.flights.length, 4, 'a hidden display takes no clicks');
|
||||
}
|
||||
});
|
||||
|
||||
test(`hide clears what the display drew and its labels; show draws it again (${name})`, (t) => {
|
||||
const f = fixture(t, makeHarness);
|
||||
f.look(-40, 35, 4_500_000);
|
||||
f.display.show(dataset());
|
||||
f.preRender();
|
||||
assert.equal(f.engine.ground.list().length, 1);
|
||||
assert.equal(f.engine.movers.list().length, 3);
|
||||
assert.equal(f.engine.lines.list().length, 2);
|
||||
f.hostCalls.length = 0;
|
||||
f.display.hide();
|
||||
assert.deepEqual(f.hostCalls, [
|
||||
['clear', CABLE_OVERLAY_SOURCE_ID],
|
||||
['visible', CABLE_OVERLAY_SOURCE_ID, false],
|
||||
]);
|
||||
assert.equal(f.engine.ground.list().length, 0);
|
||||
assert.equal(f.engine.movers.list().length, 0);
|
||||
assert.equal(f.engine.lines.list().length, 0);
|
||||
assert.equal(f.display.stats().referenceLabelCount, 0);
|
||||
f.preRender();
|
||||
assert.equal(f.publishes().length, 0, 'no sweep while hidden');
|
||||
// An identical cohort publishes again after the hide cleared the host.
|
||||
const same = dataset();
|
||||
f.display.show(same);
|
||||
f.preRender();
|
||||
assert.equal(f.publishes().length, 1);
|
||||
f.display.show(same);
|
||||
assert.equal(f.engine.ground.list().length, 1, 'the same dataset stays');
|
||||
f.display.destroy();
|
||||
assert.equal(f.engine.ground.list().length, 0);
|
||||
assert.equal(f.engine.movers.list().length, 0);
|
||||
f.display.show(same);
|
||||
assert.equal(f.engine.ground.list().length, 0, 'destroyed: draws nothing');
|
||||
});
|
||||
}
|
||||
|
||||
test('every bundled cable path draws with its own feature, one reference per feature', (t) => {
|
||||
const read = (file) =>
|
||||
JSON.parse(
|
||||
readFileSync(
|
||||
new URL(
|
||||
`../../../data/local_data/telegeography_submarine_cables/${file}`,
|
||||
import.meta.url,
|
||||
),
|
||||
'utf8',
|
||||
),
|
||||
);
|
||||
const cables = read('cable-geo.json');
|
||||
const landings = read('landing-point-geo.json');
|
||||
const [makeFake] = HARNESSES;
|
||||
const f = fixture(t, makeFake);
|
||||
f.display.show({ cables, landingPoints: landings });
|
||||
const items = f.groundSet(PATHS).items;
|
||||
const expanded = cables.features.flatMap((feature) =>
|
||||
feature.geometry.coordinates.map(() => feature),
|
||||
);
|
||||
assert.equal(items.length, expanded.length);
|
||||
const ids = new Map();
|
||||
items.forEach((item, index) => {
|
||||
const feature = expanded[index];
|
||||
near(item.color, rgba(feature.properties.color, 0.92), feature.id);
|
||||
const owner = ids.get(item.pickId);
|
||||
if (owner) assert.equal(owner, feature, 'one reference per feature');
|
||||
ids.set(item.pickId, feature);
|
||||
});
|
||||
assert.equal(ids.size, cables.features.length);
|
||||
assert.equal(
|
||||
f.engine.movers.list().find(({ id }) => id === CABLE_TIPS).count,
|
||||
cables.features.length,
|
||||
);
|
||||
assert.equal(
|
||||
f.engine.movers.list().find(({ id }) => id === MARKERS).count,
|
||||
landings.features.length,
|
||||
);
|
||||
});
|
||||
|
||||
test('the display draws on the contract only', () => {
|
||||
const source = readFileSync(new URL('./display.js', import.meta.url), 'utf8');
|
||||
assert.doesNotMatch(source, /from 'cesium'|from 'three'|@navaramap/);
|
||||
assert.doesNotMatch(source, /engine\.kind|extensions|defineGroundEffect/);
|
||||
assert.doesNotMatch(source, /ScreenSpaceEventHandler/);
|
||||
});
|
||||
|
||||
const FIJI = [178.44, -18.12];
|
||||
// Cable A leaves Fiji eastwards across the antimeridian as ONE unsplit path
|
||||
// and has no reference coordinates, so its reference comes from its geometry.
|
||||
const cableA = {
|
||||
type: 'Feature',
|
||||
properties: { id: 'cable-a', name: 'Cable A' },
|
||||
geometry: {
|
||||
type: 'LineString',
|
||||
coordinates: [FIJI, [-170, -10]],
|
||||
},
|
||||
};
|
||||
// Cable B ends at the same landing point and runs south-west.
|
||||
const cableB = {
|
||||
type: 'Feature',
|
||||
properties: { id: 'cable-b', name: 'Cable B', coordinates: [174, -24] },
|
||||
geometry: {
|
||||
type: 'LineString',
|
||||
coordinates: [FIJI, [170, -30]],
|
||||
},
|
||||
};
|
||||
const landing = {
|
||||
type: 'Feature',
|
||||
properties: { id: 'suva', name: 'Suva' },
|
||||
geometry: { type: 'Point', coordinates: FIJI },
|
||||
};
|
||||
|
||||
function fijiFixture(t) {
|
||||
const harness = fakeHarness();
|
||||
const { engine } = harness;
|
||||
engine.fake.setPose({
|
||||
longitude: geo.math.toRadians(FIJI[0]),
|
||||
latitude: geo.math.toRadians(FIJI[1]),
|
||||
height: 400000,
|
||||
});
|
||||
const host = { setVisible() {}, setEntries() {}, clearSource() {} };
|
||||
const cables = createCablesDisplay(engine, { overlayHost: host });
|
||||
cables.show({
|
||||
cables: { type: 'FeatureCollection', features: [cableA, cableB] },
|
||||
landingPoints: { type: 'FeatureCollection', features: [landing] },
|
||||
});
|
||||
harness.preRender();
|
||||
t.after(() => {
|
||||
cables.destroy();
|
||||
engine.destroy();
|
||||
});
|
||||
return harness;
|
||||
}
|
||||
|
||||
const fijiScreen = (engine, [lon, lat]) =>
|
||||
engine.projector.worldToWindow(geo.cartesian3.fromDegrees(lon, lat), {});
|
||||
|
||||
test('edge:telegeography-submarine-cables: an antimeridian crossing draws no segment across the whole map', (t) => {
|
||||
const { engine, groundSet } = fijiFixture(t);
|
||||
// The path keeps its own two points: the ground set follows the short
|
||||
// great circle across 180°, as Cesium's ground polylines do.
|
||||
const [first] = groundSet(PATHS).items;
|
||||
assert.deepEqual(first.positions, cableA.geometry.coordinates);
|
||||
// Picks find it along the short way and nowhere on the long way round.
|
||||
const edgeLat = -18.12 + ((180 - 178.44) / (190 - 178.44)) * (-10 + 18.12);
|
||||
const beyond = fijiScreen(engine, [180.5, edgeLat + 0.35]);
|
||||
assert.equal(engine.picker.pick(beyond)?.id, 'cable-reference-0-cable-a');
|
||||
for (const lon of [170, 160, 150])
|
||||
assert.notEqual(
|
||||
engine.picker.pick(fijiScreen(engine, [lon, -14]))?.owner,
|
||||
PATHS,
|
||||
`no cable at ${lon}°`,
|
||||
);
|
||||
});
|
||||
|
||||
test('edge:telegeography-submarine-cables: a click on a cable beside its landing point returns that cable and flies to its own reference', (t) => {
|
||||
const { engine, flights } = fijiFixture(t);
|
||||
const edgeLat = -18.12 + ((180 - 178.44) / (190 - 178.44)) * (-10 + 18.12);
|
||||
const from = fijiScreen(engine, FIJI);
|
||||
const to = fijiScreen(engine, [180, edgeLat]);
|
||||
// Halfway along cable A's first stretch, well clear of the landing point.
|
||||
const at = { x: (from.x + to.x) / 2, y: (from.y + to.y) / 2 };
|
||||
assert.ok(Math.hypot(at.x - from.x, at.y - from.y) > 20);
|
||||
const picked = engine.picker.pick(at);
|
||||
assert.equal(picked?.id, 'cable-reference-0-cable-a');
|
||||
// The landing point itself still answers as the landing point.
|
||||
assert.equal(engine.picker.pick(from)?.id, 'landing-point-reference-2-suva');
|
||||
engine.fake.input('click', { position: at });
|
||||
const [flight] = flights;
|
||||
assert.ok(flight, 'the click flies to the cable');
|
||||
const target = geo.cartographic.fromCartesian(flight.destination);
|
||||
// The reference of a cable across the antimeridian stays beside it, not at 0°.
|
||||
assert.ok(
|
||||
Math.abs(geo.math.toDegrees(target.longitude)) > 170,
|
||||
`reference at ${geo.math.toDegrees(target.longitude)}°`,
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user