mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-23 11:42:21 +00:00
Space Missions no longer runs as a Context mode. The launches layer owns its Satellites dependency, including the rule that a Satellites off asked for after Space Missions was switched on ends it (request order decides), and a small controller connects the layer to its own panel and store. Context no longer isolates, snapshots or restores Space Missions or Satellites, so Contacts and Space Missions run together in either order, and scene playback no longer exits an isolating mode. Settled by the owner: Contacts leaves Satellites as it is, and only a person's or voice Satellites off ends Space Missions; a scene, story, preset or other programmatic off does not. Turning the layer on by hand or by voice, choosing it at first run, or picking a mission on the globe opens the Space Missions panel, and on a phone its Missions sheet. Asking voice to open the panel while the layer is off is refused with a reason, and voice never opens it while the Cockpit owns the screen. With no Context mode on, a voice Context off switches Space Missions off. A failed Satellites restore no longer cuts the layer's teardown short. Mission labels on the globe select their mission. The layer names a failed first index load itself, so the Context toast no longer imports Space Missions code. Also carries the satellites request ordering and DataLayerManager.waitForLayerIdle, the share token for the panel, voice panel ids, Cockpit folding the panel away and the phone tab ellipsis. The panel shares the rail gutters and hover border of the other side panels. On top of the Omnibar: "open space missions panel" reaches the new panel, and Open Context no longer answers to "missions". Co-authored-by: Sameh Khamis <[email protected]>
330 lines
11 KiB
JavaScript
330 lines
11 KiB
JavaScript
import { onFollowChanged } from '../data/followed.js';
|
|
import { isExplicitLayerStateOrigin } from '../data/layerState.js';
|
|
import {
|
|
registerCctvFocusRequestListener,
|
|
routeCctvFocusRequest,
|
|
} from '../cctvFocusRequest.js';
|
|
import {
|
|
flyToWorldTarget,
|
|
registerWorldFocusRequestListener,
|
|
routeWorldFocusRequest,
|
|
} from '../worldFocus.js';
|
|
import { registerNavigationAuthorityListener } from '../navigationPolicy.js';
|
|
/** Own manager subscriptions and the camera-entry events that outlive controls. */
|
|
export class LayerBindings {
|
|
constructor({
|
|
viewer,
|
|
services,
|
|
readControls,
|
|
operations,
|
|
feedback,
|
|
shareRestoration,
|
|
}) {
|
|
Object.assign(
|
|
this,
|
|
{
|
|
viewer,
|
|
services,
|
|
readControls,
|
|
_feedback: feedback,
|
|
_shareRestoration: shareRestoration,
|
|
},
|
|
operations,
|
|
);
|
|
this._disposed = false;
|
|
this._dataManager = null;
|
|
this._directionsShellModule = null;
|
|
this._weatherShellModules = [];
|
|
this._cctvRequestFocusHandler = null;
|
|
this._removeCctvRequestFocusListener = null;
|
|
this._worldRequestFocusHandler = null;
|
|
this._removeWorldRequestFocusListener = null;
|
|
this._removeNavigationAuthorityListener = null;
|
|
this._navigationOwnerChangedRemover = null;
|
|
this._awarenessSelectedHandler = null;
|
|
this._awarenessClearedHandler = null;
|
|
}
|
|
get hud() {
|
|
return this.readControls().hud;
|
|
}
|
|
get _contextControls() {
|
|
return this.readControls()._contextControls;
|
|
}
|
|
get _spaceMissionsControls() {
|
|
return this.readControls()._spaceMissionsControls;
|
|
}
|
|
get _cctvControls() {
|
|
return this.readControls()._cctvControls;
|
|
}
|
|
get _radioControls() {
|
|
return this.readControls()._radioControls;
|
|
}
|
|
get _streetLevelControls() {
|
|
return this.readControls()._streetLevelControls;
|
|
}
|
|
observeCamera() {
|
|
this._cctvRequestFocusHandler = (event) =>
|
|
routeCctvFocusRequest(
|
|
event,
|
|
(activate, focus) => this._runExplicitCctvFocus(activate, focus),
|
|
(cameraId, durationSec) =>
|
|
this.services.cctvLayer.focusCamera(cameraId, durationSec),
|
|
);
|
|
this._removeCctvRequestFocusListener = registerCctvFocusRequestListener(
|
|
window,
|
|
this._cctvRequestFocusHandler,
|
|
);
|
|
this._worldRequestFocusHandler = (event) =>
|
|
routeWorldFocusRequest(
|
|
event,
|
|
(detail, fly) => this._runExplicitWorldFocus(detail, fly),
|
|
(detail) => flyToWorldTarget(this.viewer, detail),
|
|
);
|
|
this._removeWorldRequestFocusListener = registerWorldFocusRequestListener(
|
|
window,
|
|
this._worldRequestFocusHandler,
|
|
);
|
|
this._navigationOwnerChangedRemover = onFollowChanged(
|
|
this.viewer,
|
|
(followed) => {
|
|
if (followed && !this._disposed)
|
|
this._stampNavigation({ cancelPendingSelection: false });
|
|
},
|
|
);
|
|
// Vessel/installation focus flies without ever assigning a tracked entity,
|
|
// so it cannot reach the listener above. It announces instead.
|
|
this._removeNavigationAuthorityListener =
|
|
registerNavigationAuthorityListener(window, (event) => {
|
|
if (this._disposed) return;
|
|
this._stampNavigation({
|
|
cancelPendingSelection:
|
|
event?.detail?.cancelPendingSelection !== false,
|
|
});
|
|
});
|
|
}
|
|
_connectDirectionsCamera() {
|
|
if (!this._dataManager) {
|
|
// Detaching: the layer outlives this shell, so it must not keep calling
|
|
// a facade whose viewer is going away.
|
|
this._directionsShellModule?.attachShellServices?.(null);
|
|
this._directionsShellModule = null;
|
|
return;
|
|
}
|
|
const directions = this._dataManager.layers?.get('directions')?.module;
|
|
if (this._directionsShellModule !== directions) {
|
|
this._directionsShellModule?.attachShellServices?.(null);
|
|
this._directionsShellModule = null;
|
|
}
|
|
if (typeof directions?.attachShellServices !== 'function') return;
|
|
this._directionsShellModule = directions;
|
|
directions.attachShellServices({
|
|
runNavigation: (navigate) =>
|
|
this.runImmediateNavigation('route', navigate),
|
|
floorFn: (lat, lon) => this.services.cachedGroundFloor(lat, lon),
|
|
warmFn: (cells) => this.services.warmGroundFloor(cells),
|
|
});
|
|
}
|
|
|
|
_connectWeatherCamera() {
|
|
for (const layer of this._weatherShellModules)
|
|
layer.attachShellServices?.(null);
|
|
this._weatherShellModules = [];
|
|
for (const id of [
|
|
'wind',
|
|
'weather-radar',
|
|
'weather-satellite',
|
|
'weather-lightning',
|
|
'weather-cyclones',
|
|
]) {
|
|
const layer = this._dataManager?.layers?.get(id)?.module;
|
|
if (typeof layer?.attachShellServices !== 'function') continue;
|
|
const noun = id === 'weather-cyclones' ? 'cyclone' : 'weather';
|
|
layer.attachShellServices({
|
|
runNavigation: (navigate) =>
|
|
this.runImmediateNavigation(noun, navigate),
|
|
imageryHost: this.services.imageryHost,
|
|
});
|
|
this._weatherShellModules.push(layer);
|
|
}
|
|
// Active Fires drapes its far-zoom heatmap on the same imagery host.
|
|
const fires = this._dataManager?.layers?.get('local-firms')?.module;
|
|
if (typeof fires?.attachShellServices === 'function') {
|
|
fires.attachShellServices({ imageryHost: this.services.imageryHost });
|
|
this._weatherShellModules.push(fires);
|
|
}
|
|
// News flies to a chosen report or hotspot through the same release.
|
|
const news = this._dataManager?.layers?.get('news')?.module;
|
|
if (typeof news?.attachShellServices === 'function') {
|
|
news.attachShellServices({
|
|
runNavigation: (navigate) =>
|
|
this.runImmediateNavigation('news', navigate),
|
|
});
|
|
this._weatherShellModules.push(news);
|
|
}
|
|
// Bike share flies into a covered city from its marker the same way.
|
|
const bikeshare = this._dataManager?.layers?.get('bikeshare')?.module;
|
|
if (typeof bikeshare?.attachShellServices === 'function') {
|
|
bikeshare.attachShellServices({
|
|
runNavigation: (navigate) =>
|
|
this.runImmediateNavigation('bike share', navigate),
|
|
});
|
|
this._weatherShellModules.push(bikeshare);
|
|
}
|
|
}
|
|
|
|
_persistAwarenessSelection(event, cleared = false) {
|
|
if (!this._dataManager) return;
|
|
const origin = String(event?.detail?.origin || 'programmatic');
|
|
if (!isExplicitLayerStateOrigin(origin)) return;
|
|
const layerId = String(event?.detail?.layerId || '');
|
|
const config = {
|
|
flights: {
|
|
key: 'selectedFlightsTrackingId',
|
|
normalize: (value) =>
|
|
String(value ?? '')
|
|
.trim()
|
|
.toLowerCase() || null,
|
|
},
|
|
military: {
|
|
key: 'selectedMilitaryTrackingId',
|
|
normalize: (value) =>
|
|
String(value ?? '')
|
|
.trim()
|
|
.toLowerCase() || null,
|
|
},
|
|
satellites: {
|
|
key: 'selectedSatTrackingId',
|
|
normalize: (value) => {
|
|
const candidate = Number(value);
|
|
return Number.isFinite(candidate) && candidate > 0
|
|
? Math.trunc(candidate)
|
|
: null;
|
|
},
|
|
},
|
|
}[layerId];
|
|
if (!config) return;
|
|
const selectedValue = cleared ? null : config.normalize(event?.detail?.id);
|
|
if (cleared || selectedValue === null) {
|
|
this._dataManager.adoptLayerParams?.(
|
|
layerId,
|
|
{
|
|
[config.key]: selectedValue,
|
|
},
|
|
{ origin },
|
|
);
|
|
return;
|
|
}
|
|
// A direct selection promotes a Context-owned tracker dependency into
|
|
// durable visibility before its selected ID is normalized. Context exit
|
|
// also keeps this adopted layer instead of tearing down the user's track.
|
|
const visibilityAdopted = this._dataManager.adoptLayerVisibility?.(
|
|
layerId,
|
|
true,
|
|
{ origin, adoptedFromSelection: true },
|
|
);
|
|
if (visibilityAdopted === false) return;
|
|
// Clear the prior family before publishing the replacement. Otherwise the
|
|
// coordinator briefly sees two IDs and correctly treats them as an
|
|
// ambiguous incoming state, which would discard the new durable target.
|
|
for (const [otherLayerId, otherKey] of [
|
|
['flights', 'selectedFlightsTrackingId'],
|
|
['military', 'selectedMilitaryTrackingId'],
|
|
['satellites', 'selectedSatTrackingId'],
|
|
]) {
|
|
if (otherLayerId === layerId) continue;
|
|
this._dataManager.setLayerParams(
|
|
otherLayerId,
|
|
{ [otherKey]: null },
|
|
{ origin },
|
|
);
|
|
}
|
|
this._dataManager.adoptLayerParams?.(
|
|
layerId,
|
|
{
|
|
[config.key]: selectedValue,
|
|
},
|
|
{ origin },
|
|
);
|
|
}
|
|
|
|
attachDataManager(dataManager) {
|
|
if (this._disposed) return;
|
|
this._dataManager = dataManager || null;
|
|
this.hud.attachDataManager(this._dataManager);
|
|
this._updateTrafficSyncChip();
|
|
if (this._dataManagerUnsubscribe) {
|
|
this._dataManagerUnsubscribe();
|
|
this._dataManagerUnsubscribe = null;
|
|
}
|
|
this._contextControls.connect(this._dataManager);
|
|
this._spaceMissionsControls?.connect(this._dataManager);
|
|
if (typeof this._dataManager?.subscribe === 'function') {
|
|
this._dataManagerUnsubscribe = this._dataManager.subscribe((change) => {
|
|
this._feedback._loadingFeedbackEvent = change;
|
|
this._updateGlobalLoadingFeedback(performance.now());
|
|
});
|
|
}
|
|
this._updateGlobalLoadingFeedback(performance.now());
|
|
this._syncContextModeButtons();
|
|
this._cctvControls.connect();
|
|
this._radioControls.connect();
|
|
// Its switch-on requests come from the manager, which arrives after it.
|
|
this._streetLevelControls?.connect();
|
|
this._connectDirectionsCamera();
|
|
this._connectWeatherCamera();
|
|
if (!this._awarenessSelectedHandler) {
|
|
this._awarenessSelectedHandler = (event) =>
|
|
this._persistAwarenessSelection(event, false);
|
|
this._awarenessClearedHandler = (event) =>
|
|
this._persistAwarenessSelection(event, true);
|
|
window.addEventListener(
|
|
'gev:awareness-subject-selected',
|
|
this._awarenessSelectedHandler,
|
|
);
|
|
window.addEventListener(
|
|
'gev:awareness-subject-cleared',
|
|
this._awarenessClearedHandler,
|
|
);
|
|
}
|
|
this._shareRestoration.connect(this._dataManager);
|
|
}
|
|
stop() {
|
|
if (this._disposed) return;
|
|
this._disposed = true;
|
|
if (this._awarenessSelectedHandler) {
|
|
window.removeEventListener(
|
|
'gev:awareness-subject-selected',
|
|
this._awarenessSelectedHandler,
|
|
);
|
|
this._awarenessSelectedHandler = null;
|
|
}
|
|
if (this._awarenessClearedHandler) {
|
|
window.removeEventListener(
|
|
'gev:awareness-subject-cleared',
|
|
this._awarenessClearedHandler,
|
|
);
|
|
this._awarenessClearedHandler = null;
|
|
}
|
|
|
|
this._removeCctvRequestFocusListener?.();
|
|
this._removeCctvRequestFocusListener = null;
|
|
this._cctvRequestFocusHandler = null;
|
|
this._removeWorldRequestFocusListener?.();
|
|
this._removeWorldRequestFocusListener = null;
|
|
this._worldRequestFocusHandler = null;
|
|
this._navigationOwnerChangedRemover?.();
|
|
this._navigationOwnerChangedRemover = null;
|
|
this._removeNavigationAuthorityListener?.();
|
|
this._removeNavigationAuthorityListener = null;
|
|
}
|
|
disconnect() {
|
|
this._dataManagerUnsubscribe?.();
|
|
this._dataManagerUnsubscribe = null;
|
|
this._directionsShellModule?.attachShellServices?.(null);
|
|
this._directionsShellModule = null;
|
|
this._dataManager = null;
|
|
this._spaceMissionsControls?.connect(null);
|
|
this._connectWeatherCamera();
|
|
}
|
|
}
|