mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-22 03:02:20 +00:00
Start the application through the contract, not on the Cesium viewer
The application scene takes a renderer plugin and no longer refuses one without a Cesium viewer. It loads the default (Cesium) plugin only when it is given none, so a page on the stub never loads Cesium. - Every layer and tool is handed the application's own scene object (createSceneHost): the container and isDestroyed(), bound to the renderer, the same on Cesium and the stub. - What only Cesium needs at startup is done in its plugin's create: the free-look height limit, and keyboard access to its credits' expand link (creditKeyboard.js moves into the adapter). - What a plugin may hand the application beside the contract goes through provideApplicationHooks, each hook optional: Cesium's map engine, stale command trimming, inline panel rendering, viewerDrawsEntity, the zoom-out guard, and the viewer QA scripts read from window.__godsEyeView. - The map stacks, and the photoreal base the scene loads, switch through the renderer's own map engine (mapEngineFor), else its globe port (globeEngine.js). The Cesium engine takes the scene object and changes the viewer behind it.
This commit is contained in:
1 parent
a72d4c3b1f
commit
6daf63d90c
24 files changed
+825
-241
No files matched your search
@@ -0,0 +1,108 @@
|
||||
import '../testSupport/registerDom.mjs';
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { createApplicationScene } from './scene.js';
|
||||
import { createApplicationRequestServices } from '../services/requests.js';
|
||||
import { createStubRendererPlugin } from '../render/stub/index.js';
|
||||
import { rendererOf } from '../render/rendererOf.js';
|
||||
|
||||
/** Start the scene on a stub renderer with `capabilities`. */
|
||||
async function startOnStub(t, { capabilities = [], ...rest } = {}) {
|
||||
document.body.innerHTML = '<div id="cesiumContainer"></div>';
|
||||
const made = [];
|
||||
const deferred = [];
|
||||
t.after(async () => {
|
||||
for (const fn of deferred.reverse()) await fn();
|
||||
});
|
||||
const scene = await createApplicationScene({
|
||||
renderer: createStubRendererPlugin({ capabilities }, (renderer) =>
|
||||
made.push(renderer),
|
||||
),
|
||||
requestServices: createApplicationRequestServices(),
|
||||
loaderStatus: { textContent: '' },
|
||||
signal: new AbortController().signal,
|
||||
defer: (fn) => deferred.push(fn),
|
||||
...rest,
|
||||
});
|
||||
return { scene, renderer: made[0], deferred };
|
||||
}
|
||||
|
||||
test('the scene runs on a renderer with only the required members', async (t) => {
|
||||
const { scene, renderer, deferred } = await startOnStub(t);
|
||||
assert.equal(scene.renderer, renderer);
|
||||
assert.equal(rendererOf(scene.viewer), renderer, 'the scene object is bound');
|
||||
assert.equal(
|
||||
scene.viewer.container,
|
||||
document.getElementById('cesiumContainer'),
|
||||
);
|
||||
assert.equal(scene.viewer.isDestroyed(), false);
|
||||
assert.ok(
|
||||
scene.viewer.container.contains(renderer.canvas),
|
||||
'the renderer fills the container',
|
||||
);
|
||||
// Nothing of the engine on the scene object.
|
||||
assert.deepEqual(Object.keys(scene.viewer).sort(), [
|
||||
'container',
|
||||
'isDestroyed',
|
||||
]);
|
||||
// No hooks: each is left out, not faked.
|
||||
for (const name of [
|
||||
'trimStaleCommands',
|
||||
'keepPanelRendering',
|
||||
'viewerDrawsEntity',
|
||||
'installZoomOutGuard',
|
||||
'qaHandles',
|
||||
])
|
||||
assert.equal(scene[name], undefined, name);
|
||||
// Keyless, the map stack shows Esri on the globe through the globe port.
|
||||
assert.equal(scene.tileset, null);
|
||||
assert.equal(scene.mapStackController.getActiveId(), 'esri-imagery');
|
||||
const layers = renderer.globe.imagery.list();
|
||||
assert.equal(layers.length, 1, 'one base imagery layer');
|
||||
assert.ok(
|
||||
renderer.testing.calls.some(
|
||||
(call) =>
|
||||
call.port === 'globe' &&
|
||||
call.member === 'imagery.add' &&
|
||||
call.args[0]?.url?.includes('World_Imagery'),
|
||||
),
|
||||
'Esri imagery through the port',
|
||||
);
|
||||
assert.equal(scene.mapStackController.getDrapeSurface(), 'globe');
|
||||
|
||||
// Switching stacks goes through the port too.
|
||||
await scene.mapStackController.setStack('osm');
|
||||
assert.equal(scene.mapStackController.getActiveId(), 'osm');
|
||||
assert.equal(renderer.globe.imagery.list().length, 1, 'Esri gave way');
|
||||
|
||||
for (const fn of deferred.splice(0).reverse()) await fn();
|
||||
assert.equal(scene.viewer.isDestroyed(), true);
|
||||
assert.equal(rendererOf(scene.viewer), null, 'and lets go of the renderer');
|
||||
assert.equal(renderer.globe.imagery.list().length, 0, 'imagery released');
|
||||
});
|
||||
|
||||
test('with credentials, the photoreal base loads through the globe port', async (t) => {
|
||||
const { scene, renderer } = await startOnStub(t, {
|
||||
capabilities: ['photoreal', 'globeVisibility'],
|
||||
googleApiKey: 'stub-key',
|
||||
});
|
||||
assert.ok(scene.tileset, 'a photoreal base');
|
||||
assert.equal(scene.mapStackController.getActiveId(), 'photoreal');
|
||||
assert.equal(renderer.globe.isGlobeVisible(), false, 'the globe is hidden');
|
||||
const photoreal = renderer.testing.calls.filter(
|
||||
(call) => call.port === 'globe' && call.member === 'setPhotoreal',
|
||||
);
|
||||
assert.equal(photoreal[0]?.args[0]?.key, 'stub-key');
|
||||
|
||||
// A globe stack hides photoreal through the port, and shows the globe.
|
||||
await scene.mapStackController.setStack('esri-imagery');
|
||||
assert.equal(renderer.globe.isGlobeVisible(), true);
|
||||
assert.equal(
|
||||
renderer.testing.calls
|
||||
.filter((call) => call.port === 'globe' && call.member === 'setPhotoreal')
|
||||
.at(-1).args[0],
|
||||
null,
|
||||
);
|
||||
await scene.mapStackController.setStack('photoreal');
|
||||
assert.equal(renderer.globe.isGlobeVisible(), false);
|
||||
});
|
||||
Reference in new issue
Block a user