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,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],
|
||||
),
|
||||
})),
|
||||
);
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user