mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
Merge origin/main into the renderer-contract branch: the procedural fleet models drawn through the renderer's model sets
Aircraft, military, local ADS-B, vessel, transit and rail models come from the fleet model set, loaded up front and drawn life size through the draw port's models sets; no layer touches the viewer or Cesium outside src/render/cesium/. The models capability gains glTF bytes (gltf), a per-axis stretch (axisScale), a colour for tinted parts (maskColor) and a cut below the origin (clip: 'belowOrigin'), with conformance checks. Main's rail layer and Data Library are ported to the ports; the CCTV footprint probe keeps the globe-terrain clamp through the query port.
This commit is contained in:
commit
e3865f462f
533 files changed
+55738
-2518
No files matched your search
@@ -0,0 +1,269 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { createLibraryViewLayer } from './layers.js';
|
||||
import { libraryEntry } from './catalog.js';
|
||||
import { fromDegrees } from '../geo/ellipsoid.js';
|
||||
import { bindFakeDraw } from '../testSupport/fakeDrawPort.mjs';
|
||||
import { fakeCameraPort } from '../testSupport/fakeCameraPort.mjs';
|
||||
|
||||
const entry = libraryEntry('fema-usa-structures');
|
||||
|
||||
/**
|
||||
* A viewer whose renderer has a camera at `height` over (lon, lat), a query
|
||||
* port picking that point on the ellipsoid, and a draw port.
|
||||
*/
|
||||
function fakeViewer(t, { height, lon = -77.03, lat = 38.89 }) {
|
||||
const viewer = { canvas: { clientWidth: 800, clientHeight: 600 } };
|
||||
const camera = fakeCameraPort();
|
||||
let centre = null;
|
||||
const moveTo = (nextLon, nextLat) => {
|
||||
centre = fromDegrees(nextLon, nextLat, 0);
|
||||
camera.setPose({
|
||||
lon: nextLon,
|
||||
lat: nextLat,
|
||||
height,
|
||||
position: fromDegrees(nextLon, nextLat, height),
|
||||
});
|
||||
camera.setViewRectangle({
|
||||
west: nextLon - 1,
|
||||
south: nextLat - 1,
|
||||
east: nextLon + 1,
|
||||
north: nextLat + 1,
|
||||
});
|
||||
};
|
||||
moveTo(lon, lat);
|
||||
const { draw, unbind } = bindFakeDraw(viewer, {
|
||||
camera: camera.port,
|
||||
query: { pickEllipsoid: () => centre },
|
||||
});
|
||||
t.after(unbind);
|
||||
/** The view's fill sets in the scene. */
|
||||
const drawn = () =>
|
||||
[...draw.sets.values()].filter(
|
||||
(set) => !set.disposed && set.spec.id.endsWith(':fills'),
|
||||
);
|
||||
return { viewer, camera, draw, drawn, moveTo };
|
||||
}
|
||||
|
||||
const polygon = {
|
||||
type: 'Feature',
|
||||
geometry: {
|
||||
type: 'Polygon',
|
||||
coordinates: [
|
||||
[
|
||||
[-77.03, 38.89],
|
||||
[-77.029, 38.89],
|
||||
[-77.029, 38.891],
|
||||
[-77.03, 38.89],
|
||||
],
|
||||
],
|
||||
},
|
||||
properties: { OCC_CLS: 'Government' },
|
||||
};
|
||||
|
||||
test('above its altitude a view-bounded layer loads nothing and asks to zoom in', async (t) => {
|
||||
const calls = [];
|
||||
const layer = createLibraryViewLayer(entry, {
|
||||
source: { loadDataset: async (...args) => calls.push(args) },
|
||||
});
|
||||
const { viewer, camera } = fakeViewer(t, { height: 900_000 });
|
||||
await layer.init(viewer);
|
||||
await layer.enable(viewer);
|
||||
assert.equal(calls.length, 0);
|
||||
assert.equal(camera.listenerCount('moveEnd'), 1);
|
||||
assert.deepEqual(layer.getStats(), {
|
||||
count: 0,
|
||||
lastUpdate: null,
|
||||
status: 'zoom-in',
|
||||
statusMessage: 'zoom in to load this layer',
|
||||
});
|
||||
await layer.disable(viewer);
|
||||
assert.equal(camera.listenerCount('moveEnd'), 0);
|
||||
});
|
||||
|
||||
test('below it, the layer loads the box around the view centre and reads PARTIAL when capped', async (t) => {
|
||||
const calls = [];
|
||||
const layer = createLibraryViewLayer(entry, {
|
||||
source: {
|
||||
loadDataset: async (target, options) => {
|
||||
calls.push(options.bbox);
|
||||
return { features: [polygon, polygon], truncated: true };
|
||||
},
|
||||
},
|
||||
});
|
||||
const { viewer, drawn } = fakeViewer(t, { height: 2000 });
|
||||
await layer.init(viewer);
|
||||
await layer.enable(viewer);
|
||||
assert.equal(calls.length, 1);
|
||||
const [west, south, east, north] = calls[0];
|
||||
// A window around the centre sized by height (±1 km here), not the
|
||||
// ±1° visible rectangle.
|
||||
assert.ok(north - south < 0.05 && north - south > 0.005, String(calls[0]));
|
||||
assert.ok(west < -77.03 && east > -77.03 && south < 38.89 && north > 38.89);
|
||||
assert.equal(drawn().length, 1);
|
||||
const [fill] = drawn()[0].items.values();
|
||||
// On the ground and the 3D tiles, with no outline.
|
||||
assert.equal(fill.height, 'clampGround');
|
||||
assert.equal(fill.clampTo, 'both');
|
||||
assert.equal(fill.outline, undefined);
|
||||
assert.equal(drawn()[0].show, true);
|
||||
const stats = layer.getStats();
|
||||
assert.equal(stats.count, 2);
|
||||
assert.equal(stats.partial, true);
|
||||
// The same view does not refetch.
|
||||
await layer.enable(viewer);
|
||||
assert.equal(calls.length, 1);
|
||||
assert.deepEqual(layer.getExtent(), {
|
||||
west: -77.04,
|
||||
south: 38.885,
|
||||
east: -77.02,
|
||||
north: 38.9,
|
||||
maxAltitudeM: 4000,
|
||||
});
|
||||
await layer.destroy(viewer);
|
||||
assert.equal(drawn().length, 0);
|
||||
});
|
||||
|
||||
test('returning to the drawn view cancels the request for the view in between', async (t) => {
|
||||
let release;
|
||||
const signals = [];
|
||||
let call = 0;
|
||||
const layer = createLibraryViewLayer(entry, {
|
||||
source: {
|
||||
loadDataset: async (target, { signal }) => {
|
||||
signals.push(signal);
|
||||
call += 1;
|
||||
if (call === 2)
|
||||
await new Promise((resolve) => {
|
||||
release = resolve;
|
||||
});
|
||||
return { features: [polygon], truncated: false };
|
||||
},
|
||||
},
|
||||
});
|
||||
const { viewer, drawn, moveTo } = fakeViewer(t, { height: 2000 });
|
||||
await layer.init(viewer);
|
||||
await layer.enable(viewer);
|
||||
const [first] = drawn();
|
||||
moveTo(-77.2, 38.95);
|
||||
const between = layer.enable(viewer);
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
moveTo(-77.03, 38.89);
|
||||
await layer.enable(viewer);
|
||||
assert.equal(signals[1].aborted, true);
|
||||
release();
|
||||
await between;
|
||||
assert.deepEqual(drawn(), [first]);
|
||||
assert.equal(layer.getStats().loading, false);
|
||||
await layer.destroy(viewer);
|
||||
});
|
||||
|
||||
test('returning to the drawn view clears an error from the view in between', async (t) => {
|
||||
let call = 0;
|
||||
const layer = createLibraryViewLayer(entry, {
|
||||
source: {
|
||||
loadDataset: async () => {
|
||||
call += 1;
|
||||
if (call === 2) throw new Error('HTTP 503');
|
||||
return { features: [polygon], truncated: false };
|
||||
},
|
||||
},
|
||||
debounceMs: 0,
|
||||
});
|
||||
const env = fakeViewer(t, { height: 2000 });
|
||||
const { viewer } = env;
|
||||
const moveTo = async (lon, lat) => {
|
||||
env.moveTo(lon, lat);
|
||||
// The camera settles: the layer's moveEnd listener schedules a load.
|
||||
env.camera.emit('moveEnd');
|
||||
await new Promise((resolve) => setTimeout(resolve, 5));
|
||||
};
|
||||
await layer.init(viewer);
|
||||
await layer.enable(viewer);
|
||||
await moveTo(-77.2, 38.95);
|
||||
assert.ok(layer.getStats().error);
|
||||
await moveTo(-77.03, 38.89);
|
||||
assert.equal(layer.getStats().error, null);
|
||||
assert.equal(layer.getStats().count, 1);
|
||||
await layer.destroy(viewer);
|
||||
});
|
||||
|
||||
test('the row legend labels each colour and counts what is in view', async (t) => {
|
||||
const { colorByLegend } = await import('./layers.js');
|
||||
const bridges = libraryEntry('ntad-national-bridges');
|
||||
assert.deepEqual(colorByLegend(bridges.display), [
|
||||
{ label: 'Good', color: '#0ca30c' },
|
||||
{ label: 'Fair', color: '#fab219' },
|
||||
{ label: 'Poor', color: '#d03b3b' },
|
||||
]);
|
||||
assert.deepEqual(
|
||||
colorByLegend(bridges.display, new Map([['P', 2]])).map(
|
||||
({ count }) => count,
|
||||
),
|
||||
[0, 0, 2],
|
||||
);
|
||||
// A tile layer's static scale.
|
||||
assert.equal(
|
||||
colorByLegend(libraryEntry('gbif-occurrence-density').display).length,
|
||||
6,
|
||||
);
|
||||
assert.deepEqual(
|
||||
colorByLegend(libraryEntry('nasa-black-marble').display),
|
||||
[],
|
||||
);
|
||||
// A loaded view layer counts by value.
|
||||
const layer = createLibraryViewLayer(bridges, {
|
||||
source: {
|
||||
loadDataset: async () => ({
|
||||
features: [
|
||||
{ ...polygon, properties: { __gevColorKey: 'G' } },
|
||||
{ ...polygon, properties: { __gevColorKey: 'G' } },
|
||||
{ ...polygon, properties: { __gevColorKey: 'P' } },
|
||||
],
|
||||
truncated: false,
|
||||
}),
|
||||
},
|
||||
});
|
||||
const { viewer, drawn } = fakeViewer(t, { height: 3000 });
|
||||
await layer.init(viewer);
|
||||
await layer.enable(viewer);
|
||||
// Each polygon fills in its value's colour.
|
||||
const fills = [...drawn()[0].items.values()].map((item) =>
|
||||
item.fill.map((channel) => Math.round(channel * 255)),
|
||||
);
|
||||
assert.deepEqual(fills[0], [12, 163, 12, 115]);
|
||||
assert.deepEqual(fills[2], [208, 59, 59, 115]);
|
||||
assert.deepEqual(
|
||||
layer.getRowControls().legend.map(({ label, count }) => [label, count]),
|
||||
[
|
||||
['Good', 2],
|
||||
['Fair', 0],
|
||||
['Poor', 1],
|
||||
],
|
||||
);
|
||||
await layer.destroy(viewer);
|
||||
});
|
||||
|
||||
test('values sharing a label are one legend group, and uncoloured values count as Other', async () => {
|
||||
const { colorByLegend } = await import('./layers.js');
|
||||
const legend = colorByLegend(
|
||||
libraryEntry('wri-global-power-plants').display,
|
||||
new Map([
|
||||
['Coal', 3],
|
||||
['Gas', 2],
|
||||
['Wind', 4],
|
||||
['Biomass', 1],
|
||||
]),
|
||||
);
|
||||
assert.deepEqual(
|
||||
legend.map(({ label, count }) => [label, count]),
|
||||
[
|
||||
['Fossil (coal, gas, oil)', 5],
|
||||
['Nuclear', 0],
|
||||
['Hydro', 0],
|
||||
['Wind and solar', 4],
|
||||
['Other', 1],
|
||||
],
|
||||
);
|
||||
assert.equal(legend.at(-1).color, '#a0aec0');
|
||||
});
|
||||
Reference in new issue
Block a user