Skip to content

A spy satellite simulator in your browser, except the data is real. Live open source spatial intelligence on a photorealistic 3D globe.

1005 B
Raw Blame
import * as Cesium from 'cesium';

/**
 * One static Cesium credit per active provider: CC BY-SA imagery needs
 * visible attribution that goes away with the imagery.
 */
export function createCredits() {
  /** @type {Map<string, object>} provider id → Cesium.Credit */
  const shown = new Map();

  function show(viewer, def) {
    if (shown.has(def.id) || !viewer?.creditDisplay) return;
    try {
      const credit = new Cesium.Credit(def.credit.html, true);
      viewer.creditDisplay.addStaticCredit(credit);
      shown.set(def.id, credit);
    } catch {
      /* credit display unavailable */
    }
  }

  function hide(viewer, def) {
    const credit = shown.get(def.id);
    if (!credit) return;
    try {
      viewer?.creditDisplay?.removeStaticCredit?.(credit);
    } catch {
      /* credit display already torn down */
    }
    shown.delete(def.id);
  }

  function hideAll(viewer) {
    for (const id of [...shown.keys()]) hide(viewer, { id });
  }

  return { show, hide, hideAll };
}