Skip to content

feat(core): return cesium credit conditionally in getCredits - #144

Merged
ZTongci merged 9 commits into
alphafrom
feat/conditional-cesium-ion-credit
Jul 14, 2026
Merged

feat(core): return cesium credit conditionally in getCredits#144
ZTongci merged 9 commits into
alphafrom
feat/conditional-cesium-ion-credit

Conversation

@ZTongci

@ZTongci ZTongci commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Overview

The Cesium-ion logo was always shown in the credit display, even when the scene contained no Cesium-ion assets. creditDisplay._currentCesiumCredit is populated by Cesium as soon as the viewer initialises, regardless of whether any Ion asset is actually loaded.

This change computes whether Ion assets are in use inside the core's Map component — the only place that already has access to both property (ViewerProperty) and layers (Layer[]) — and threads the result down to getCredits() so the credit is only emitted when Ion assets are genuinely present.

What I've done

  • src/Map/cesiumIonDetection.ts (new) — computeHasCesiumIonAsset(property, layers) detects Ion usage across:
    • Tiles: type starts with cesium_ion, or is a legacy alias (default, default_road, default_label, black_marble).
    • Terrain: type cesium or cesiumion with enabled: true, or assets.cesium.terrain.ionUrl contains ion.cesium.com.
    • Layers: osm-buildings, google-photorealistic not routed through Google Maps API, or 3dtiles with an ion.cesium.com URL. Recurses into LayerGroup.children.
  • src/Map/index.tsx — Computes hasCesiumIonAsset internally via useMemo and passes it to the engine. hasCesiumIonAsset is excluded from Map.Props via Omit so external callers cannot set it.
  • src/Visualizer/index.tsx — Removed hasCesiumIonAsset from CoreVisualizerProps; callers no longer need to know about Ion detection.
  • src/engines/Cesium/common.tsgetCredits(viewer, hasCesiumIonAsset?) sets engine.cesium to undefined when hasCesiumIonAsset === false. undefined (not provided) preserves existing behavior.
  • src/engines/Cesium/hooks.ts — Accepts hasCesiumIonAsset, stores it in a ref, passes ref to useEngineRef and value to getCredits.
  • src/engines/Cesium/index.tsx — Destructures and forwards hasCesiumIonAsset to useHooks.
  • src/engines/Cesium/hooks/useEngineRef.ts — Passes hasCesiumIonAssetRef.current to getCredits.

How I tested

Manually verified: default scene (OSM tile + reearth terrain) → logo hidden; switching to a Cesium Ion tile → logo appears; switching back → logo disappears after the next 3-second credit poll.

Backward compatibility

hasCesiumIonAsset === false is the only case that suppresses the credit. When the flag computes to undefined or true, the existing behavior is preserved.

…re in use

Add `hasCesiumIonAsset?: boolean` to `EngineProps` and thread it through
the engine stack so `getCredits()` omits `engine.cesium` when the flag is
explicitly `false`.  Callers that do not pass the flag receive the existing
behavior (`undefined` → credit included) for full backward compatibility.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
ZTongci and others added 2 commits July 6, 2026 14:29
Detection logic was previously passed in from the visualizer as a prop
(`hasCesiumIonAsset`). Core already owns both `property` (ViewerProperty)
and `layers` (Layer[]) in `Map/index.tsx`, so computing the boolean there
keeps Ion-awareness entirely within core — consistent with how credits are
already surfaced via `getCredits`.

`CoreVisualizerProps` no longer exposes `hasCesiumIonAsset`; callers are
unaffected.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ZTongci
ZTongci force-pushed the feat/conditional-cesium-ion-credit branch from ca14a30 to d5a27b4 Compare July 9, 2026 06:27
Comment thread src/Map/cesiumIonDetection.ts Outdated
Comment thread src/Map/cesiumIonDetection.ts Outdated
- google-photorealistic: only check provider === "cesium-ion" (drop serviceTokens check)
- remove 3dtiles type restriction from URL check (isIonUrl applies to any layer type)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ZTongci ZTongci changed the title feat(core): conditionally hide Cesium-ion credit when no Ion assets are in use feat(core): return cesium credit conditionally in getCredits Jul 13, 2026
@bnimit
bnimit requested a review from Copilot July 13, 2026 06:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR makes the Cesium credit emission conditional on whether Cesium-ion assets are actually in use, by computing an internal hasCesiumIonAsset flag in the core Map component and plumbing it down into Cesium’s getCredits().

Changes:

  • Add Cesium-ion usage detection (computeHasCesiumIonAsset) based on viewer property (tiles/terrain) and layer tree analysis.
  • Compute hasCesiumIonAsset inside src/Map/index.tsx (kept internal via Omit) and pass it to the engine.
  • Update Cesium engine hooks and getCredits(viewer, hasCesiumIonAsset?) to suppress the Cesium credit when hasCesiumIonAsset === false.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/Map/types/index.ts Adds hasCesiumIonAsset?: boolean to EngineProps for engine-level plumbing.
src/Map/index.tsx Computes hasCesiumIonAsset via useMemo and passes it to the engine while preventing external override.
src/Map/cesiumIonDetection.ts New Cesium-ion usage detection helper (tiles, terrain, layers, recursive groups).
src/engines/Cesium/index.tsx Forwards hasCesiumIonAsset into Cesium hooks.
src/engines/Cesium/hooks.ts Stores hasCesiumIonAsset in a ref and threads it to credit polling and useEngineRef.
src/engines/Cesium/hooks/useEngineRef.ts Passes hasCesiumIonAssetRef.current through the imperative getCredits() API.
src/engines/Cesium/common.ts Updates getCredits signature and conditionally suppresses Cesium credit when explicitly no Ion assets.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Map/cesiumIonDetection.ts
Comment thread src/Map/cesiumIonDetection.ts
ZTongci and others added 3 commits July 13, 2026 15:24
Covers tiles, terrain, layers (osm-buildings, google-photorealistic, ion URL),
LayerGroup recursion, and edge cases.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
bnimit
bnimit previously approved these changes Jul 13, 2026

@bnimit bnimit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@airslice airslice left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@ZTongci
ZTongci merged commit fa71ada into alpha Jul 14, 2026
2 of 3 checks passed
@ZTongci
ZTongci deleted the feat/conditional-cesium-ion-credit branch July 14, 2026 07:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants