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

+18 -20
View File
@@ -1,33 +1,31 @@
import * as Cesium from 'cesium';
import { creditFromMarkup } from '../../render/creditMarkup.js';
import { findCredits } from '../../render/rendererOf.js';
/**
* One static Cesium credit per active provider: CC BY-SA imagery needs
* visible attribution that goes away with the imagery.
* One on-map credit per active provider, through the renderer's credits
* port: CC BY-SA imagery needs visible attribution that goes away with the
* imagery. A provider's credit is markup with one link, read as the
* port's plain data.
*/
export function createCredits() {
/** @type {Map<string, object>} provider id → Cesium.Credit */
/** @type {Map<string, () => void>} provider id → the credit's Off */
const shown = new Map();
function show(viewer, def) {
if (shown.has(def.id) || !viewer?.creditDisplay) return;
try {
const credit = new Cesium.Credit(def.credit.html, true);
viewer.creditDisplay.addStaticCredit(credit);
shown.set(def.id, credit);
} catch {
/* credit display unavailable */
}
if (shown.has(def.id)) return;
const credits = findCredits(viewer);
if (!credits) return;
shown.set(
def.id,
credits.addStatic({ ...creditFromMarkup(def.credit.html), inline: true }),
);
}
function hide(viewer, def) {
const credit = shown.get(def.id);
if (!credit) return;
try {
viewer?.creditDisplay?.removeStaticCredit?.(credit);
} catch {
/* credit display already torn down */
}
function hide(_viewer, def) {
const off = shown.get(def.id);
if (!off) return;
shown.delete(def.id);
off();
}
function hideAll(viewer) {