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

+3
View File
@@ -1,6 +1,9 @@
import { indexMapSources } from './registry.js';
import * as Cesium from 'cesium';
import { createMapCredits } from './credits.js';
// A viewer of a caller's own gets its credits port (and camera) from the
// factories this loads.
import '../render/cesium/camera.js';
import { acquireImageryComparison } from './imageryComparison.js';
/**
+13 -11
View File
@@ -2,6 +2,7 @@ import test from 'node:test';
import assert from 'node:assert/strict';
import { MapSourceController } from './controller.js';
import { createDefaultMapSources } from './defaultSources.js';
import { bindRenderer } from '../render/rendererOf.js';
function event() {
const listeners = new Set();
@@ -28,16 +29,6 @@ function fixture(registry, options = {}) {
scene: {
globe: { show: true },
requestRender() {},
frameState: {
creditDisplay: {
addStaticCredit(value) {
credits.add(value);
},
removeStaticCredit(value) {
credits.delete(value);
},
},
},
primitives: {
add(value) {
primitives.push(value);
@@ -58,6 +49,14 @@ function fixture(registry, options = {}) {
},
},
};
bindRenderer(viewer, {
credits: {
addStatic(credit) {
credits.add(credit);
return () => credits.delete(credit);
},
},
});
const controller = new MapSourceController(viewer, {
registry,
createImageryLayer: (provider) => ({ provider }),
@@ -274,7 +273,10 @@ test('Esri construction fallback reports and attributes the source actually rend
test('one Esri tile failure stays put, two fall back, and stale errors cannot replace a selection', async () => {
const env = publicFixture();
await env.controller.setStack('esri-imagery');
assert.equal(env.credits.size, 1);
assert.deepEqual(
[...env.credits],
[{ text: 'Powered by Esri', href: 'https://www.esri.com', inline: true }],
);
const errorEvent = env.providers.get('esri-imagery').errorEvent;
errorEvent.raise();
await settle();
+15 -13
View File
@@ -1,22 +1,24 @@
import * as Cesium from 'cesium';
import { creditFromMarkup } from '../render/creditMarkup.js';
import { findCredits } from '../render/rendererOf.js';
/** Static credits follow the source actually on screen, including fallback. */
/**
* The on-map credit of the source actually on screen, including fallback,
* through the renderer's credits port. A source's credit is markup with one
* link, read as the port's plain data.
*/
export function createMapCredits(viewer) {
let active = null;
let off = null;
let markup = null;
return {
show(html) {
if (html === markup) return;
const display = viewer?.scene?.frameState?.creditDisplay;
if (!display) return;
try {
if (active) display.removeStaticCredit(active);
active = html ? new Cesium.Credit(html, true) : null;
markup = html;
if (active) display.addStaticCredit(active);
} catch {
/* Switching remains usable on older credit displays. */
}
const credits = findCredits(viewer);
if (!credits) return;
off?.();
off = html
? credits.addStatic({ ...creditFromMarkup(html), inline: true })
: null;
markup = html;
},
destroy() {
this.show(null);
@@ -7,9 +7,6 @@ function fixture() {
scene: {
globe: { show: true },
requestRender() {},
frameState: {
creditDisplay: { addStaticCredit() {}, removeStaticCredit() {} },
},
primitives: { add() {}, remove() {} },
},
imageryLayers: { add() {}, remove() {} },