Files
gods-eye-view/src/globe/cesium/credits.js
T
German Khokhlov 83c13f330d refactor(credits): use the globe engine
Map credits (maps/credits.js) are shown through a credits capability
(engine.credits.addStatic) instead of the scene's credit display; the
shared map scene takes the engine's credits, so the Cesium engine's maps
and its credits part share one owner. Data credits (registerDataCredits,
registerDynamicCredit, show/hideOsmCredit) take the globe engine and keep
accepting a viewer from layers that still hold one; the scene registers
the data credits on its engine. The Cesium credits part reads
Viewer.creditDisplay, else the scene frame state display it aliases.
2026-10-15 18:37:02 +04:00

32 lines
951 B
JavaScript

// Static credits on the viewer's credit display.
import * as Cesium from 'cesium';
/**
* @param {Cesium.Viewer} viewer
* @returns {{ credits: { addStatic: (html: string, options?: { onScreen?: boolean }) => () => void }, destroy: () => void }}
*/
export function createCesiumCredits(viewer) {
const added = new Set();
// Viewer.creditDisplay is the scene frame state's display.
const display = () =>
viewer.creditDisplay ?? viewer.scene?.frameState?.creditDisplay;
const remove = (credit) => {
if (!added.delete(credit)) return;
display()?.removeStaticCredit(credit);
};
return {
credits: {
addStatic(html, { onScreen = false } = {}) {
const credit = new Cesium.Credit(html, Boolean(onScreen));
display().addStaticCredit(credit);
added.add(credit);
return () => remove(credit);
},
},
destroy() {
for (const credit of [...added]) remove(credit);
},
};
}