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
+30
-25
@@ -1,4 +1,5 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { findCredits } from '../render/rendererOf.js';
|
||||
|
||||
/**
|
||||
* Per-layer data attribution registered into Cesium's credit display.
|
||||
@@ -36,6 +37,20 @@ export const OPENMAPTILES_CREDIT = {
|
||||
|
||||
const osmDisplays = new WeakMap();
|
||||
|
||||
/** The short inline OSM credits, as the renderer's credits port takes them. */
|
||||
const OSM_INLINE_CREDITS = Object.freeze({
|
||||
osm: Object.freeze({
|
||||
text: '© OpenStreetMap',
|
||||
href: 'https://www.openstreetmap.org/copyright',
|
||||
inline: true,
|
||||
}),
|
||||
tiles: Object.freeze({
|
||||
text: '© OpenMapTiles',
|
||||
href: 'https://openmaptiles.org',
|
||||
inline: true,
|
||||
}),
|
||||
});
|
||||
|
||||
function updateOsmDisplay(viewer, state) {
|
||||
const osm = state.owners.size > 0;
|
||||
let tiles = false;
|
||||
@@ -44,37 +59,27 @@ function updateOsmDisplay(viewer, state) {
|
||||
['osm', osm],
|
||||
['tiles', tiles],
|
||||
]) {
|
||||
if (state[key].visible === visible) continue;
|
||||
state[key].visible = visible;
|
||||
viewer.creditDisplay[visible ? 'addStaticCredit' : 'removeStaticCredit'](
|
||||
state[key].credit,
|
||||
);
|
||||
viewer.scene?.requestRender?.();
|
||||
if (Boolean(state.offs[key]) === visible) continue;
|
||||
if (visible) {
|
||||
// Looked up each time: a renderer bound later takes over.
|
||||
const credits = findCredits(viewer);
|
||||
if (credits) state.offs[key] = credits.addStatic(OSM_INLINE_CREDITS[key]);
|
||||
} else {
|
||||
state.offs[key]();
|
||||
state.offs[key] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Keep one short inline credit while an OSM display owner has visible data. */
|
||||
/**
|
||||
* Keep one short inline credit, through the renderer's credits port, while
|
||||
* an OSM display owner has visible data.
|
||||
*/
|
||||
export function showOsmCredit(viewer, owner, { openMapTiles = false } = {}) {
|
||||
if (!viewer?.creditDisplay?.addStaticCredit || !owner) return false;
|
||||
if (!owner || !findCredits(viewer)) return false;
|
||||
let state = osmDisplays.get(viewer);
|
||||
if (!state) {
|
||||
state = {
|
||||
owners: new Map(),
|
||||
osm: {
|
||||
visible: false,
|
||||
credit: new Cesium.Credit(
|
||||
'<a href="https://www.openstreetmap.org/copyright" target="_blank" rel="noopener">© OpenStreetMap</a>',
|
||||
true,
|
||||
),
|
||||
},
|
||||
tiles: {
|
||||
visible: false,
|
||||
credit: new Cesium.Credit(
|
||||
'<a href="https://openmaptiles.org" target="_blank" rel="noopener">© OpenMapTiles</a>',
|
||||
true,
|
||||
),
|
||||
},
|
||||
};
|
||||
state = { owners: new Map(), offs: { osm: null, tiles: null } };
|
||||
osmDisplays.set(viewer, state);
|
||||
}
|
||||
if (state.owners.get(owner) === openMapTiles) return false;
|
||||
|
||||
Reference in new issue
Block a user