mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Retain live flights and earthquake observations across globe switches
This commit is contained in:
1 parent
a0e5f04c30
commit
c0062c4d3d
17 files changed
+428
-66
No files matched your search
+33
-11
@@ -66,6 +66,7 @@ export function createApplicationCatalog({
|
||||
metadata = APPLICATION_LAYER_METADATA,
|
||||
vesselOptions,
|
||||
resolveAsset,
|
||||
layerSession,
|
||||
nepalBoundaryResolver,
|
||||
streetLevelProviders,
|
||||
engineKind = 'cesium',
|
||||
@@ -79,30 +80,48 @@ export function createApplicationCatalog({
|
||||
|
||||
const sourceComposition = resolveCatalogSources(sources);
|
||||
sources = sourceComposition.sources;
|
||||
const militaryRegistry = createMilitaryRegistry();
|
||||
const militaryRegistry =
|
||||
layerSession?.militaryRegistry ?? createMilitaryRegistry();
|
||||
const weatherClock = createWeatherClock();
|
||||
const dispose = () => {
|
||||
signal.removeEventListener('abort', dispose);
|
||||
militaryRegistry.dispose();
|
||||
if (!layerSession) militaryRegistry.dispose();
|
||||
weatherClock.destroy();
|
||||
};
|
||||
signal.addEventListener('abort', dispose, { once: true });
|
||||
try {
|
||||
if (sourceComposition.isConfigured('military'))
|
||||
militaryRegistry.configureSource(sources.military, { signal });
|
||||
if (!layerSession?.militaryRegistry) {
|
||||
const lifetime = layerSession?.lifetime.signal ?? signal;
|
||||
if (sourceComposition.isConfigured('military'))
|
||||
militaryRegistry.configureSource(sources.military, { signal: lifetime });
|
||||
if (layerSession) {
|
||||
layerSession.militaryRegistry = militaryRegistry;
|
||||
lifetime.addEventListener('abort', militaryRegistry.dispose, {
|
||||
once: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
// Shared instances (awareness and launches read others) are made once,
|
||||
// when the first layer that needs them is built.
|
||||
const once = (create) => {
|
||||
let value;
|
||||
return () => (value ??= create());
|
||||
};
|
||||
const sessionModel = (id, create) => {
|
||||
if (!layerSession) return create();
|
||||
const models = (layerSession.models ??= new Map());
|
||||
if (!models.has(id)) models.set(id, create());
|
||||
return models.get(id);
|
||||
};
|
||||
const flights = once(() =>
|
||||
createApplicationFlights({
|
||||
surface,
|
||||
source: sources.flights,
|
||||
militaryRegistry,
|
||||
resolveAsset,
|
||||
}),
|
||||
sessionModel('flights', () =>
|
||||
createApplicationFlights({
|
||||
surface,
|
||||
source: sources.flights,
|
||||
militaryRegistry,
|
||||
resolveAsset,
|
||||
}),
|
||||
),
|
||||
);
|
||||
const military = once(() =>
|
||||
createApplicationMilitary({
|
||||
@@ -158,7 +177,10 @@ export function createApplicationCatalog({
|
||||
],
|
||||
[
|
||||
'earthquakes',
|
||||
() => createApplicationEarthquakes({ source: sources.earthquakes }),
|
||||
() =>
|
||||
sessionModel('earthquakes', () =>
|
||||
createApplicationEarthquakes({ source: sources.earthquakes }),
|
||||
),
|
||||
],
|
||||
[
|
||||
'air-quality',
|
||||
|
||||
+9
-4
@@ -8,12 +8,13 @@ export function createApplicationData({
|
||||
controls: { styleManager },
|
||||
catalog,
|
||||
allowQaRegistration,
|
||||
layerSession,
|
||||
onData,
|
||||
defer,
|
||||
}) {
|
||||
// Initialize data layer manager
|
||||
// The modules get { signal, engine } on every call (viewer null on Navara).
|
||||
const dataManager = new LayerLifecycle(viewer, {
|
||||
const dataManager = layerSession?.manager ?? new LayerLifecycle(viewer, {
|
||||
engine,
|
||||
allowQaRegistration,
|
||||
// A panel's host may report it hidden while it is on screen; its layers
|
||||
@@ -21,7 +22,12 @@ export function createApplicationData({
|
||||
visibilityTarget: panelAwareVisibility(document),
|
||||
getSourceAvailability: catalog?.getSourceAvailability,
|
||||
});
|
||||
if (layerSession) layerSession.manager = dataManager;
|
||||
defer(async () => {
|
||||
if (layerSession && !layerSession.lifetime.signal.aborted) {
|
||||
await dataManager.detachScene();
|
||||
return;
|
||||
}
|
||||
await dataManager.destroyAll();
|
||||
if (dataManager.layers.size)
|
||||
throw new Error(
|
||||
@@ -35,12 +41,11 @@ export function createApplicationData({
|
||||
onData?.(dataManager);
|
||||
if (!catalog?.layers || !catalog?.metadata)
|
||||
throw new TypeError('An application layer catalog is required');
|
||||
for (const layer of catalog.layers) dataManager.register(layer);
|
||||
dataManager.bindCatalog(viewer, engine, catalog);
|
||||
for (const layer of catalog.layers) layer.attachDataManager?.(dataManager);
|
||||
for (const layer of catalog.layers)
|
||||
layer.attachMapStackController?.(mapStackController);
|
||||
// Restoration starts only after the caller's complete registry is sealed.
|
||||
dataManager.finalizeRegistrations(catalog.metadata);
|
||||
|
||||
if (allowQaRegistration) {
|
||||
window.__gevQaRegisterLayer = (targetManager, layerModule) => {
|
||||
if (targetManager !== dataManager)
|
||||
|
||||
+12
-2
@@ -29,12 +29,14 @@ export async function createApplicationScene({
|
||||
signal,
|
||||
defer,
|
||||
rendererCache,
|
||||
layerSession,
|
||||
...options
|
||||
}) {
|
||||
const operations = createApplicationOperations({
|
||||
const operations = layerSession?.operations ?? createApplicationOperations({
|
||||
requests: requestServices,
|
||||
signal,
|
||||
signal: layerSession?.lifetime.signal ?? signal,
|
||||
});
|
||||
if (layerSession) layerSession.operations = operations;
|
||||
defer(initLogoGaze());
|
||||
const previousKey = window.__GOOGLE_MAPS_API_KEY__;
|
||||
if (googleApiKey) {
|
||||
@@ -55,6 +57,14 @@ export async function createApplicationScene({
|
||||
const { viewer, engine, tileset, mapStackController } = rendererCache
|
||||
? await rendererCache.acquire(options.engineKind, build, defer)
|
||||
: await build({ defer });
|
||||
if (layerSession) {
|
||||
// DEM cells belong to the session. Mesh samples came from the outgoing
|
||||
// scene, including when the incoming canvas was warm in the cache.
|
||||
operations.surface.groundFloor.clearMeshFloorCells();
|
||||
operations.surface.groundFloor.setMeshFloorPreferred(
|
||||
mapStackController.getActiveId() === 'photoreal',
|
||||
);
|
||||
}
|
||||
return { viewer, engine, tileset, mapStackController, operations };
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user