mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Add a globe visibility getter to the renderer contract
The globe port could show or hide the globe surface but not say whether it is shown. It now has an optional isGlobeVisible(), gated by a new globeVisibility capability, in the Cesium adapter, the stub and a conformance check. A Cesium scene without a globe does not offer it, so callers keep their own default for an unknown surface. The OSM overlays, the CCTV ground regime and the submarine cable drape now read the getter instead of the scene's globe. cableClassificationTypeForScene takes the viewer rather than its scene.
This commit is contained in:
1 parent
23d56f8393
commit
2e91579f8f
23 files changed
+140
-29
No files matched your search
@@ -438,6 +438,8 @@ export function createCesiumGlobe(
|
||||
return progressListeners.on(cb);
|
||||
},
|
||||
};
|
||||
if (can('globeVisibility'))
|
||||
port.isGlobeVisible = () => scene.globe?.show === true;
|
||||
if (can('splitSwipe')) {
|
||||
// Cesium's split starts at the canvas's left edge, as the scene was
|
||||
// made: a `left` layer shows once the split moves.
|
||||
@@ -469,8 +471,13 @@ export function createCesiumGlobe(
|
||||
// built over it: imagery and the sky as the renderer's would.
|
||||
provideUnboundGlobe((viewer) => {
|
||||
if (!viewer?.scene) return null;
|
||||
// Visibility reads back only from a globe that keeps it: a scene made
|
||||
// without one gives no reading, so its callers keep their own default.
|
||||
const capabilities = new Set(['imageHooks', 'imageryOnTiles', 'splitSwipe']);
|
||||
if (typeof viewer.scene.globe?.show === 'boolean')
|
||||
capabilities.add('globeVisibility');
|
||||
const { port, dispose } = createCesiumGlobe(viewer, {
|
||||
capabilities: new Set(['imageHooks', 'imageryOnTiles', 'splitSwipe']),
|
||||
capabilities,
|
||||
requestRender: () => viewer.scene.requestRender?.(),
|
||||
});
|
||||
// A renderer bound later leaves it running: its layers keep following
|
||||
|
||||
@@ -4,7 +4,13 @@ import * as Cesium from 'cesium';
|
||||
import { createCesiumGlobe, markBaseTileset } from './globe.js';
|
||||
import { hookProvider, TILE_RETRY_DELAY_MS, xyzTileUrl } from './imagery.js';
|
||||
|
||||
const ALL = new Set(['imageHooks', 'imageryOnTiles', 'splitSwipe', 'terrain']);
|
||||
const ALL = new Set([
|
||||
'imageHooks',
|
||||
'imageryOnTiles',
|
||||
'splitSwipe',
|
||||
'terrain',
|
||||
'globeVisibility',
|
||||
]);
|
||||
const url = (name) => `https://${name}.invalid/{z}/{x}/{y}.png`;
|
||||
|
||||
function fakeScene() {
|
||||
@@ -458,8 +464,14 @@ test('globe visibility, settling and progress', () => {
|
||||
const { scene, port, tick } = setup();
|
||||
port.setGlobeVisible(false);
|
||||
assert.equal(scene.globe.show, false);
|
||||
assert.equal(port.isGlobeVisible(), false);
|
||||
assert.equal(port.isSettled('terrain'), true, 'a hidden globe loads nothing');
|
||||
port.setGlobeVisible(true);
|
||||
assert.equal(port.isGlobeVisible(), true);
|
||||
// It reads the scene, whoever changed it.
|
||||
scene.globe.show = false;
|
||||
assert.equal(port.isGlobeVisible(), false);
|
||||
scene.globe.show = true;
|
||||
scene.globe.tilesLoaded = false;
|
||||
assert.equal(port.isSettled('terrain'), false);
|
||||
assert.equal(port.isSettled('base'), false);
|
||||
|
||||
@@ -69,6 +69,7 @@ export const CESIUM_CHECKS = new Set([
|
||||
'globe.imagery',
|
||||
'globe.sky',
|
||||
'globe.split',
|
||||
'globe.visible',
|
||||
'globe.withoutImageHooks',
|
||||
'input.behaviours',
|
||||
'input.clickPick',
|
||||
|
||||
@@ -44,6 +44,7 @@ const GLOBE_CAPABILITIES = [
|
||||
'imageryOnTiles',
|
||||
'splitSwipe',
|
||||
'imageHooks',
|
||||
'globeVisibility',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -67,7 +68,13 @@ export function cesiumCapabilities(scene, only) {
|
||||
...queryCapabilities(scene),
|
||||
];
|
||||
const allowed = only && new Set(only);
|
||||
return all.filter((c) => !allowed || allowed.has(c));
|
||||
return all.filter(
|
||||
(c) =>
|
||||
(!allowed || allowed.has(c)) &&
|
||||
// Visibility reads back only from a globe that keeps it: a scene
|
||||
// made without one gives no reading.
|
||||
(c !== 'globeVisibility' || typeof scene?.globe?.show === 'boolean'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,7 +22,14 @@ test('capabilities follow what the scene supports', () => {
|
||||
'splitSwipe',
|
||||
'imageHooks',
|
||||
];
|
||||
const globe = { show: true };
|
||||
assert.deepEqual(cesiumCapabilities({}), ['models', ...effects]);
|
||||
// A scene with a globe reads its visibility back.
|
||||
assert.deepEqual(cesiumCapabilities({ globe }), [
|
||||
'models',
|
||||
...effects,
|
||||
'globeVisibility',
|
||||
]);
|
||||
assert.deepEqual(cesiumCapabilities({ pickPositionSupported: true }), [
|
||||
'models',
|
||||
...effects,
|
||||
@@ -30,12 +37,14 @@ test('capabilities follow what the scene supports', () => {
|
||||
]);
|
||||
assert.deepEqual(
|
||||
cesiumCapabilities({
|
||||
globe,
|
||||
pickPositionSupported: true,
|
||||
sampleHeightSupported: true,
|
||||
}),
|
||||
[
|
||||
'models',
|
||||
...effects,
|
||||
'globeVisibility',
|
||||
'pickPosition',
|
||||
'sampleHeight',
|
||||
'finestHeights',
|
||||
|
||||
@@ -2,10 +2,11 @@
|
||||
* @module render/cesium/unbound
|
||||
* @description What to load, once, before handing the Cesium-free
|
||||
* layers a Cesium viewer with no renderer bound: the factories
|
||||
* that build a camera, credits, effects, draw, frame and query port over
|
||||
* that build a camera, credits, effects, draw, frame, globe and query port over
|
||||
* such a viewer when code first asks for one (`rendererOf.js`).
|
||||
*/
|
||||
import './camera.js';
|
||||
import './effects.js';
|
||||
import './frame.js';
|
||||
import './globe.js';
|
||||
import './query.js';
|
||||
@@ -2617,6 +2617,17 @@ export function portChecks() {
|
||||
},
|
||||
{ capability: 'splitSwipe' },
|
||||
),
|
||||
check(
|
||||
'globe.visible',
|
||||
'the globe surface reads back as it was shown or hidden',
|
||||
(h, r) => {
|
||||
r.globe.setGlobeVisible(false);
|
||||
equal(r.globe.isGlobeVisible(), false, 'hidden');
|
||||
r.globe.setGlobeVisible(true);
|
||||
equal(r.globe.isGlobeVisible(), true, 'shown');
|
||||
},
|
||||
{ capability: 'globeVisibility' },
|
||||
),
|
||||
check(
|
||||
'globe.sky',
|
||||
'sky settings round-trip and keep unchanged keys',
|
||||
|
||||
Vendored
+2
@@ -206,5 +206,7 @@ export type Capability =
|
||||
| 'sharpen'
|
||||
/** Following with an automatically chosen frame (orbit or north-up). */
|
||||
| 'followAutodetect'
|
||||
/** Reading back whether the globe surface is shown (`globe.isGlobeVisible`). */
|
||||
| 'globeVisibility'
|
||||
/** A built-in quality benchmark. */
|
||||
| 'benchmark';
|
||||
Vendored
+7
@@ -258,6 +258,13 @@ export interface GlobePort {
|
||||
setTerrain(spec: TerrainSpec | null): Promise<void>;
|
||||
/** Show or hide the globe surface (hidden under photoreal). */
|
||||
setGlobeVisible(visible: boolean): void;
|
||||
/**
|
||||
* `globeVisibility`: whether the globe surface is shown now, as
|
||||
* `setGlobeVisible` or whoever last set it left it. For code that only holds
|
||||
* the scene and must know whether the surface it drapes on or samples is
|
||||
* drawn.
|
||||
*/
|
||||
isGlobeVisible?(): boolean;
|
||||
/** `surfaceShading`. */
|
||||
setSurfaceShading?(shading: SurfaceShading | null): void;
|
||||
/** `clouds`: the renderer's volumetric clouds, or none. */
|
||||
|
||||
@@ -46,6 +46,7 @@ export const CAPABILITIES = Object.freeze([
|
||||
'bloom',
|
||||
'sharpen',
|
||||
'followAutodetect',
|
||||
'globeVisibility',
|
||||
'benchmark',
|
||||
]);
|
||||
|
||||
@@ -147,6 +148,7 @@ export const PORTS = deepFreeze({
|
||||
'isSettled',
|
||||
'on',
|
||||
),
|
||||
['isGlobeVisible', 'globeVisibility'],
|
||||
['setSurfaceShading', 'surfaceShading'],
|
||||
['setClouds', 'clouds'],
|
||||
['setWater', 'water'],
|
||||
|
||||
@@ -917,6 +917,7 @@ export function createStubRenderer(options = {}) {
|
||||
...(options.sky ?? {}),
|
||||
};
|
||||
let photorealStatus = { route: 'none' };
|
||||
let globeVisible = true;
|
||||
|
||||
function addImagery(spec, index) {
|
||||
if (
|
||||
@@ -1055,6 +1056,7 @@ export function createStubRenderer(options = {}) {
|
||||
},
|
||||
setGlobeVisible(visible) {
|
||||
log('globe', 'setGlobeVisible', [visible]);
|
||||
globeVisible = Boolean(visible);
|
||||
requestRender('base');
|
||||
},
|
||||
imagery: {
|
||||
@@ -1078,6 +1080,8 @@ export function createStubRenderer(options = {}) {
|
||||
};
|
||||
},
|
||||
};
|
||||
if (capabilities.has('globeVisibility'))
|
||||
globe.isGlobeVisible = () => globeVisible;
|
||||
if (capabilities.has('surfaceShading'))
|
||||
globe.setSurfaceShading = (shading) => {
|
||||
log('globe', 'setSurfaceShading', [shading]);
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
* builds `findCredits`' port for such a viewer the same way.
|
||||
* Likewise an entry that reaches a caller of `findEffects` must load
|
||||
* `render/cesium/effects.js`, which provides the effects factory, and one
|
||||
* that reaches a caller of `findGlobe` must load `render/cesium/globe.js`.
|
||||
* that reaches a caller of `findGlobe` must load `render/cesium/globe.js`,
|
||||
* or be such a Cesium-free entry (below).
|
||||
* An entry that reaches a caller of `findDraw` or `drawOf` loads
|
||||
* `render/cesium/draw.js` the same way (the camera factory loads it),
|
||||
* unless it is Cesium-free: then it is listed in `DRAW_FROM_CALLER`, and
|
||||
@@ -287,8 +288,10 @@ test('every public entry that reaches a findEffects caller loads the unbound eff
|
||||
|
||||
test('every public entry that reaches a findGlobe caller loads the unbound globe factory', () => {
|
||||
// A caller may take `findGlobe` as a default rather than call it, so any
|
||||
// use of the name counts.
|
||||
checkLookupFactory('findGlobe', GLOBE_FACTORY);
|
||||
// use of the name counts. A Cesium-free entry with no globe port (its
|
||||
// caller has not loaded `./render/cesium/unbound`) reads the globe as
|
||||
// unknown.
|
||||
checkLookupFactory('findGlobe', GLOBE_FACTORY, { fromCaller: true });
|
||||
});
|
||||
|
||||
test('every public entry that reaches a findQuery or queryOf caller loads the unbound query factory, or its caller can', () => {
|
||||
|
||||
Reference in new issue
Block a user