-
Notifications
You must be signed in to change notification settings - Fork 5
feat(core): return cesium credit conditionally in getCredits #144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7a2fcb5
feat(core): conditionally hide Cesium-ion credit when no Ion assets a…
ZTongci 8c528a1
fix(core): fix prettier formatting and exhaustive-deps lint error
ZTongci d5a27b4
refactor: move Cesium Ion asset detection into Map layer of core
ZTongci cfbb4e2
refactor(core): simplify cesium ion detection per review feedback
ZTongci 4ba05c2
test(core): add unit tests for computeHasCesiumIonAsset
ZTongci 657c773
chore: fix prettier formatting in cesiumIonDetection.test.ts
ZTongci a282cf2
fix(lint): fix prettier formatting in cesiumIonDetection.test.ts
ZTongci bbd9428
test: fix cesiumIonDetection test
ZTongci 4b8b9c2
fix: fix lint issue
ZTongci File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,221 @@ | ||
| import { describe, expect, test } from "vitest"; | ||
|
|
||
| import { computeHasCesiumIonAsset } from "./cesiumIonDetection"; | ||
|
|
||
| const makeSimple = (data?: object) => ({ | ||
| id: "layer1", | ||
| type: "simple" as const, | ||
| ...(data ? { data } : {}), | ||
| }); | ||
|
|
||
| const makeGroup = (children: object[]) => ({ | ||
| id: "group1", | ||
| type: "group" as const, | ||
| children, | ||
| }); | ||
|
|
||
| describe("computeHasCesiumIonAsset", () => { | ||
| describe("tiles", () => { | ||
| test("returns false when no tiles", () => { | ||
| expect(computeHasCesiumIonAsset({ tiles: [] })).toBe(false); | ||
| }); | ||
|
|
||
| test("returns true for cesium_ion tile type", () => { | ||
| expect(computeHasCesiumIonAsset({ tiles: [{ type: "cesium_ion" }] })).toBe(true); | ||
| }); | ||
|
|
||
| test("returns true for cesium_ion_default tile type", () => { | ||
| expect(computeHasCesiumIonAsset({ tiles: [{ type: "cesium_ion_default" }] })).toBe(true); | ||
| }); | ||
|
|
||
| test("returns true for legacy tile types", () => { | ||
| for (const type of ["default", "default_road", "default_label", "black_marble"]) { | ||
| expect(computeHasCesiumIonAsset({ tiles: [{ type }] })).toBe(true); | ||
| } | ||
| }); | ||
|
|
||
| test("returns false for non-ion tile type", () => { | ||
| expect(computeHasCesiumIonAsset({ tiles: [{ type: "open_street_map" }] })).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe("terrain", () => { | ||
| test("returns true for cesium terrain type when enabled", () => { | ||
| expect( | ||
| computeHasCesiumIonAsset({ | ||
| terrain: { enabled: true, type: "cesium" }, | ||
| }), | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| test("returns true for cesiumion terrain type when enabled", () => { | ||
| expect( | ||
| computeHasCesiumIonAsset({ | ||
| terrain: { enabled: true, type: "cesiumion" }, | ||
| }), | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| test("returns false for cesium terrain when disabled", () => { | ||
| expect( | ||
| computeHasCesiumIonAsset({ | ||
| terrain: { enabled: false, type: "cesium" }, | ||
| }), | ||
| ).toBe(false); | ||
| }); | ||
|
|
||
| test("returns true for ion terrain URL", () => { | ||
| expect( | ||
| computeHasCesiumIonAsset({ | ||
| terrain: { enabled: true, type: "url" }, | ||
| assets: { | ||
| cesium: { | ||
| terrain: { | ||
| ionUrl: "https://assets.ion.cesium.com/1/tileset.json", | ||
| }, | ||
| }, | ||
| }, | ||
| } as any), | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| test("returns false for non-ion terrain URL", () => { | ||
| expect( | ||
| computeHasCesiumIonAsset({ | ||
| terrain: { enabled: true, type: "url" }, | ||
| assets: { | ||
| cesium: { terrain: { ionUrl: "https://example.com/terrain" } }, | ||
| }, | ||
| } as any), | ||
| ).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe("layers", () => { | ||
| test("returns true for osm-buildings layer", () => { | ||
| expect( | ||
| computeHasCesiumIonAsset(undefined, [makeSimple({ type: "osm-buildings" })] as any), | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| test("returns true for google-photorealistic with cesium-ion provider", () => { | ||
| expect( | ||
| computeHasCesiumIonAsset(undefined, [ | ||
| makeSimple({ type: "google-photorealistic", provider: "cesium-ion" }), | ||
| ] as any), | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| test("returns false for google-photorealistic with reearth provider", () => { | ||
| expect( | ||
| computeHasCesiumIonAsset(undefined, [ | ||
| makeSimple({ type: "google-photorealistic", provider: "reearth" }), | ||
| ] as any), | ||
| ).toBe(false); | ||
| }); | ||
|
|
||
| test("returns false for google-photorealistic with no provider (google API path)", () => { | ||
| expect( | ||
| computeHasCesiumIonAsset(undefined, [makeSimple({ type: "google-photorealistic" })] as any), | ||
| ).toBe(false); | ||
| }); | ||
|
|
||
| test("returns true for layer with ion URL", () => { | ||
| expect( | ||
| computeHasCesiumIonAsset(undefined, [ | ||
| makeSimple({ | ||
| type: "3dtiles", | ||
| url: "https://assets.ion.cesium.com/123/tileset.json", | ||
| }), | ||
| ] as any), | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| test("returns true for any layer type with ion URL", () => { | ||
| expect( | ||
| computeHasCesiumIonAsset(undefined, [ | ||
| makeSimple({ | ||
| type: "geojson", | ||
| url: "https://assets.ion.cesium.com/456/data.json", | ||
| }), | ||
| ] as any), | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| test("returns false for layer with non-ion URL", () => { | ||
| expect( | ||
| computeHasCesiumIonAsset(undefined, [ | ||
| makeSimple({ | ||
| type: "3dtiles", | ||
| url: "https://example.com/tileset.json", | ||
| }), | ||
| ] as any), | ||
| ).toBe(false); | ||
| }); | ||
|
|
||
| test("returns false for layer with no data", () => { | ||
| expect(computeHasCesiumIonAsset(undefined, [makeSimple()] as any)).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe("layer groups (recursion)", () => { | ||
| test("returns true when nested layer uses ion", () => { | ||
| const group = makeGroup([makeSimple({ type: "osm-buildings" })]); | ||
| expect(computeHasCesiumIonAsset(undefined, [group] as any)).toBe(true); | ||
| }); | ||
|
|
||
| test("returns false when nested layer does not use ion", () => { | ||
| const group = makeGroup([ | ||
| makeSimple({ type: "geojson", url: "https://example.com/data.json" }), | ||
| ]); | ||
| expect(computeHasCesiumIonAsset(undefined, [group] as any)).toBe(false); | ||
| }); | ||
|
|
||
| test("returns true when deeply nested layer uses ion", () => { | ||
| const inner = makeGroup([makeSimple({ type: "osm-buildings" })]); | ||
| const outer = makeGroup([inner]); | ||
| expect(computeHasCesiumIonAsset(undefined, [outer] as any)).toBe(true); | ||
| }); | ||
| }); | ||
|
|
||
| describe("combined", () => { | ||
| test("returns false when nothing uses ion", () => { | ||
| expect( | ||
| computeHasCesiumIonAsset( | ||
| { | ||
| tiles: [{ type: "open_street_map" }], | ||
| terrain: { enabled: false, type: "cesium" }, | ||
| }, | ||
| [ | ||
| makeSimple({ | ||
| type: "geojson", | ||
| url: "https://example.com/data.json", | ||
| }), | ||
| ] as any, | ||
| ), | ||
| ).toBe(false); | ||
| }); | ||
|
|
||
| test("returns true when only tile uses ion", () => { | ||
| expect( | ||
| computeHasCesiumIonAsset({ tiles: [{ type: "default" }] }, [ | ||
| makeSimple({ type: "geojson" }), | ||
| ] as any), | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| test("returns true when only terrain uses ion", () => { | ||
| expect( | ||
| computeHasCesiumIonAsset({ terrain: { enabled: true, type: "cesium" } }, [ | ||
| makeSimple({ type: "geojson" }), | ||
| ] as any), | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| test("returns undefined-safe (no property, no layers)", () => { | ||
| expect(computeHasCesiumIonAsset()).toBe(false); | ||
| expect(computeHasCesiumIonAsset(undefined, undefined)).toBe(false); | ||
| expect(computeHasCesiumIonAsset(undefined, [])).toBe(false); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import type { Layer, LayerSimple } from "../mantle"; | ||
|
|
||
| import type { TileProperty, ViewerProperty } from "./types/viewerProperty"; | ||
|
|
||
| const CESIUM_ION_URL_PATTERN = "ion.cesium.com"; | ||
| const CESIUM_ION_LEGACY_TILE_TYPES = new Set([ | ||
| "default", | ||
| "default_road", | ||
| "default_label", | ||
| "black_marble", | ||
| ]); | ||
|
|
||
| function isIonUrl(url?: string | null): boolean { | ||
| return !!url && url.includes(CESIUM_ION_URL_PATTERN); | ||
| } | ||
|
|
||
| function tileUsesIon(tile: TileProperty): boolean { | ||
| if (!tile.type) return false; | ||
| if (tile.type.startsWith("cesium_ion")) return true; | ||
| if (CESIUM_ION_LEGACY_TILE_TYPES.has(tile.type)) return true; | ||
| return false; | ||
| } | ||
|
|
||
| function terrainUsesIon(property?: ViewerProperty): boolean { | ||
| const terrain = property?.terrain; | ||
| if (!terrain?.enabled) return false; | ||
| if (terrain.type === "cesium" || terrain.type === "cesiumion") return true; | ||
| if (isIonUrl(property?.assets?.cesium?.terrain?.ionUrl)) return true; | ||
| return false; | ||
| } | ||
|
|
||
| function layerUsesIon(layer: LayerSimple): boolean { | ||
| const data = layer.data; | ||
| if (!data) return false; | ||
| if (data.type === "osm-buildings") return true; | ||
| if (data.type === "google-photorealistic") { | ||
| return data.provider === "cesium-ion"; | ||
| } | ||
| if (isIonUrl(data.url)) return true; | ||
| return false; | ||
| } | ||
|
|
||
| function anyLayerUsesIon(layer: Layer): boolean { | ||
| if (layer.type === "group") { | ||
| return layer.children.some(anyLayerUsesIon); | ||
| } | ||
| return layerUsesIon(layer); | ||
| } | ||
|
|
||
| export function computeHasCesiumIonAsset(property?: ViewerProperty, layers?: Layer[]): boolean { | ||
| if (property?.tiles?.some(tileUsesIon)) return true; | ||
| if (terrainUsesIon(property)) return true; | ||
| if (layers?.some(anyLayerUsesIon)) return true; | ||
| return false; | ||
|
ZTongci marked this conversation as resolved.
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.