mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
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:
1 parent
979e2213b9
commit
765a0db094
26 files changed
+418
-142
No files matched your search
@@ -2,6 +2,7 @@ import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import * as Cesium from 'cesium';
|
||||
import { createCesiumCredits, creditMarkup } from './credits.js';
|
||||
import { findCredits } from '../rendererOf.js';
|
||||
|
||||
/** A credit display as Cesium keeps it: static credits and a frame's. */
|
||||
function fakeDisplay() {
|
||||
@@ -271,6 +272,31 @@ test('dispose detaches from the frame and takes the page’s credits off', () =>
|
||||
assert.equal(t.renders(), 1, 'no render asked of a disposed scene');
|
||||
});
|
||||
|
||||
test('a credit let go after its display is destroyed leaves the display alone', () => {
|
||||
const t = setup();
|
||||
const off = t.port.addStatic({ text: 'x' });
|
||||
t.display.isDestroyed = () => true;
|
||||
t.display.removeStaticCredit = () => {
|
||||
throw new Error('destroyed');
|
||||
};
|
||||
off();
|
||||
assert.deepEqual(t.port.list(), []);
|
||||
t.part.dispose();
|
||||
});
|
||||
|
||||
test('a released port stops following frames and keeps its credits until their Off', () => {
|
||||
const t = setup();
|
||||
const seen = [];
|
||||
t.port.on('change', () => seen.push(1));
|
||||
const off = t.port.addStatic({ text: 'x' });
|
||||
t.part.release();
|
||||
assert.equal(t.listeners.size, 0);
|
||||
assert.equal(t.display._staticCredits.length, 1, 'still shown');
|
||||
off();
|
||||
assert.equal(t.display._staticCredits.length, 0);
|
||||
assert.deepEqual(seen, [1], 'its listeners are gone');
|
||||
});
|
||||
|
||||
test('credit markup escapes every value and links only web URLs', () => {
|
||||
assert.equal(
|
||||
creditMarkup({ text: 'a "b" & <c>' }),
|
||||
@@ -289,3 +315,28 @@ test('credit markup escapes every value and links only web URLs', () => {
|
||||
'<a href="https://example.com/?a=1&b=%222%22" target="_blank" rel="noopener">x</a>',
|
||||
);
|
||||
});
|
||||
|
||||
test('a Cesium viewer with no renderer gets a credits port over its display', () => {
|
||||
const display = fakeDisplay();
|
||||
const listeners = new Set();
|
||||
let renders = 0;
|
||||
const viewer = {
|
||||
creditDisplay: display,
|
||||
scene: {
|
||||
postRender: {
|
||||
addEventListener(cb) {
|
||||
listeners.add(cb);
|
||||
return () => listeners.delete(cb);
|
||||
},
|
||||
},
|
||||
requestRender: () => (renders += 1),
|
||||
},
|
||||
};
|
||||
const port = findCredits(viewer);
|
||||
assert.equal(findCredits(viewer), port);
|
||||
port.addStatic({ text: 'Unbound' });
|
||||
assert.equal(display._staticCredits.length, 1);
|
||||
assert.equal(renders, 1);
|
||||
assert.equal(listeners.size, 1);
|
||||
assert.equal(findCredits({ creditDisplay: display }), null, 'no scene');
|
||||
});
|
||||
Reference in new issue
Block a user