mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
- src/app/layers/renderers.js: the layer renderer registry
(registerLayerRenderers(engineKind, { [layerId]: factory }),
rendererFor(layerId, engine), layerAvailableOn(layerId, engineKind)).
Every application layer is registered for Cesium as CESIUM_BUILTIN (it
still draws itself until its render/cesium.js); Navara factories come with
the layer tasks. On it, the stable availability API phase 4 injects into
its layer list: createLayerAvailability(engineKind) →
{ engine, isAvailable(id), available(), unavailable() } with { id, name }
rows (src/app/layers/directory.js holds the ids and names in catalog
order; a test keeps it equal to the constructed catalog).
- createApplicationCatalog({ engineKind, availability }) constructs only the
layers the engine can show, in the same order (shared instances made
once, on demand); the catalog carries `availability` and the others'
metadata (`unavailableMetadata`). Cesium builds the same 30 layers in the
same order as before; Navara builds none yet (no Navara renderers) - the
standalone app now asks the catalog for it instead of making an empty one.
- catalogControlServices: a role whose layer the engine leaves out gets an
empty stand-in (absentLayerControlServices folded in); any other missing
layer is still a wiring error.
- LayerLifecycle(viewer, { engine }): every module call (init, enable,
update, disable, destroy) gets { signal, engine } as its second argument;
viewer is null on Navara.
- Links: a link that turns on layers this engine leaves out keeps them in
the durable state (re-saved links carry them; back on Cesium they turn
on) and activates nothing; a notice names them ("NOT ON THIS ENGINE · Kept
in the link: …"). The Navara notice lists the engine's data layers from
the registry.
- The dev launcher's CCTV wiring check matches the new catalog form.
245 lines
8.3 KiB
JavaScript
245 lines
8.3 KiB
JavaScript
import { createSurfaceServices } from './surfaceServices.js';
|
|
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { createApplicationCatalog } from './constructCatalog.js';
|
|
import { createStandaloneLayerSources } from '../standalone/layerSources.js';
|
|
import { catalogControlServices } from './catalog.js';
|
|
import { LayerLifecycle } from '../data/lifecycle.js';
|
|
import { fakeStreetLevelProvider } from '../testSupport/streetLevelFakes.mjs';
|
|
|
|
function fixtureSources(ids, calls) {
|
|
const sources = createStandaloneLayerSources();
|
|
sources.military = {
|
|
getSnapshot: async () => {
|
|
throw new Error('Use identity acquisition');
|
|
},
|
|
async getIdentities(_query, { signal }) {
|
|
calls.push(signal);
|
|
return ids;
|
|
},
|
|
};
|
|
return sources;
|
|
}
|
|
|
|
test('catalogs construct distinct layers and classification from their supplied source', async (t) => {
|
|
const a = new AbortController();
|
|
const b = new AbortController();
|
|
t.after(() => {
|
|
a.abort();
|
|
b.abort();
|
|
});
|
|
const callsA = [];
|
|
const callsB = [];
|
|
const first = createApplicationCatalog({
|
|
sources: fixtureSources(['abc123'], callsA),
|
|
signal: a.signal,
|
|
surface: fixtureSurface(a.signal),
|
|
});
|
|
const second = createApplicationCatalog({
|
|
sources: fixtureSources(['def456'], callsB),
|
|
signal: b.signal,
|
|
surface: fixtureSurface(b.signal),
|
|
});
|
|
assert.equal(first.layers.length, 30);
|
|
assert.ok(first.get('local-adsb'), 'Local ADS-B is registered');
|
|
assert.deepEqual(
|
|
first.metadata.find(({ id }) => id === 'local-adsb'),
|
|
{ id: 'local-adsb', disposition: 'local-only' },
|
|
'the hardware-local layer is never serialized into links',
|
|
);
|
|
assert.notEqual(first.weatherClock, second.weatherClock);
|
|
await first.weatherClock.setTarget('2026-09-21T12:00:00.000Z');
|
|
assert.match(
|
|
first.get('wind').getRowControls().info,
|
|
/Forecast · does not follow history/,
|
|
);
|
|
assert.equal(second.get('wind').getRowControls().summary.status, null);
|
|
for (const id of ['weather-radar', 'weather-satellite', 'weather-lightning'])
|
|
assert.equal(
|
|
first.get(id).getDiagnostics().clock.target,
|
|
'2026-09-21T12:00:00.000Z',
|
|
);
|
|
assert.ok(first.get('fire-perimeters'));
|
|
assert.ok(first.get('transit'));
|
|
const order = first.layers.map(({ id }) => id);
|
|
assert.deepEqual(
|
|
order.slice(order.indexOf('traffic'), order.indexOf('directions') + 1),
|
|
['traffic', 'cctv', 'radio', 'transit', 'bikeshare', 'directions'],
|
|
);
|
|
assert.ok(first.get('bhote-koshi-2026'));
|
|
assert.ok(first.get('bhote-koshi-locator'));
|
|
const lifecycle = new LayerLifecycle({});
|
|
for (const layer of first.layers) lifecycle.register(layer);
|
|
const rows = lifecycle.getAll();
|
|
for (const id of ['bhote-koshi-2026', 'bhote-koshi-locator']) {
|
|
assert.equal(
|
|
rows.find((row) => row.id === id)?.showInTogglePanel,
|
|
false,
|
|
`${id} remains registered for Scenes but is absent from Data Layers`,
|
|
);
|
|
assert.equal(typeof first.get(id).enable, 'function');
|
|
assert.equal(typeof first.get(id).setParams, 'function');
|
|
}
|
|
assert.equal(
|
|
rows.find((row) => row.id === 'flights')?.showInTogglePanel,
|
|
true,
|
|
'ordinary data layer entries remain visible',
|
|
);
|
|
assert.deepEqual(
|
|
first.layers.map(({ id }) => id),
|
|
second.layers.map(({ id }) => id),
|
|
);
|
|
for (const layer of first.layers)
|
|
assert.notEqual(layer, second.get(layer.id));
|
|
assert.equal(
|
|
catalogControlServices(first).satellitesLayer,
|
|
first.get('satellites'),
|
|
);
|
|
assert.equal(callsA.length, 0, 'construction must not acquire');
|
|
await first.militaryRegistry.refreshMilitaryRegistryIfStale();
|
|
await second.militaryRegistry.refreshMilitaryRegistryIfStale();
|
|
assert.equal(first.militaryRegistry.isMilitaryIcao('abc123'), true);
|
|
assert.equal(first.militaryRegistry.isMilitaryIcao('def456'), false);
|
|
assert.equal(second.militaryRegistry.isMilitaryIcao('def456'), true);
|
|
a.abort();
|
|
assert.equal(
|
|
await first.weatherClock.setTarget('2026-09-21T13:00:00.000Z'),
|
|
false,
|
|
);
|
|
assert.equal(callsA[0].aborted, true);
|
|
assert.equal(first.militaryRegistry.isMilitaryIcao('abc123'), false);
|
|
assert.equal(callsB[0].aborted, false);
|
|
assert.equal(second.militaryRegistry.isMilitaryIcao('def456'), true);
|
|
});
|
|
|
|
test('invalid or already cancelled construction fails before classification can acquire', () => {
|
|
const lifetime = new AbortController();
|
|
assert.throws(
|
|
() =>
|
|
createApplicationCatalog({
|
|
sources: { flights: {} },
|
|
signal: lifetime.signal,
|
|
surface: fixtureSurface(lifetime.signal),
|
|
}),
|
|
/catalog source/,
|
|
);
|
|
lifetime.abort();
|
|
assert.throws(
|
|
() =>
|
|
createApplicationCatalog({
|
|
sources: createStandaloneLayerSources(),
|
|
signal: lifetime.signal,
|
|
}),
|
|
{ name: 'AbortError' },
|
|
);
|
|
});
|
|
|
|
function fixtureSurface(signal) {
|
|
return createSurfaceServices({
|
|
terrainSource: { getHeights: async () => [] },
|
|
signal,
|
|
eventTarget: null,
|
|
});
|
|
}
|
|
|
|
test('Mapillary can be omitted or replaced without changing catalog membership', (t) => {
|
|
const lifetime = new AbortController();
|
|
t.after(() => lifetime.abort());
|
|
const sources = fixtureSources([], []);
|
|
delete sources.mapillary;
|
|
const options = {
|
|
sources,
|
|
signal: lifetime.signal,
|
|
surface: fixtureSurface(lifetime.signal),
|
|
};
|
|
const catalog = createApplicationCatalog(options);
|
|
assert.equal(catalog.layers.length, 30);
|
|
assert.deepEqual(catalog.get('street-level').providerIds, []);
|
|
assert.equal(
|
|
catalogControlServices(catalog).streetLevelLayer,
|
|
catalog.get('street-level'),
|
|
);
|
|
assert.match(
|
|
catalog.get('street-level').getUIState().coverage.hint,
|
|
/No street-level imagery providers/,
|
|
);
|
|
const provider = fakeStreetLevelProvider({
|
|
id: 'example',
|
|
pickPrefix: 'example:',
|
|
});
|
|
const replacement = createApplicationCatalog({
|
|
...options,
|
|
streetLevelProviders: [provider],
|
|
});
|
|
assert.deepEqual(replacement.get('street-level').providerIds, ['example']);
|
|
assert.deepEqual(replacement.metadata, catalog.metadata);
|
|
assert.equal(provider.calls.activate, 0, 'construction must not acquire');
|
|
assert.deepEqual(
|
|
createApplicationCatalog({
|
|
...options,
|
|
sources: fixtureSources([], []),
|
|
streetLevelProviders: [],
|
|
}).get('street-level').providerIds,
|
|
[],
|
|
);
|
|
assert.throws(
|
|
() =>
|
|
createApplicationCatalog({
|
|
...options,
|
|
sources: { ...sources, mapillary: {} },
|
|
}),
|
|
/Mapillary source/,
|
|
);
|
|
});
|
|
|
|
test('the catalog per engine: Cesium as before, Navara only what it can show', async (t) => {
|
|
const { APPLICATION_LAYER_DIRECTORY } = await import('./layers/directory.js');
|
|
const { createLayerAvailability, createRendererRegistry } =
|
|
await import('./layers/renderers.js');
|
|
const controller = new AbortController();
|
|
t.after(() => controller.abort());
|
|
const build = (options) =>
|
|
createApplicationCatalog({
|
|
sources: createStandaloneLayerSources(),
|
|
signal: controller.signal,
|
|
surface: fixtureSurface(controller.signal),
|
|
...options,
|
|
});
|
|
const cesium = build({});
|
|
// The directory is the catalog Cesium builds: ids, names and order.
|
|
assert.deepEqual(
|
|
cesium.layers.map(({ id, name }) => ({ id, name })),
|
|
APPLICATION_LAYER_DIRECTORY.map(({ id, name }) => ({ id, name })),
|
|
);
|
|
assert.equal(cesium.engineKind, 'cesium');
|
|
assert.deepEqual(cesium.unavailableMetadata, []);
|
|
assert.equal(cesium.availability.unavailable().length, 0);
|
|
|
|
const navara = build({ engineKind: 'navara' });
|
|
assert.equal(navara.layers.length, 0, 'no Navara renderers yet');
|
|
assert.equal(navara.unavailableMetadata.length, cesium.metadata.length);
|
|
assert.equal(navara.availability.engine, 'navara');
|
|
|
|
// With Navara renderers for two layers, only those are constructed, in
|
|
// catalog order, with their metadata.
|
|
const registry = createRendererRegistry();
|
|
registry.register('navara', {
|
|
satellites: () => ({}),
|
|
flights: () => ({}),
|
|
});
|
|
const subset = build({
|
|
engineKind: 'navara',
|
|
availability: createLayerAvailability('navara', { registry }),
|
|
});
|
|
assert.deepEqual(
|
|
subset.layers.map(({ id }) => id),
|
|
['flights', 'satellites'],
|
|
);
|
|
assert.deepEqual(
|
|
subset.metadata.map(({ id }) => id),
|
|
['flights', 'satellites'],
|
|
);
|
|
assert.ok(subset.unavailableMetadata.some(({ id }) => id === 'military'));
|
|
assert.equal(subset.get('military'), undefined);
|
|
});
|