mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +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,123 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { globeMapEngine as engine } from './globeEngine.js';
|
||||
import { mapEngineFor, provideMapEngine } from './engine.js';
|
||||
import { bindRenderer } from '../render/rendererOf.js';
|
||||
import { provideApplicationHooks } from '../render/applicationHooks.js';
|
||||
import { createStubRenderer } from '../render/stub/index.js';
|
||||
|
||||
function scene(capabilities) {
|
||||
const renderer = createStubRenderer(capabilities ? { capabilities } : {});
|
||||
const host = {};
|
||||
bindRenderer(host, renderer);
|
||||
return { host, renderer };
|
||||
}
|
||||
|
||||
const calls = (renderer, member) =>
|
||||
renderer.testing.calls.filter(
|
||||
(call) => call.port === 'globe' && call.member === member,
|
||||
);
|
||||
|
||||
test('a renderer without a map engine of its own switches through its globe port', () => {
|
||||
const { host, renderer } = scene();
|
||||
assert.equal(mapEngineFor(host), engine);
|
||||
const own = { own: true };
|
||||
provideApplicationHooks(renderer, { mapEngine: own });
|
||||
assert.equal(mapEngineFor(host), own, "the plugin's own comes first");
|
||||
const provided = { provided: true };
|
||||
provideMapEngine(provided);
|
||||
assert.equal(mapEngineFor({}), provided, 'a viewer with no renderer');
|
||||
});
|
||||
|
||||
test('imagery layers go through the port, lowest first, and come off again', () => {
|
||||
const { host, renderer } = scene();
|
||||
const spec = engine.imagery.esri();
|
||||
assert.equal(spec.kind, 'xyz');
|
||||
assert.match(
|
||||
spec.url,
|
||||
/World_Imagery\/MapServer\/tile\/\{z\}\/\{y\}\/\{x\}$/,
|
||||
);
|
||||
const layer = engine.createImageryLayer(spec);
|
||||
engine.addImageryLayer(host, layer, 0);
|
||||
assert.deepEqual(calls(renderer, 'imagery.add')[0].args, [spec, 0]);
|
||||
assert.equal(renderer.globe.imagery.list().length, 1);
|
||||
let errors = 0;
|
||||
const off = engine.onTileError(spec, () => (errors += 1));
|
||||
assert.equal(typeof off, 'function', 'tile errors are heard');
|
||||
off();
|
||||
engine.removeImageryLayer(host, layer);
|
||||
assert.equal(renderer.globe.imagery.list().length, 0);
|
||||
assert.equal(
|
||||
engine.onTileError(spec, () => {}),
|
||||
null,
|
||||
'none once removed',
|
||||
);
|
||||
assert.equal(errors, 0);
|
||||
});
|
||||
|
||||
test('the globe is shown and hidden through the port, read back without globe visibility', () => {
|
||||
const { host, renderer } = scene([]);
|
||||
assert.equal(engine.globeShown(host), true);
|
||||
engine.setGlobeShown(host, false);
|
||||
assert.equal(engine.globeShown(host), false);
|
||||
assert.deepEqual(calls(renderer, 'setGlobeVisible').at(-1).args, [false]);
|
||||
const visible = scene(['globeVisibility']);
|
||||
engine.setGlobeShown(visible.host, false);
|
||||
assert.equal(visible.renderer.globe.isGlobeVisible(), false);
|
||||
assert.equal(engine.globeShown(visible.host), false);
|
||||
});
|
||||
|
||||
test('terrain is the port’s world terrain, or the ellipsoid without a token', async () => {
|
||||
const { host, renderer } = scene();
|
||||
await assert.rejects(engine.terrain.world(''), /ion token/);
|
||||
const world = await engine.terrain.world('token');
|
||||
engine.applyTerrain(host, world);
|
||||
assert.deepEqual(calls(renderer, 'setTerrain').at(-1).args, [
|
||||
{ kind: 'world', requestVertexNormals: true },
|
||||
]);
|
||||
engine.applyTerrain(host, await engine.terrain.keyless());
|
||||
assert.deepEqual(calls(renderer, 'setTerrain').at(-1).args, [
|
||||
{ kind: 'ellipsoid' },
|
||||
]);
|
||||
assert.throws(() => engine.imagery.ion(2, ''), /token/);
|
||||
assert.deepEqual(engine.imagery.ion(3, 'token'), {
|
||||
kind: 'world',
|
||||
worldStyle: 'aerialLabels',
|
||||
});
|
||||
});
|
||||
|
||||
test('photoreal loads through the port, hides and shows, and is released', async () => {
|
||||
const { host, renderer } = scene(['photoreal']);
|
||||
const none = await engine.loadPhotoreal(host, {});
|
||||
assert.deepEqual(none, { tileset: null, route: 'none', errors: [] });
|
||||
assert.equal(calls(renderer, 'setPhotoreal').length, 0, 'no credentials');
|
||||
|
||||
const tokens = { token: async () => 'session' };
|
||||
const loaded = await engine.loadPhotoreal(host, { googleTokens: tokens });
|
||||
assert.equal(loaded.route, 'google');
|
||||
const handle = loaded.tileset;
|
||||
assert.equal(engine.tilesetShown(handle), true);
|
||||
const spec = calls(renderer, 'setPhotoreal')[0].args[0];
|
||||
assert.equal(spec.provider, 'google');
|
||||
assert.equal(await spec.token(), 'session');
|
||||
assert.equal(spec.fallback, false);
|
||||
|
||||
engine.showTileset(handle, false);
|
||||
assert.equal(engine.tilesetShown(handle), false);
|
||||
assert.equal(calls(renderer, 'setPhotoreal').at(-1).args[0], null);
|
||||
engine.showTileset(handle, true);
|
||||
assert.equal(calls(renderer, 'setPhotoreal').at(-1).args[0], spec);
|
||||
engine.release(handle);
|
||||
assert.equal(engine.isDestroyed(handle), true);
|
||||
assert.equal(calls(renderer, 'setPhotoreal').at(-1).args[0], null);
|
||||
const count = calls(renderer, 'setPhotoreal').length;
|
||||
engine.showTileset(handle, true);
|
||||
assert.equal(calls(renderer, 'setPhotoreal').length, count, 'never again');
|
||||
});
|
||||
|
||||
test('a renderer without photoreal reports none, with the reason it gave', async () => {
|
||||
const { host } = scene([]);
|
||||
const result = await engine.loadPhotoreal(host, { googleApiKey: 'key' });
|
||||
assert.equal(result.tileset, null);
|
||||
assert.equal(result.route, 'none');
|
||||
});
|
||||
Reference in new issue
Block a user