mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Flights, military, satellites, installations, local ADS-B and ALPR hung gevTrackedId, gevDisplayPosition, gevVisualPosition, gevSelectionOrigin and gevLabelModel on the Cesium entities they draw, and the tracked readout, follow camera, cockpit, share links and awareness read them back. They now live in src/data/entityRecords.js, a Core-owned record per entity: layers write entityRecord(entity), readers use readEntityRecord(entity). Nothing changes on screen. This is the first slice of the renderer plan's state mirror (P1). The module is exported as ./data/entity-records so hosted code can read the same records, and window.__godsEyeView.entityRecords gives the QA scripts the same access from the page.
91 lines
3.4 KiB
JavaScript
91 lines
3.4 KiB
JavaScript
import * as Cesium from 'cesium';
|
|
import { isPointerFree } from '../../data/inputOwnership.js';
|
|
import { readEntityRecord } from '../../data/entityRecords.js';
|
|
|
|
export function createInteraction({
|
|
state: layerState,
|
|
services,
|
|
parts,
|
|
source,
|
|
}) {
|
|
const { resolvePickId, isOwnedByOtherLayer } = services.picking;
|
|
|
|
function _onKeyDown(e) {
|
|
if (layerState._enabled && e.key === 'Escape' && layerState._trackedNorad) {
|
|
parts.tracking._cancelPendingTrackingRestore();
|
|
parts.tracking._clearTracking(false, { origin: 'user' });
|
|
}
|
|
}
|
|
|
|
function _installClickHandler(viewer) {
|
|
if (layerState._clickHandler) return; // already installed
|
|
|
|
// Cross-layer untrack (H2, mirror of flights): if ANOTHER layer (flights,
|
|
// military, …) grabs the follow-camera, drop our tracking so the orbit ring /
|
|
// tracked entity don't orphan — without touching viewer.trackedEntity (the
|
|
// new owner controls it). Guarded so our OWN switch (viewer.trackedEntity
|
|
// briefly undefined mid-_trackSatellite) doesn't self-clear.
|
|
if (!layerState._trackedEntityChangedRemove) {
|
|
layerState._trackedEntityChangedRemove =
|
|
viewer.trackedEntityChanged.addEventListener(() => {
|
|
if (!layerState._enabled) return;
|
|
if (
|
|
layerState._trackedNorad &&
|
|
layerState._viewer &&
|
|
layerState._viewer.trackedEntity &&
|
|
layerState._viewer.trackedEntity !== layerState._trackedEntity
|
|
) {
|
|
parts.tracking._clearTracking(true, {
|
|
origin:
|
|
readEntityRecord(layerState._viewer.trackedEntity)
|
|
?.selectionOrigin || 'programmatic',
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
layerState._clickHandler = new Cesium.ScreenSpaceEventHandler(
|
|
viewer.scene.canvas,
|
|
);
|
|
layerState._clickHandler.setInputAction((click) => {
|
|
// A tool owns the pointer (src/data/inputOwnership.js): yield the click.
|
|
if (!isPointerFree()) return;
|
|
if (!layerState._enabled) return;
|
|
const picked = viewer.scene.pick(click.position);
|
|
|
|
if (picked) {
|
|
// Clicking tracked entity itself — ignore
|
|
if (picked.id === layerState._trackedEntity) return;
|
|
|
|
// Check if it's a satellite point (id is NORAD catalog number)
|
|
const prim = picked.primitive;
|
|
if (prim && prim.id != null) {
|
|
const noradId = Number(prim.id);
|
|
if (!isNaN(noradId) && layerState._catalog.has(noradId)) {
|
|
parts.tracking._cancelPendingTrackingRestore();
|
|
parts.tracking._trackSatellite(noradId, { origin: 'user' });
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
// A pick that belongs to a sibling layer (plane, vessel, station, CCTV
|
|
// camera…) is not "empty space" — leave OUR tracking (and crucially
|
|
// viewer.trackedEntity, which that sibling may have JUST set) alone (H2).
|
|
if (picked) {
|
|
const pickedId = resolvePickId(picked);
|
|
if (pickedId && isOwnedByOtherLayer('satellites', pickedId)) return;
|
|
}
|
|
|
|
// Clicked empty space — deselect
|
|
if (layerState._trackedNorad) {
|
|
parts.tracking._cancelPendingTrackingRestore();
|
|
parts.tracking._clearTracking(false, { origin: 'user' });
|
|
}
|
|
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
|
|
|
document.addEventListener('keydown', _onKeyDown);
|
|
}
|
|
return { _onKeyDown, _installClickHandler };
|
|
}
|