mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Map stacks off the Cesium allow-list: providers move into the Cesium adapter
The map stacks' imagery, terrain and Google 3D factories move into the Cesium adapter (src/render/cesium/mapImagery.js, mapTerrain.js, google3d.js); the ./maps/imagery, ./maps/terrain and ./maps/3d exports point there. The catalog names its ion stacks by asset number, and the map source controller and default sources are Cesium-free: they build providers and switch imagery layers, terrain, tilesets and the globe's visibility through a map engine (src/maps/engine.js) that the Cesium adapter provides as it loads (mapEngine.js), through the application's renderer or the ./render/cesium/unbound export. The controller and createDefaultMapSources also take it as an `engine` option. src/maps/catalog.js, controller.js, imagery.js, terrain.js and google3d.js leave the allow-list.
This commit is contained in:
1 parent
aea5c3acc6
commit
a8a9cc73a4
31 files changed
+364
-140
No files matched your search
+73
-62
@@ -1,10 +1,7 @@
|
||||
import { indexMapSources } from './registry.js';
|
||||
import * as Cesium from 'cesium';
|
||||
import { createMapCredits } from './credits.js';
|
||||
// A viewer of a caller's own gets its credits port (and camera) from the
|
||||
// factories this loads.
|
||||
import '../render/cesium/camera.js';
|
||||
import { markBaseTileset } from '../render/cesium/globe.js';
|
||||
import { mapEngine } from './engine.js';
|
||||
import { markBaseTileset } from '../render/baseTilesets.js';
|
||||
import { acquireImageryComparison } from './imageryComparison.js';
|
||||
|
||||
/**
|
||||
@@ -25,7 +22,12 @@ const resolved = (provider, effectiveStackId) => ({
|
||||
fallbackMessage: null,
|
||||
});
|
||||
|
||||
/** Coordinate source lifetimes and scene changes; the registry owns provider choices. */
|
||||
/**
|
||||
* Coordinate source lifetimes and scene changes; the registry owns provider
|
||||
* choices. The scene changes go through the renderer's map engine
|
||||
* (`engine.js`), which a viewer with no renderer bound gets once its owner
|
||||
* has loaded the package's `./render/cesium/unbound` export.
|
||||
*/
|
||||
export class MapSourceController {
|
||||
constructor(
|
||||
viewer,
|
||||
@@ -34,11 +36,13 @@ export class MapSourceController {
|
||||
initialStack,
|
||||
onChange = null,
|
||||
onError = null,
|
||||
requestRender = () => viewer?.scene?.requestRender?.(),
|
||||
createImageryLayer = (provider) => new Cesium.ImageryLayer(provider),
|
||||
engine = mapEngine(),
|
||||
requestRender = () => engine.requestRender(viewer),
|
||||
createImageryLayer = (provider) => engine.createImageryLayer(provider),
|
||||
},
|
||||
) {
|
||||
this.viewer = viewer;
|
||||
this._engine = engine;
|
||||
this._registry = registry;
|
||||
this._sources = indexMapSources(registry.sources);
|
||||
this._activeId = this.isStackAvailable(initialStack)
|
||||
@@ -110,10 +114,11 @@ export class MapSourceController {
|
||||
/** Return the shown supplied or controller-owned tileset, if any. */
|
||||
getImageryHostTileset() {
|
||||
if (this._destroyed) return null;
|
||||
const shown = this._engine.tilesetShown;
|
||||
for (const source of this._sources.values())
|
||||
if (source.tileset?.show === true) return source.tileset;
|
||||
if (shown(source.tileset)) return source.tileset;
|
||||
for (const tileset of this._ownedTilesets)
|
||||
if (tileset.show === true) return tileset;
|
||||
if (shown(tileset)) return tileset;
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
@@ -124,9 +129,9 @@ export class MapSourceController {
|
||||
*/
|
||||
getDrapeSurface() {
|
||||
if (this._destroyed) return null;
|
||||
if (this.viewer?.scene?.globe?.show === true) return 'globe';
|
||||
if (this._engine.globeShown(this.viewer)) return 'globe';
|
||||
const tileset = this.getImageryHostTileset();
|
||||
return tileset && !tileset.isDestroyed?.() ? 'tileset' : 'none';
|
||||
return tileset && !this._engine.isDestroyed(tileset) ? 'tileset' : 'none';
|
||||
}
|
||||
getActiveId() {
|
||||
return this._activeId;
|
||||
@@ -285,23 +290,24 @@ export class MapSourceController {
|
||||
}
|
||||
if (gen !== this._switchGen) return;
|
||||
if (!source.tileset && !this._ownedTilesets.has(tileset)) {
|
||||
tileset.show = false;
|
||||
this._engine.showTileset(tileset, false);
|
||||
markBaseTileset(tileset);
|
||||
this.viewer.scene.primitives.add(tileset);
|
||||
this._engine.addTileset(this.viewer, tileset);
|
||||
this._ownedTilesets.add(tileset);
|
||||
}
|
||||
this._removeImageryLayer();
|
||||
this._credits.show(source.credit || null);
|
||||
this._showTileset(tileset);
|
||||
this.viewer.scene.globe.show = false;
|
||||
this._engine.setGlobeShown(this.viewer, false);
|
||||
// Terrain is intentionally untouched while the globe is hidden.
|
||||
}
|
||||
|
||||
_showTileset(active) {
|
||||
const show = this._engine.showTileset;
|
||||
for (const source of this._sources.values())
|
||||
if (source.tileset) source.tileset.show = source.tileset === active;
|
||||
if (source.tileset) show(source.tileset, source.tileset === active);
|
||||
for (const tileset of this._ownedTilesets)
|
||||
tileset.show = tileset === active;
|
||||
show(tileset, tileset === active);
|
||||
}
|
||||
|
||||
async _activateGlobeStack(stack, gen) {
|
||||
@@ -317,7 +323,7 @@ export class MapSourceController {
|
||||
this._removeImageryLayer();
|
||||
this._imageryLayer = this._createImageryLayer(resolution.provider);
|
||||
this._activeImageryProvider = resolution.provider;
|
||||
this.viewer.imageryLayers.add(this._imageryLayer, 0);
|
||||
this._engine.addImageryLayer(this.viewer, this._imageryLayer, 0);
|
||||
}
|
||||
const source = this._sources.get(resolution.effectiveStackId);
|
||||
this._credits.show(source?.credit || null);
|
||||
@@ -327,7 +333,7 @@ export class MapSourceController {
|
||||
this._removeImageryErrorListener = null;
|
||||
this._watchProvider(resolution, gen);
|
||||
this._showTileset(null);
|
||||
this.viewer.scene.globe.show = true;
|
||||
this._engine.setGlobeShown(this.viewer, true);
|
||||
this._activeId = resolution.effectiveStackId;
|
||||
this._activeResolution = resolution;
|
||||
if (source?.terrain && source.terrain.id !== this._terrainMode) {
|
||||
@@ -349,8 +355,7 @@ export class MapSourceController {
|
||||
}
|
||||
|
||||
_applyTerrain(result) {
|
||||
if (result.terrain) this.viewer.scene.setTerrain(result.terrain);
|
||||
else this.viewer.terrainProvider = result.provider;
|
||||
this._engine.applyTerrain(this.viewer, result);
|
||||
this._terrainFallback = result.fallback ? result : null;
|
||||
if (this._replacedTerrain && this._replacedTerrain !== result) {
|
||||
this._dispose(this._replacedTerrain.provider);
|
||||
@@ -379,7 +384,9 @@ export class MapSourceController {
|
||||
|
||||
async _retryFallbacks() {
|
||||
const resolution = this._activeResolution;
|
||||
const flat = this.viewer.scene.globe.show ? this._terrainFallback : null;
|
||||
const flat = this._engine.globeShown(this.viewer)
|
||||
? this._terrainFallback
|
||||
: null;
|
||||
const id = resolution?.fallbackFor;
|
||||
let terrain = flat && this._sources.get(this._activeId)?.terrain;
|
||||
if (terrain?.id !== this._terrainMode) terrain = null;
|
||||
@@ -460,7 +467,10 @@ export class MapSourceController {
|
||||
return Boolean(real && !real.fallback);
|
||||
}
|
||||
this._terrainProviders.set(terrain.id, Promise.resolve(real));
|
||||
if (this._terrainFallback === flat && this.viewer.scene.globe.show) {
|
||||
if (
|
||||
this._terrainFallback === flat &&
|
||||
this._engine.globeShown(this.viewer)
|
||||
) {
|
||||
this._applyTerrain(real);
|
||||
this._dispose(flat.provider);
|
||||
this._requestRender('map-stack');
|
||||
@@ -540,50 +550,52 @@ export class MapSourceController {
|
||||
const fallback = this._sources.get(
|
||||
resolution.effectiveStackId,
|
||||
)?.tileFailureFallback;
|
||||
const errorEvent = resolution.provider?.errorEvent;
|
||||
if (!fallback || !errorEvent?.addEventListener) return;
|
||||
if (!fallback) return;
|
||||
let failures = 0;
|
||||
let pending = false;
|
||||
this._removeImageryErrorListener = errorEvent.addEventListener((error) => {
|
||||
if (
|
||||
gen !== this._switchGen ||
|
||||
this._activeImageryProvider !== resolution.provider
|
||||
)
|
||||
return;
|
||||
const retryCount = Number(error?.timesRetried);
|
||||
failures =
|
||||
Number.isInteger(retryCount) && retryCount >= 0
|
||||
? Math.max(failures + 1, retryCount + 1)
|
||||
: failures + 1;
|
||||
if (failures < fallback.threshold || pending) return;
|
||||
pending = true;
|
||||
this._onError?.(
|
||||
fallback.message,
|
||||
this.getStack(resolution.effectiveStackId),
|
||||
);
|
||||
const expectedGen = this._switchGen + 1;
|
||||
void this.setStack(fallback.id, { silent: true, [AUTOMATIC]: true })
|
||||
.then((state) => {
|
||||
if (
|
||||
!this._destroyed &&
|
||||
this._switchGen === expectedGen &&
|
||||
state?.activeId === fallback.id
|
||||
) {
|
||||
this._lastError = fallback.message;
|
||||
this._emitChange('error');
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
pending = false;
|
||||
});
|
||||
});
|
||||
this._removeImageryErrorListener = this._engine.onTileError(
|
||||
resolution.provider,
|
||||
(error) => {
|
||||
if (
|
||||
gen !== this._switchGen ||
|
||||
this._activeImageryProvider !== resolution.provider
|
||||
)
|
||||
return;
|
||||
const retryCount = Number(error?.timesRetried);
|
||||
failures =
|
||||
Number.isInteger(retryCount) && retryCount >= 0
|
||||
? Math.max(failures + 1, retryCount + 1)
|
||||
: failures + 1;
|
||||
if (failures < fallback.threshold || pending) return;
|
||||
pending = true;
|
||||
this._onError?.(
|
||||
fallback.message,
|
||||
this.getStack(resolution.effectiveStackId),
|
||||
);
|
||||
const expectedGen = this._switchGen + 1;
|
||||
void this.setStack(fallback.id, { silent: true, [AUTOMATIC]: true })
|
||||
.then((state) => {
|
||||
if (
|
||||
!this._destroyed &&
|
||||
this._switchGen === expectedGen &&
|
||||
state?.activeId === fallback.id
|
||||
) {
|
||||
this._lastError = fallback.message;
|
||||
this._emitChange('error');
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
pending = false;
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
_removeImageryLayer() {
|
||||
this._removeImageryErrorListener?.();
|
||||
this._removeImageryErrorListener = null;
|
||||
if (this._imageryLayer)
|
||||
this.viewer.imageryLayers.remove(this._imageryLayer, true);
|
||||
this._engine.removeImageryLayer(this.viewer, this._imageryLayer);
|
||||
this._imageryLayer = null;
|
||||
this._activeImageryProvider = null;
|
||||
this._activeResolution = null;
|
||||
@@ -591,8 +603,7 @@ export class MapSourceController {
|
||||
_dispose(value) {
|
||||
if (!value || this._disposed.has(value)) return;
|
||||
this._disposed.add(value);
|
||||
if (typeof value.destroy === 'function' && !value.isDestroyed?.())
|
||||
value.destroy();
|
||||
this._engine.release(value);
|
||||
}
|
||||
destroy() {
|
||||
if (this._destroyed) return;
|
||||
@@ -620,7 +631,7 @@ export class MapSourceController {
|
||||
() => {},
|
||||
);
|
||||
for (const tileset of this._ownedTilesets) {
|
||||
this.viewer.scene.primitives.remove(tileset);
|
||||
this._engine.removeTileset(this.viewer, tileset);
|
||||
this._dispose(tileset);
|
||||
}
|
||||
for (const promise of this._tilesets.values())
|
||||
|
||||
Reference in new issue
Block a user