mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Installation selection fills and outlines record the installation they
belong to in the layer's installationMarkers store instead of an
installationId expando, and the click handler resolves them from there.
Named-marker points keep their { installationId } pick payload, which is
the app's own object, so sibling layers treat a point click as before; the
marker remembers its record id for visit() instead of reading the point.
The local GeoJSON package tracks the entities each layer loaded in a
per-instance set instead of a __localLayerId tag, and passes the stem
base to registerEntityContext as targetPosition instead of hanging it on
the entity; FIRMS does the same, and voice targeting reads the context
record. QA scripts find a layer's features by their context id.
88 lines
3.0 KiB
JavaScript
88 lines
3.0 KiB
JavaScript
import * as Cesium from 'cesium';
|
|
import { isPointerFree } from '../../data/inputOwnership.js';
|
|
import { LAYER_ID } from './policy.js';
|
|
import { installationMarkers } from './markerState.js';
|
|
|
|
export function createSelection({
|
|
state: layerState,
|
|
services,
|
|
parts,
|
|
source,
|
|
}) {
|
|
const { clearSelectedEntityContextForLayer } = services.context;
|
|
|
|
let removeContextListeners = null;
|
|
|
|
function syncContextSelection(event) {
|
|
if (!layerState.enabled) return;
|
|
// Tracking layers publish this event before replacing the shared context.
|
|
const selected =
|
|
event?.type === 'gev:awareness-subject-selected'
|
|
? event.detail
|
|
: services.context.getSelectedEntityContext();
|
|
const next =
|
|
selected?.layerId === LAYER_ID && layerState.recordById.has(selected.id)
|
|
? selected.id
|
|
: null;
|
|
if (next === layerState.selectedId) return;
|
|
layerState.selectedId = next;
|
|
parts.rendering.renderRecords();
|
|
}
|
|
|
|
function selectRecord(id) {
|
|
const record = layerState.recordById.get(id);
|
|
if (!record || !layerState.dataSource) return false;
|
|
layerState.selectedId = id;
|
|
parts.rendering.renderRecords({ claimSelection: true });
|
|
// renderRecords drops selectedId when the record produced no entity.
|
|
return layerState.selectedId === id;
|
|
}
|
|
|
|
function installInteraction(viewer) {
|
|
if (layerState.clickHandler) return;
|
|
const events = [
|
|
'gev:entity-selected',
|
|
'gev:entity-selection-cleared',
|
|
'gev:awareness-subject-selected',
|
|
];
|
|
for (const event of events)
|
|
globalThis.window?.addEventListener?.(event, syncContextSelection);
|
|
removeContextListeners = () => {
|
|
for (const event of events)
|
|
globalThis.window?.removeEventListener?.(event, syncContextSelection);
|
|
};
|
|
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);
|
|
const target = picked?.id;
|
|
const id =
|
|
target?.installationId ||
|
|
installationMarkers.read(target)?.recordId ||
|
|
(typeof target?.id === 'string' ? target.id : null);
|
|
if (id && layerState.recordById.has(id) && id !== layerState.selectedId) {
|
|
selectRecord(id);
|
|
} else if (layerState.selectedId) {
|
|
// Clicking the selected site again, empty map, or another contact
|
|
// releases this layer's selection. Clear only our shared context so a
|
|
// sibling click handler's newly selected aircraft/site stays intact.
|
|
layerState.selectedId = null;
|
|
clearSelectedEntityContextForLayer(LAYER_ID);
|
|
parts.rendering.renderRecords();
|
|
}
|
|
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
|
}
|
|
return {
|
|
selectRecord,
|
|
installInteraction,
|
|
destroy() {
|
|
removeContextListeners?.();
|
|
removeContextListeners = null;
|
|
},
|
|
};
|
|
}
|