mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +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
@@ -6,6 +6,7 @@ import { createCameraEvents } from '../render/camera/events.js';
|
||||
import { toDegrees } from '../geo/index.js';
|
||||
import { bindRenderer, rendererOf } from '../render/rendererOf.js';
|
||||
import { createCesiumCamera } from '../render/cesium/camera.js';
|
||||
import { fakeCesiumCredits } from './fakeCreditsPort.mjs';
|
||||
|
||||
const DEFAULT_POSE = Object.freeze({
|
||||
lon: 0,
|
||||
@@ -72,8 +73,9 @@ export function fakeCameraPort({ pose = {}, viewRectangle = null } = {}) {
|
||||
* from what the fake has (`positionCartographic`, `heading`, `pitch`,
|
||||
* `roll`) and events come from the fake's own `changed`, `moveStart` and
|
||||
* `moveEnd`. A fake with `trackedEntityChanged` and `entities` follows
|
||||
* through the port, as the renderer does. Binding a viewer twice keeps the
|
||||
* first. Returns the viewer.
|
||||
* through the port, as the renderer does. Its credits are the renderer's
|
||||
* credits port over the fake's `creditDisplay`, if it has one. Binding a
|
||||
* viewer twice keeps the first. Returns the viewer.
|
||||
* @template {{camera: object}} V
|
||||
* @param {V} viewer
|
||||
* @returns {V}
|
||||
@@ -164,6 +166,6 @@ export function bindFakeCesiumCamera(viewer) {
|
||||
},
|
||||
},
|
||||
});
|
||||
bindRenderer(viewer, { camera: port });
|
||||
bindRenderer(viewer, { camera: port, credits: fakeCesiumCredits(viewer) });
|
||||
return viewer;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* The Cesium renderer's own credits port over a fake viewer's
|
||||
* `creditDisplay`, for tests of code that adds credits through the port
|
||||
* and checks what Cesium's display was given.
|
||||
*/
|
||||
import { bindRenderer, rendererOf } from '../render/rendererOf.js';
|
||||
import { createCesiumCredits } from '../render/cesium/credits.js';
|
||||
|
||||
const noEvent = { addEventListener: () => () => {} };
|
||||
|
||||
/**
|
||||
* @param {{creditDisplay?: object, scene?: object}} viewer
|
||||
* @returns {import('../render/contract/credits').CreditsPort}
|
||||
*/
|
||||
export function fakeCesiumCredits(viewer) {
|
||||
return createCesiumCredits({
|
||||
display: viewer.creditDisplay,
|
||||
scene: { postRender: noEvent },
|
||||
report: (error) => {
|
||||
throw error;
|
||||
},
|
||||
requestRender: () => viewer.scene?.requestRender?.(),
|
||||
}).port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind a renderer with just that port to `viewer`; a viewer already bound
|
||||
* keeps its renderer. Returns the viewer.
|
||||
* @template V
|
||||
* @param {V} viewer
|
||||
* @returns {V}
|
||||
*/
|
||||
export function bindFakeCesiumCredits(viewer) {
|
||||
if (!rendererOf(viewer))
|
||||
bindRenderer(viewer, { credits: fakeCesiumCredits(viewer) });
|
||||
return viewer;
|
||||
}
|
||||
Reference in new issue
Block a user