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

+41 -6
View File
@@ -24,7 +24,8 @@ import {
creditFromMarkup,
safeUrl,
} from '../creditMarkup.js';
import { listenerList } from './common.js';
import { provideUnboundCredits } from '../rendererOf.js';
import { listenerList, uncaught } from './common.js';
import { creditDisplayContents } from './internals.js';
const CREDIT_KEYS = new Set(['text', 'href', 'logoUrl', 'inline']);
@@ -86,6 +87,9 @@ function copyCredit(credit) {
*/
export function createCesiumCredits({ display, scene, report, requestRender }) {
const listeners = listenerList(report);
// A viewer may be destroyed before the code holding credits lets
// them go; a destroyed display throws on every call.
const displayLive = () => Boolean(display) && !display.isDestroyed?.();
/** The page's credits, in the order added: each `{credit, markup}`. */
const added = [];
/** The page's credits as Cesium shows them, by markup: `{credit, count}`. */
@@ -120,7 +124,9 @@ export function createCesiumCredits({ display, scene, report, requestRender }) {
* leaves it out.
*/
function shownCredits() {
const { statics, screen, lightbox, logo } = creditDisplayContents(display);
const { statics, screen, lightbox, logo } = creditDisplayContents(
displayLive() ? display : undefined,
);
const out = [];
const seen = new Set();
const take = (credit) => {
@@ -204,7 +210,7 @@ export function createCesiumCredits({ display, scene, report, requestRender }) {
entry = { credit: new Cesium.Credit(markup, inline), count: 0 };
shown.set(key, entry);
coreCredits.add(entry.credit);
display?.addStaticCredit(entry.credit);
if (displayLive()) display.addStaticCredit(entry.credit);
}
entry.count += 1;
return key;
@@ -217,7 +223,7 @@ export function createCesiumCredits({ display, scene, report, requestRender }) {
if (entry.count > 0) return;
shown.delete(key);
coreCredits.delete(entry.credit);
display?.removeStaticCredit(entry.credit);
if (displayLive()) display.removeStaticCredit(entry.credit);
}
let disposed = false;
@@ -251,15 +257,44 @@ export function createCesiumCredits({ display, scene, report, requestRender }) {
return {
port,
/** Detach from the scene and take the page's credits off the display. */
dispose() {
disposed = true;
offFrame();
listeners.clear();
if (!display?.isDestroyed?.())
if (displayLive())
for (const { credit } of shown.values())
display?.removeStaticCredit(credit);
display.removeStaticCredit(credit);
shown.clear();
coreCredits.clear();
},
/**
* Detach from the scene only: the credits added stay shown until their
* own Off, for a port another one supersedes.
*/
release() {
offFrame();
listeners.clear();
},
};
}
// A Cesium viewer with no renderer bound to it gets a
// credits port over its credit display when code first asks `findCredits`
// for one. `camera.js` loads this module, so the entries that load the
// unbound camera load this too.
provideUnboundCredits((viewer) =>
// By shape, not `instanceof`: the viewer may come from another
// copy of Cesium.
typeof viewer.creditDisplay?.addStaticCredit === 'function' &&
typeof viewer.scene?.postRender?.addEventListener === 'function'
? createCesiumCredits({
display: viewer.creditDisplay,
scene: viewer.scene,
report: uncaught,
requestRender: () => {
if (!viewer.scene.isDestroyed?.()) viewer.scene.requestRender?.();
},
})
: null,
);