Add layer and map credits through the renderer's credits port

The street-level provider credits, the map source credit, the shared
inline OpenStreetMap and OpenMapTiles credits and the ALPR provider credit
go through the renderer's credits port instead of Cesium's credit display.
Their markup has one link each and is read as the port's plain data; the
ALPR credit is built as plain data, which the port escapes. src/maps/credits.js
and src/layers/streetLevel/credits.js no longer reach Cesium and leave the
allow-list.

findCredits finds the port as findCamera finds the camera: a Cesium viewer
of a caller's own, with no renderer bound, gets a credits port over its
own credit display, so the public entries keep their attribution. A port
built that way is released, not disposed, when a renderer binds later, and
a credit let go after its viewer is destroyed leaves the display alone.

The per-layer data credits and the transit and event credits stay on
Cesium's display: their markup carries several links each, which the
contract's credit cannot hold.
This commit is contained in:
Sameh Khamis committed 2026-11-06 16:32:23 -08:00
1 parent 979e2213b9
commit 765a0db094
26 files changed
+418 -142

No files matched your search

+48 -10
View File
@@ -15,6 +15,9 @@ const renderers = new WeakMap();
*/
const unboundCameras = new WeakMap();
let buildUnboundCamera = null;
/** Credits ports built likewise, each `{port, dispose, release}`. */
const unboundCredits = new WeakMap();
let buildUnboundCredits = null;
/**
* Provide the factory `cameraOf` builds a camera port with for a scene
@@ -26,6 +29,17 @@ export function provideUnboundCamera(build) {
buildUnboundCamera = build;
}
/**
* Provide the factory `findCredits` builds a credits port with for a scene
* object no renderer is bound to, as `provideUnboundCamera` does. `release`
* detaches a port a bound renderer supersedes, keeping its credits shown.
* @param {(host: object) => ({port: object, dispose: () => void,
* release: () => void} | null)} build
*/
export function provideUnboundCredits(build) {
buildUnboundCredits = build;
}
/**
* Bind a renderer to its scene object. A camera `cameraOf` built for it
* while it had no renderer is disposed: its listeners hear nothing more,
@@ -39,6 +53,11 @@ export function bindRenderer(host, renderer) {
// The renderer's camera supersedes one built while there was none.
unboundCameras.get(host)?.dispose();
unboundCameras.delete(host);
// Its credits port does too for credits added from now on; one built
// before is released, not disposed: the credits added through it stay
// shown until their own Off.
unboundCredits.get(host)?.release?.();
unboundCredits.delete(host);
renderers.set(host, renderer);
return () => {
if (renderers.get(host) === renderer) renderers.delete(host);
@@ -60,21 +79,40 @@ export const rendererOf = (host) => (host && renderers.get(host)) || null;
* has no renderer and no camera can be built for it, or is destroyed.
*/
export function findCamera(host) {
const camera = rendererOf(host)?.camera;
if (camera) return camera;
return (
rendererOf(host)?.camera ??
findUnbound(host, unboundCameras, buildUnboundCamera)
);
}
/**
* The credits port of the renderer bound to `host`; with no renderer bound,
* one built over `host` by the provided factory and kept with it while
* `host` lives, as `findCamera` does.
* @param {object|null|undefined} host
* @returns {import('./contract/credits').CreditsPort | null}
*/
export function findCredits(host) {
return (
rendererOf(host)?.credits ??
findUnbound(host, unboundCredits, buildUnboundCredits)
);
}
function findUnbound(host, built, build) {
if (!host || typeof host !== 'object') return null;
if (host.isDestroyed?.()) {
// Gone with its scene: let the built camera go with it.
unboundCameras.get(host)?.dispose();
unboundCameras.delete(host);
// Gone with its scene: let the built port go with it.
built.get(host)?.dispose();
built.delete(host);
return null;
}
let built = unboundCameras.get(host);
if (!built && buildUnboundCamera) {
built = buildUnboundCamera(host);
if (built) unboundCameras.set(host, built);
let part = built.get(host);
if (!part && build) {
part = build(host);
if (part) built.set(host, part);
}
return built?.port ?? null;
return part?.port ?? null;
}
/**