mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
- The standalone page starts loading the default renderer as it starts (loadDefaultRenderer), so Cesium arrives beside the page's own setup, not after it; the scene takes a plugin or a promise of one. - Where a follow target's layer has no display position yet, the followed position is the target's own position at the frame port's scene time. - The globe engine's photoreal base that fails to come back is off again and the globe shown; a later switch tries again. The draped-imagery host asks the map engine whether the globe is shown where the renderer cannot say. The scene resizes the renderer with its container. - Cockpit and voice tests follow through the camera port (followEntity), not by setting the viewer's tracked entity; the fake frame port has a scene time.
155 lines
6.0 KiB
JavaScript
155 lines
6.0 KiB
JavaScript
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');
|
||
});
|
||
|
||
test('photoreal that fails to come back leaves the globe shown, and is tried again', async () => {
|
||
const { host, renderer } = scene(['photoreal']);
|
||
const loaded = await engine.loadPhotoreal(host, { googleApiKey: 'key' });
|
||
const handle = loaded.tileset;
|
||
engine.showTileset(handle, false);
|
||
engine.setGlobeShown(host, false);
|
||
// The port cannot draw photoreal any more.
|
||
renderer.globe.setPhotoreal = async (spec) => ({
|
||
route: 'none',
|
||
error: { code: 'refused', message: 'refused' },
|
||
spec,
|
||
});
|
||
const warn = console.warn;
|
||
console.warn = () => {};
|
||
try {
|
||
engine.showTileset(handle, true);
|
||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||
} finally {
|
||
console.warn = warn;
|
||
}
|
||
assert.equal(engine.tilesetShown(handle), false, 'off again');
|
||
assert.equal(engine.globeShown(host), true, 'the base is not blank');
|
||
let tried = 0;
|
||
renderer.globe.setPhotoreal = async () => {
|
||
tried += 1;
|
||
return { route: 'google' };
|
||
};
|
||
engine.showTileset(handle, true);
|
||
assert.equal(tried, 1, 'a later switch tries again');
|
||
});
|