mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
feat(globe): implement the engine on Cesium
createCesiumEngine wraps an existing viewer without changing it: camera, picker, projector, frames, render (through the render governor), surface, input, credits and maps, with geo values out and Cesium values in at the boundary. Map and surface code is shared with src/maps and services/groundSnap instead of copied. scripts/qa-globe-contract.mjs runs the contract suite against the engine in headless Chrome; the camera-events check now waits for the previous move to end, as Cesium's moveStart marks a move from rest.
This commit is contained in:
1 parent
cd94a26b9f
commit
d831cbd23a
33 files changed
+2374
-32
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { indexMapSources } from './registry.js';
|
||||
import * as Cesium from 'cesium';
|
||||
import { createMapCredits } from './credits.js';
|
||||
import { applyTerrain } from './terrain.js';
|
||||
import { acquireImageryComparison } from './imageryComparison.js';
|
||||
|
||||
/**
|
||||
@@ -290,8 +291,7 @@ export class MapSourceController {
|
||||
() => terrain.create({ signal: this._abort.signal }),
|
||||
);
|
||||
if (gen !== this._switchGen) return;
|
||||
if (result.terrain) this.viewer.scene.setTerrain(result.terrain);
|
||||
else this.viewer.terrainProvider = result.provider;
|
||||
applyTerrain(this.viewer, result);
|
||||
this._terrainMode = terrain.id;
|
||||
}
|
||||
return resolution;
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
import { MAP_STACKS } from './catalog.js';
|
||||
import { photorealUnavailableReason } from './availability.js';
|
||||
import { keySetupRequirement } from '../keySetupCore.mjs';
|
||||
import {
|
||||
createOsmImagery,
|
||||
createEsriImagery,
|
||||
createIonImagery,
|
||||
ESRI_ATTRIBUTION_HTML,
|
||||
} from './imagery.js';
|
||||
import { createWorldTerrain, createKeylessTerrain } from './terrain.js';
|
||||
import { imageryFactoryFor, ESRI_ATTRIBUTION_HTML } from './imagery.js';
|
||||
import { terrainSourceFor } from './terrain.js';
|
||||
|
||||
/** Select sources and setup guidance without putting provider branches in the controller. */
|
||||
export function createDefaultMapSources({
|
||||
@@ -18,12 +13,7 @@ export function createDefaultMapSources({
|
||||
const ionToken = String(cesiumToken || '').trim();
|
||||
const hasIon = Boolean(ionToken);
|
||||
const hasGoogle = Boolean(String(googleApiKey || '').trim());
|
||||
const terrain = {
|
||||
id: hasIon ? 'world' : 'keyless',
|
||||
create: hasIon
|
||||
? (request) => createWorldTerrain(ionToken, request)
|
||||
: createKeylessTerrain,
|
||||
};
|
||||
const terrain = terrainSourceFor(ionToken);
|
||||
return {
|
||||
defaultId: googleTileset ? 'photoreal' : 'esri-imagery',
|
||||
unknownId: 'photoreal',
|
||||
@@ -44,12 +34,7 @@ export function createDefaultMapSources({
|
||||
unavailableReason: photorealUnavailableReason(hasIon || hasGoogle),
|
||||
tileset: googleTileset,
|
||||
};
|
||||
const imagery =
|
||||
descriptor.kind === 'ion'
|
||||
? () => createIonImagery(descriptor.style, ionToken)
|
||||
: descriptor.id === 'osm'
|
||||
? createOsmImagery
|
||||
: createEsriImagery;
|
||||
const imagery = imageryFactoryFor(descriptor, ionToken);
|
||||
return {
|
||||
...common,
|
||||
imagery,
|
||||
|
||||
@@ -27,3 +27,16 @@ export function createIonImagery(style, accessToken) {
|
||||
if (!accessToken) throw new Error('Ion imagery requires an explicit token');
|
||||
return Cesium.IonImageryProvider.fromAssetId(style, { accessToken });
|
||||
}
|
||||
|
||||
/**
|
||||
* The imagery factory a globe stack descriptor names: ion styles, OSM, or
|
||||
* Esri. Shared by the default map sources and the Cesium globe engine.
|
||||
* @param {{ kind: string, style?: number }} descriptor
|
||||
* @param {string} [ionToken]
|
||||
* @returns {(request?: { signal?: AbortSignal }) => object | Promise<object>}
|
||||
*/
|
||||
export function imageryFactoryFor(descriptor, ionToken = '') {
|
||||
if (descriptor.kind === 'ion')
|
||||
return () => createIonImagery(descriptor.style, ionToken);
|
||||
return descriptor.kind === 'osm' ? createOsmImagery : createEsriImagery;
|
||||
}
|
||||
@@ -1,8 +1,18 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import * as Cesium from 'cesium';
|
||||
import { createIonImagery } from './imagery.js';
|
||||
import { createWorldTerrain, createKeylessTerrain } from './terrain.js';
|
||||
import {
|
||||
createEsriImagery,
|
||||
createIonImagery,
|
||||
createOsmImagery,
|
||||
imageryFactoryFor,
|
||||
} from './imagery.js';
|
||||
import {
|
||||
applyTerrain,
|
||||
createWorldTerrain,
|
||||
createKeylessTerrain,
|
||||
terrainSourceFor,
|
||||
} from './terrain.js';
|
||||
import { createDefaultMapSources } from './defaultSources.js';
|
||||
|
||||
test('Esri uses Re:Earth without keys and preserves ion terrain when configured', async () => {
|
||||
@@ -161,3 +171,48 @@ test('both Google 3D routes keep tiles drawing while draped imagery loads', asyn
|
||||
assert.equal(calls[1][1].asynchronouslyLoadImagery, true);
|
||||
assert.equal(calls[1][1].enableCollision, true);
|
||||
});
|
||||
|
||||
test('imageryFactoryFor picks the factory a stack descriptor names', async () => {
|
||||
assert.equal(imageryFactoryFor({ id: 'osm', kind: 'osm' }), createOsmImagery);
|
||||
assert.equal(
|
||||
imageryFactoryFor({ id: 'esri-imagery', kind: 'esri-imagery' }),
|
||||
createEsriImagery,
|
||||
);
|
||||
const original = Cesium.IonImageryProvider.fromAssetId;
|
||||
try {
|
||||
Cesium.IonImageryProvider.fromAssetId = async (style, options) => ({
|
||||
style,
|
||||
token: options.accessToken,
|
||||
});
|
||||
const ion = imageryFactoryFor(
|
||||
{ id: 'bing-aerial', kind: 'ion', style: 2 },
|
||||
'ion-token',
|
||||
);
|
||||
assert.deepEqual(await ion(), { style: 2, token: 'ion-token' });
|
||||
} finally {
|
||||
Cesium.IonImageryProvider.fromAssetId = original;
|
||||
}
|
||||
});
|
||||
|
||||
test('terrainSourceFor chooses world terrain only with an ion token', () => {
|
||||
assert.deepEqual(terrainSourceFor(''), {
|
||||
id: 'keyless',
|
||||
create: createKeylessTerrain,
|
||||
});
|
||||
const world = terrainSourceFor(' token ');
|
||||
assert.equal(world.id, 'world');
|
||||
assert.equal(typeof world.create, 'function');
|
||||
});
|
||||
|
||||
test('applyTerrain installs a terrain object or a provider', () => {
|
||||
const calls = [];
|
||||
const viewer = {
|
||||
terrainProvider: null,
|
||||
scene: { setTerrain: (terrain) => calls.push(terrain) },
|
||||
};
|
||||
applyTerrain(viewer, { provider: 'provider' });
|
||||
assert.equal(viewer.terrainProvider, 'provider');
|
||||
applyTerrain(viewer, { terrain: 'terrain' });
|
||||
assert.deepEqual(calls, ['terrain']);
|
||||
assert.equal(viewer.terrainProvider, 'provider');
|
||||
});
|
||||
@@ -62,3 +62,22 @@ export async function createKeylessTerrain() {
|
||||
return { provider: new Cesium.EllipsoidTerrainProvider() };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The terrain source for a session: Cesium World Terrain with an ion token,
|
||||
* otherwise the keyless Re:Earth mesh.
|
||||
* @param {string} [ionToken]
|
||||
* @returns {{ id: 'world' | 'keyless', create: Function }}
|
||||
*/
|
||||
export function terrainSourceFor(ionToken = '') {
|
||||
const token = String(ionToken || '').trim();
|
||||
return token
|
||||
? { id: 'world', create: (request) => createWorldTerrain(token, request) }
|
||||
: { id: 'keyless', create: createKeylessTerrain };
|
||||
}
|
||||
|
||||
/** Install a terrain factory result (`{ terrain }` or `{ provider }`) on a viewer. */
|
||||
export function applyTerrain(viewer, result) {
|
||||
if (result.terrain) viewer.scene.setTerrain(result.terrain);
|
||||
else viewer.terrainProvider = result.provider;
|
||||
}
|
||||
Reference in new issue
Block a user