mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 09:42:21 +00:00
Review fixes for #1781: - One rule for cards: the world-overlay host hands its hit test to the pick registry, and every click handler reads the topmost interactive card or label once per click (`clickCard`, `isUnderOtherCard` in src/data/pickRegistry.js), so all handlers agree in any listener order. A layer whose own card or label is on top acts on it whatever is drawn under it; a layer under another layer's card neither acts nor treats the click as empty space (a tracked aircraft stays tracked, a selection stays selected); Context names nothing under a card. A selected news card over a vessel no longer opens the link and selects the vessel. - With one rule, the per-owner arbitration options are no longer read and are removed: `passive`, `expanded` and `declinesClick` pick owners, `rememberClickPickActions`, `isActedOnByOtherLayer`, card backgrounds and `cardKeepsClick`. The dispatcher is unchanged from main. - A drag that ends on a quake disc, label or card does nothing; opening the USGS page or clearing the selection needs a clean click. - A click on the map under another layer's card opens no Street Level ground image. - A CCTV card that is going away is still not the scene under it. - Docs and changelog describe the new rule.
88 lines
3.0 KiB
JavaScript
88 lines
3.0 KiB
JavaScript
import { inputFor } from '../../input/dispatcher.js';
|
|
import { isUnderOtherCard } from '../../data/pickRegistry.js';
|
|
import { LAYER_ID } from './policy.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.sets) return false;
|
|
layerState.selectedId = id;
|
|
parts.rendering.renderRecords({ claimSelection: true });
|
|
// renderRecords drops selectedId when the record produced no marker.
|
|
return layerState.selectedId === id;
|
|
}
|
|
|
|
function installInteraction(viewer) {
|
|
if (layerState.clickSubscription) 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);
|
|
};
|
|
const input = inputFor(viewer);
|
|
layerState.clickSubscription = input.onClick((event) => {
|
|
if (!layerState.enabled) return;
|
|
// Another layer's card or label painted on top takes the click: the item
|
|
// under it does not act, and the click is not empty space either.
|
|
if (isUnderOtherCard(event)) return;
|
|
// A site's dot, outline or fill, or a named marker: each draw item
|
|
// names its installation in its `meta`.
|
|
const hit = event.drawHit;
|
|
const id =
|
|
hit?.set === parts.namedMarkers?.setId ||
|
|
parts.rendering.ownsSet(hit?.set)
|
|
? hit.meta?.installationId
|
|
: 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();
|
|
}
|
|
});
|
|
}
|
|
return {
|
|
selectRecord,
|
|
installInteraction,
|
|
destroy() {
|
|
removeContextListeners?.();
|
|
removeContextListeners = null;
|
|
},
|
|
};
|
|
}
|