mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
feat(app): layer catalog per engine
- 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.
This commit is contained in:
1 parent
e1be2eac19
commit
b0cbed081b
23 files changed
+826
-146
No files matched your search
@@ -0,0 +1,86 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import {
|
||||
CESIUM_BUILTIN,
|
||||
createLayerAvailability,
|
||||
createRendererRegistry,
|
||||
layerAvailableOn,
|
||||
} from './renderers.js';
|
||||
import { APPLICATION_LAYER_DIRECTORY } from './directory.js';
|
||||
|
||||
test('a registry knows which engine renders which layer', () => {
|
||||
const registry = createRendererRegistry();
|
||||
const made = [];
|
||||
registry.register('navara', {
|
||||
flights: (engine, options) => {
|
||||
made.push([engine.kind, options]);
|
||||
return { destroy() {} };
|
||||
},
|
||||
});
|
||||
registry.register('cesium', {
|
||||
flights: CESIUM_BUILTIN,
|
||||
satellites: CESIUM_BUILTIN,
|
||||
});
|
||||
assert.equal(registry.layerAvailableOn('flights', 'navara'), true);
|
||||
assert.equal(registry.layerAvailableOn('satellites', 'navara'), false);
|
||||
assert.equal(registry.layerAvailableOn('satellites', 'cesium'), true);
|
||||
assert.equal(registry.layerAvailableOn('flights', 'other'), false);
|
||||
const renderer = registry.rendererFor(
|
||||
'flights',
|
||||
{ kind: 'navara' },
|
||||
{ tint: 1 },
|
||||
);
|
||||
assert.ok(renderer);
|
||||
assert.deepEqual(made, [['navara', { tint: 1 }]]);
|
||||
// A Cesium layer that still renders itself has no separate renderer.
|
||||
assert.equal(registry.rendererFor('flights', { kind: 'cesium' }), null);
|
||||
assert.equal(registry.rendererFor('satellites', { kind: 'navara' }), null);
|
||||
assert.deepEqual(registry.availableIds('cesium').sort(), [
|
||||
'flights',
|
||||
'satellites',
|
||||
]);
|
||||
assert.throws(() => registry.register('navara', { x: 42 }), TypeError);
|
||||
assert.throws(
|
||||
() => registry.register('navara', { flights: () => ({}) }),
|
||||
/already/,
|
||||
'one renderer per layer and engine',
|
||||
);
|
||||
});
|
||||
|
||||
test('the default registry: every layer on Cesium, none yet on Navara', () => {
|
||||
for (const { id } of APPLICATION_LAYER_DIRECTORY) {
|
||||
assert.equal(layerAvailableOn(id, 'cesium'), true, id);
|
||||
assert.equal(layerAvailableOn(id, 'navara'), false, id);
|
||||
}
|
||||
});
|
||||
|
||||
test('the layer availability API: engine, isAvailable, available, unavailable', () => {
|
||||
const registry = createRendererRegistry();
|
||||
registry.register('navara', { flights: () => ({}) });
|
||||
const directory = [
|
||||
{ id: 'flights', name: 'Live Flights' },
|
||||
{ id: 'satellites', name: 'Satellites' },
|
||||
];
|
||||
const availability = createLayerAvailability('navara', {
|
||||
registry,
|
||||
directory,
|
||||
});
|
||||
assert.equal(availability.engine, 'navara');
|
||||
assert.equal(availability.isAvailable('flights'), true);
|
||||
assert.equal(availability.isAvailable('satellites'), false);
|
||||
assert.equal(availability.isAvailable('unknown'), false);
|
||||
assert.deepEqual(availability.available(), [
|
||||
{ id: 'flights', name: 'Live Flights' },
|
||||
]);
|
||||
assert.deepEqual(availability.unavailable(), [
|
||||
{ id: 'satellites', name: 'Satellites' },
|
||||
]);
|
||||
// Fresh copies: a caller cannot change the answer.
|
||||
availability.unavailable().push({ id: 'x', name: 'x' });
|
||||
assert.equal(availability.unavailable().length, 1);
|
||||
assert.ok(Object.isFrozen(availability));
|
||||
const cesium = createLayerAvailability('cesium');
|
||||
assert.equal(cesium.unavailable().length, 0);
|
||||
assert.equal(cesium.available().length, APPLICATION_LAYER_DIRECTORY.length);
|
||||
assert.throws(() => createLayerAvailability('vulkan'), TypeError);
|
||||
});
|
||||
Reference in new issue
Block a user