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.
119 lines
4.1 KiB
JavaScript
119 lines
4.1 KiB
JavaScript
const contract = (layers, methods) =>
|
|
Object.freeze({
|
|
layers: Object.freeze(layers),
|
|
methods: Object.freeze(methods),
|
|
});
|
|
|
|
/** Acquisition contracts and their consumers; records remain family-specific. */
|
|
export const CATALOG_SOURCE_CONTRACTS = Object.freeze({
|
|
directions: contract(['directions'], ['getRoute']),
|
|
'recent-imagery': contract(
|
|
['recent-imagery'],
|
|
['searchHls', 'getThumbnail', 'getTileTemplate'],
|
|
),
|
|
flights: contract(['flights'], ['getSnapshot']),
|
|
military: contract(['military'], ['getSnapshot']),
|
|
vessels: contract(['ais-live-vessels'], ['getSnapshot']),
|
|
cctv: contract(
|
|
['cctv'],
|
|
['getCatalog', 'getHealth', 'getFrameUrl', 'getMediaUrl'],
|
|
),
|
|
radio: contract(['radio'], ['getDirectory', 'recordClick']),
|
|
traffic: contract(
|
|
['traffic'],
|
|
[
|
|
'requestRoads',
|
|
'getStatus',
|
|
'fetchFlowForBounds',
|
|
'getFlowSessionStats',
|
|
'resetFlowTileCache',
|
|
],
|
|
),
|
|
bikeshare: contract(['bikeshare'], ['getStations']),
|
|
installations: contract(
|
|
['military-installations'],
|
|
['getMappedSites', 'searchNearby'],
|
|
),
|
|
satellites: contract(['satellites'], ['readGroup']),
|
|
launches: contract(['rocket-launches'], ['getLaunches', 'getActiveTle']),
|
|
alpr: contract(['alpr-cameras'], ['fetch']),
|
|
firms: contract(['local-firms'], ['getSnapshot']),
|
|
wind: contract(['wind'], ['getSnapshot']),
|
|
weather: contract(
|
|
['weather-radar', 'weather-satellite', 'weather-lightning'],
|
|
['getSnapshot'],
|
|
),
|
|
cyclones: contract(['weather-cyclones'], ['getSnapshot']),
|
|
earthquakes: contract(['earthquakes'], ['getSnapshot']),
|
|
'fire-perimeters': contract(['fire-perimeters'], ['getSnapshot']),
|
|
cables: contract(['telegeography-submarine-cables'], ['fetch']),
|
|
transit: contract(['transit'], ['requestSnapshot', 'getHistory']),
|
|
});
|
|
|
|
/** An omitted provider is unavailable, never an authoritative empty dataset. */
|
|
export class SourceUnavailableError extends Error {
|
|
constructor(name) {
|
|
super(`Data source not configured: ${name}`);
|
|
this.name = 'SourceUnavailableError';
|
|
this.code = 'unavailable';
|
|
this.unavailable = true;
|
|
this.retryable = false;
|
|
}
|
|
}
|
|
|
|
/** Validate supplied contracts and keep omitted sources inert during construction. */
|
|
export function resolveCatalogSources(supplied = {}) {
|
|
if (!supplied || typeof supplied !== 'object' || Array.isArray(supplied))
|
|
throw new TypeError('Catalog sources must be an object');
|
|
const sources = { ...supplied };
|
|
const missing = new Set();
|
|
for (const [name, { methods }] of Object.entries(CATALOG_SOURCE_CONTRACTS)) {
|
|
const source = sources[name];
|
|
if (source == null) {
|
|
missing.add(name);
|
|
const unavailable = () => {
|
|
throw new SourceUnavailableError(name);
|
|
};
|
|
sources[name] = Object.freeze({
|
|
label: name,
|
|
...Object.fromEntries(methods.map((method) => [method, unavailable])),
|
|
});
|
|
} else if (methods.some((method) => typeof source[method] !== 'function')) {
|
|
throw new TypeError(`Invalid catalog source: ${name}`);
|
|
}
|
|
}
|
|
return {
|
|
sources,
|
|
isConfigured: (name) => !missing.has(name),
|
|
/** `omitted`: layer ids the catalog leaves out on purpose (another
|
|
* engine's layers); any other missing consumer is a wiring error. */
|
|
createAvailabilityLookup(layers, { omitted = new Set() } = {}) {
|
|
const byId = new Map(layers.map((layer) => [layer.id, layer]));
|
|
const availability = new Map();
|
|
for (const [name, { layers: ids }] of Object.entries(
|
|
CATALOG_SOURCE_CONTRACTS,
|
|
)) {
|
|
for (const id of ids) {
|
|
const layer = byId.get(id);
|
|
if (!layer) {
|
|
if (omitted.has(id)) continue;
|
|
throw new Error(`Missing source consumer: ${id}`);
|
|
}
|
|
availability.set(
|
|
id,
|
|
Object.freeze({
|
|
available: !missing.has(name),
|
|
source: name,
|
|
reason: missing.has(name)
|
|
? `${layer.name || id}: data source not configured`
|
|
: null,
|
|
}),
|
|
);
|
|
}
|
|
}
|
|
return (id) =>
|
|
availability.get(id) ?? byId.get(id)?.getSourceAvailability?.();
|
|
},
|
|
};
|
|
}
|