mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-18 01:02:23 +00:00
- Radio: stations, clusters, the selection and its brackets are point and sprite sets; clusters come from the layer's engine-neutral screen clusterer with Cesium's EntityCluster rules, and clicks go through the selection dispatcher. One style module holds the sizes and colours. - Transit: vehicles are two sprite sets from an up-front atlas, rotated with Cesium's projected-rotation maths. The selected vehicle's trail is engine.lines in two lanes and 29 age bands, so trails are no longer draped over terrain until the contract has ground corridors. The Cesium contact trail renderer and its re-export go. - CCTV: markers, wedges, the plane outline and the calibration gizmo (rings, arrows, handles, drags through engine.input) draw on the contract. The textured monitor plane and the viewshed volume, which no primitive expresses yet, sit behind one seam, render/meshes.js, with a Cesium backend and a Navara backend the Navara mode passes in. Known gaps against Cesium: transit trails are not draped, and the surveillance-lens click correction runs only where the engine reports its style stage (Navara). Coupling: layer renderer lines fall from 2638/8735 to 1636/6953 (Cesium/Navara), ScreenSpaceEventHandler files from 15 to 10, `viewer` lines from 2014 to 1901.
103 lines
6.4 KiB
JavaScript
103 lines
6.4 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import * as C from 'cesium';
|
|
import { showOsmCredit, hideOsmCredit } from './dataCredits.js';
|
|
import { createInfrastructureLayers } from './infrastructure.js';
|
|
import { createBhoteKoshiLocatorLayer } from './bhoteKoshiLocator.js';
|
|
import { createWorldAnnotationRenderer } from '../annotations/worldAnnotationRenderer.js';
|
|
import * as annotations from '../annotations/worldAnnotationRenderer.js';
|
|
import { createDirectionsLayer } from '../layers/directions/index.js';
|
|
import { createDirectionsSource } from '../layers/directions/source.js';
|
|
import { createLifecycle as createCctvLifecycle } from '../layers/cctv/lifecycle.js';
|
|
import { createCctvDisplay } from '../layers/cctv/render/display.js';
|
|
import { createFakeEngine } from '../globe/testing/fakeEngine.js';
|
|
import * as input from './inputOwnership.js';
|
|
import { createOverpassAlprSource } from '../layers/alpr/source.js';
|
|
|
|
const noop = () => {};
|
|
const overlayHost = { setEntries: noop, setVisible: noop, clearSource: noop };
|
|
function viewer(t) {
|
|
t.mock.timers.enable({ apis: ['setTimeout'] });
|
|
for (const name of ['HTMLCanvasElement', 'HTMLImageElement', 'ImageBitmap', 'OffscreenCanvas']) {
|
|
const original = globalThis[name];
|
|
globalThis[name] = class {};
|
|
t.after(() => { if (original === undefined) delete globalThis[name]; else globalThis[name] = original; });
|
|
}
|
|
const before = globalThis.document;
|
|
globalThis.document = { addEventListener: noop, removeEventListener: noop };
|
|
t.after(() => { if (before === undefined) delete globalThis.document; else globalThis.document = before; });
|
|
const credits = [];
|
|
const v = { credits, creditDisplay: { addStaticCredit: (c) => credits.push(c), removeStaticCredit: c => { const i = credits.indexOf(c); if (i >= 0) credits.splice(i, 1); } },
|
|
entities: new C.EntityCollection(), dataSources: new C.DataSourceCollection(),
|
|
camera: { moveEnd: new C.Event(), positionCartographic: { height: 1000 } },
|
|
scene: { requestRender: noop, canvas: { addEventListener: noop, removeEventListener: noop }, preRender: new C.Event(),
|
|
primitives: { add: (p) => p, remove: noop }, screenSpaceCameraController: { enableInputs: true } },
|
|
};
|
|
return v;
|
|
}
|
|
function assertCredit(v) {
|
|
assert.ok(v.credits.some((credit) => credit.showOnScreen && credit.html.includes('>© OpenStreetMap<')));
|
|
}
|
|
for (const index of [0, 1]) test(`${index ? 'dams' : 'datacenters'} introduce the shared OSM credit when data displays`, async (t) => {
|
|
const v = viewer(t);
|
|
t.mock.method(globalThis, 'fetch', async () => ({ ok: true, text: async () => JSON.stringify({ type: 'Feature', id: 'test', properties: { name: 'Site' }, geometry: { type: 'Polygon', coordinates: [[[0, 0], [0.01, 0], [0, 0.01], [0, 0]]] } }) }));
|
|
const layer = createInfrastructureLayers({ overlayHost, registerEntityContext: noop, selectEntityContext: noop, clearSelectedEntityContextForLayer: noop, removeEntityContextsForLayer: noop, governorRequestRender: noop, showOsmCredit, hideOsmCredit })[index];
|
|
await layer.enable(v);
|
|
assert.equal(layer.getStats().count, 1);
|
|
assertCredit(v);
|
|
layer.destroy(v);
|
|
assert.equal(v.credits.filter(c => c.showOnScreen).length, 0);
|
|
});
|
|
|
|
test('Nepal locator introduces the shared OSM credit', async (t) => {
|
|
const v = viewer(t);
|
|
const layer = createBhoteKoshiLocatorLayer({ boundaryResolver: async () => ({ name: 'Nepal', ring: [[80, 26], [88, 26], [88, 30], [80, 30]] }), overlayHost, requestRender: noop, scheduleFrame: () => 1, cancelFrame: noop });
|
|
await layer.init(v); await layer.enable(v, { origin: 'scene' });
|
|
assertCredit(v); await layer.destroy(v);
|
|
assert.equal(v.credits.filter(c => c.showOnScreen).length, 0);
|
|
});
|
|
|
|
test('voice route geometry introduces the shared OSM credit', (t) => {
|
|
const v = viewer(t), renderer = createWorldAnnotationRenderer(v);
|
|
renderer.add({ id: 'route', type: 'route', color: 'primary', anchor: { lat: 0, lon: 0 }, path: [{ lat: 0, lon: 0 }, { lat: 0.01, lon: 0.01 }] });
|
|
assertCredit(v); renderer.destroy();
|
|
assert.equal(v.credits.filter(c => c.showOnScreen).length, 0);
|
|
});
|
|
|
|
test('Directions introduces the shared OSM credit when the requested route draws', async (t) => {
|
|
const v = viewer(t);
|
|
t.mock.method(globalThis, 'fetch', async () => Response.json({ ok: true, geometry: [[0, 0], [0.01, 0.01]], steps: [] }));
|
|
const layer = createDirectionsLayer({ source: createDirectionsSource(), services: {
|
|
credits: { showOsmCredit, hideOsmCredit }, annotations, input, scenePick: {}, camera: {},
|
|
overlays: { setOverlayEntries: noop, setOverlaySourceVisible: noop, clearOverlaySource: noop },
|
|
render: { governorRequestRender: noop, holdContinuousRender: noop, releaseContinuousRender: noop },
|
|
sprites: { registerSpriteCollection: noop, unregisterSpriteCollection: noop, restoreSpriteOrder: noop },
|
|
picking: { registerPickOwner: noop, unregisterPickOwner: noop },
|
|
ground: { warmGroundFloor: noop },
|
|
} });
|
|
layer.init(v); layer.enable(v);
|
|
layer.placeEndpoint('a', { lat: 0, lon: 0 }); layer.placeEndpoint('b', { lat: 0.01, lon: 0.01 });
|
|
for (let i = 0; i < 30; i++) await Promise.resolve();
|
|
assert.equal(layer.getStats().error, null);
|
|
assertCredit(v); await layer.destroy(v);
|
|
assert.equal(v.credits.filter(c => c.showOnScreen).length, 0);
|
|
});
|
|
|
|
test('Warendorf webcam display introduces the shared OSM credit', (t) => {
|
|
const engine = createFakeEngine(), empty = new Proxy({}, { get: () => noop });
|
|
const renderer = createCctvDisplay(engine, { state: {}, services: { credits: { showOsmCredit, hideOsmCredit } } });
|
|
renderer.attach();
|
|
t.after(() => renderer.destroy());
|
|
const lifecycle = createCctvLifecycle({ state: { _records: [{ camera: { id: 'warendorf-marktplatz-rathaus', cityId: 'warendorf' } }], _recordById: new Map(), _cctvOverlayHost: overlayHost },
|
|
services: { credits: { showOsmCredit, hideOsmCredit }, sprites: empty, activation: empty, picking: empty, focus: empty, render: empty },
|
|
parts: { renderer, selection: empty, geometryQueue: empty, rendering: empty, projection: empty, cards: empty, presentation: empty }, source: {} });
|
|
lifecycle.methods.enable();
|
|
assert.ok(engine.fake.credits.some((credit) => credit.onScreen && credit.html.includes('>© OpenStreetMap<')));
|
|
lifecycle.methods.disable();
|
|
assert.equal(engine.fake.credits.filter((credit) => credit.onScreen).length, 0);
|
|
});
|
|
|
|
test('optional Overpass ALPR adapter uses the shared contributor wording', () => {
|
|
assert.equal(createOverpassAlprSource().attribution.text, '© OpenStreetMap contributors');
|
|
});
|