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:
Sameh Khamis committed 2026-11-10 17:18:48 -08:00
1 parent a72d4c3b1f
commit 6daf63d90c
24 files changed
+825 -241

No files matched your search

+33 -16
View File
@@ -2,11 +2,17 @@
* @module render/cesium/mapEngine
* @description The Cesium map engine (`src/maps/engine.js`): the providers
* the map stacks' imagery and terrain come from (`mapImagery.js`,
* `mapTerrain.js`), and the viewer operations the map source controller
* switches stacks with. Provided as this module loads.
* `mapTerrain.js`), the photoreal base the application scene loads
* (`google3d.js`), and the viewer operations the map source controller
* switches stacks with. Each operation takes the scene object: the viewer
* behind it (`viewers.js`) is the one it changes. Provided as this module
* loads, for viewers with no renderer bound, and handed to the application
* with each renderer the plugin makes (`appRenderer.js`).
*/
import * as Cesium from 'cesium';
import { provideMapEngine } from '../../maps/engine.js';
import { loadPhotorealisticTileset } from './google3d.js';
import { viewerBehind } from './viewers.js';
import {
createEsriImagery,
createIonImagery,
@@ -27,33 +33,35 @@ export const cesiumMapEngine = Object.freeze({
}),
/** The layer a globe stack's imagery provider draws through. */
createImageryLayer: (provider) => new Cesium.ImageryLayer(provider),
requestRender(viewer) {
viewer?.scene?.requestRender?.();
requestRender(host) {
viewerBehind(host)?.scene?.requestRender?.();
},
globeShown: (viewer) => viewer?.scene?.globe?.show === true,
setGlobeShown(viewer, shown) {
viewer.scene.globe.show = shown;
globeShown: (host) => viewerBehind(host)?.scene?.globe?.show === true,
setGlobeShown(host, shown) {
viewerBehind(host).scene.globe.show = shown;
},
addTileset(viewer, tileset) {
viewer.scene.primitives.add(tileset);
addTileset(host, tileset) {
viewerBehind(host).scene.primitives.add(tileset);
},
removeTileset(viewer, tileset) {
viewer.scene.primitives.remove(tileset);
/** Removed, which destroys it. */
removeTileset(host, tileset) {
viewerBehind(host).scene.primitives.remove(tileset);
},
tilesetShown: (tileset) => tileset?.show === true,
showTileset(tileset, shown) {
tileset.show = shown;
},
/** Below every other imagery layer, at `index`. */
addImageryLayer(viewer, layer, index) {
viewer.imageryLayers.add(layer, index);
addImageryLayer(host, layer, index) {
viewerBehind(host).imageryLayers.add(layer, index);
},
/** Removed and destroyed. */
removeImageryLayer(viewer, layer) {
viewer.imageryLayers.remove(layer, true);
removeImageryLayer(host, layer) {
viewerBehind(host).imageryLayers.remove(layer, true);
},
/** A terrain factory's result: `{terrain}` or `{provider}`. */
applyTerrain(viewer, result) {
applyTerrain(host, result) {
const viewer = viewerBehind(host);
if (result.terrain) viewer.scene.setTerrain(result.terrain);
else viewer.terrainProvider = result.provider;
},
@@ -75,6 +83,15 @@ export const cesiumMapEngine = Object.freeze({
if (typeof value?.destroy === 'function' && !value.isDestroyed?.())
value.destroy();
},
/**
* Load Google Photorealistic 3D Tiles by the best route the credentials
* allow (`google3d.js`); the tileset is not yet drawn.
* @param {object} host
* @param {{googleApiKey?: string, googleTokens?: object|null, cesiumToken?: string}} credentials
* @returns {Promise<{tileset: object|null, route: string, errors: Error[]}>}
*/
loadPhotoreal: (host, credentials) =>
loadPhotorealisticTileset(Cesium, credentials),
});
provideMapEngine(cesiumMapEngine);