mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 02:02: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.
126 lines
4.1 KiB
JavaScript
126 lines
4.1 KiB
JavaScript
import { getContextStore, isContextRecordActive } from './contextStore.js';
|
|
import { readEntityRecord } from './entityRecords.js';
|
|
import { findPickOwner, resolvePickId } from './pickRegistry.js';
|
|
|
|
/**
|
|
* Resolve a pick (the contract's `Hit`, as `pickAt` in
|
|
* src/input/dispatcher.js gives it) to the identity a person would name:
|
|
* which layer, which record, and its display label.
|
|
*
|
|
* Two lanes, in order:
|
|
* 1. Context-store carriers. Layers drawing through the draw port
|
|
* (infrastructure GeoJSON, ALPR) write a `contextId` into a draw item's
|
|
* `meta`; the store record already carries the label and position voice
|
|
* uses everywhere else.
|
|
* 2. Pick owners. Layers (aircraft, satellites, vessels) register an
|
|
* ownership predicate in `pickRegistry`; the owning layer's
|
|
* `findByQuery` turns the pick id into a live descriptor.
|
|
*
|
|
* Trails claim their pick ids only to make clicks inert, so they never
|
|
* resolve. Disabled layers never resolve: what the user cannot see is not
|
|
* what they are pointing at.
|
|
*/
|
|
|
|
const KIND_BY_LAYER = Object.freeze({
|
|
flights: 'aircraft',
|
|
military: 'aircraft',
|
|
'local-adsb': 'aircraft',
|
|
'ais-live-vessels': 'vessel',
|
|
satellites: 'satellite',
|
|
'local-firms': 'fire',
|
|
});
|
|
|
|
const IGNORED_OWNERS = new Set(['trails']);
|
|
|
|
function text(value) {
|
|
return String(value ?? '').trim();
|
|
}
|
|
|
|
function finite(value) {
|
|
if (value === null || value === undefined || value === '') return null;
|
|
const number = Number(value);
|
|
return Number.isFinite(number) ? number : null;
|
|
}
|
|
|
|
/** Kind of thing a layer holds, for deixis ("this aircraft", "this place"). */
|
|
export function pickedKindForLayer(layerId) {
|
|
return KIND_BY_LAYER[layerId] || 'feature';
|
|
}
|
|
|
|
function contextCarrierRecord(hit, dataManager) {
|
|
const contextId = readEntityRecord(hit?.meta)?.contextId;
|
|
if (!contextId) return null;
|
|
const record = getContextStore().entities.get(contextId);
|
|
return record && isContextRecordActive(record, dataManager) ? record : null;
|
|
}
|
|
|
|
function fromRecord(record) {
|
|
const layerId = record.layerId || null;
|
|
const id =
|
|
layerId === 'ais-live-vessels' && record.properties?.vesselId
|
|
? String(record.properties.vesselId)
|
|
: String(record.id);
|
|
return {
|
|
layerId,
|
|
id,
|
|
label:
|
|
text(record.label) ||
|
|
text(record.properties?.name) ||
|
|
text(record.layerName) ||
|
|
id,
|
|
kind: pickedKindForLayer(layerId),
|
|
lat: finite(record.latitude),
|
|
lon: finite(record.longitude),
|
|
};
|
|
}
|
|
|
|
function descriptorLabel(found, fallback) {
|
|
return (
|
|
text(found?.callsign) ||
|
|
text(found?.registration) ||
|
|
text(found?.name) ||
|
|
text(found?.icao24) ||
|
|
text(found?.mmsi) ||
|
|
text(found?.noradId) ||
|
|
fallback
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @param {import('../render/contract/query').Hit|null} picked
|
|
* @param {object} [options]
|
|
* @param {object} [options.dataManager] Layer lifecycle (enabled state, modules).
|
|
* @returns {{layerId: string, id: string, label: string, kind: string, lat: number|null, lon: number|null, altitudeM?: number|null}|null}
|
|
*/
|
|
export function resolvePickedContext(picked, { dataManager = null } = {}) {
|
|
if (!picked || picked.surface) return null;
|
|
const record = contextCarrierRecord(picked, dataManager);
|
|
if (record) return fromRecord(record);
|
|
|
|
// An item drawn in parts names the id its parts pick as (`meta.pick`:
|
|
// a Street Level sequence), as the one primitive they were picked as.
|
|
const pickId =
|
|
(typeof picked.meta?.pick === 'string' && picked.meta.pick) ||
|
|
resolvePickId(picked);
|
|
if (!pickId) return null;
|
|
const layerId = findPickOwner(pickId);
|
|
if (!layerId || IGNORED_OWNERS.has(layerId)) return null;
|
|
if (dataManager?.isEnabled && !dataManager.isEnabled(layerId)) return null;
|
|
const layer = dataManager?.layers?.get?.(layerId);
|
|
let found = null;
|
|
try {
|
|
found = layer?.module?.findByQuery?.(pickId) || null;
|
|
} catch {
|
|
found = null;
|
|
}
|
|
return {
|
|
layerId,
|
|
id: pickId,
|
|
label: descriptorLabel(found, text(layer?.name) || pickId),
|
|
kind: pickedKindForLayer(layerId),
|
|
lat: finite(found?.latitude),
|
|
lon: finite(found?.longitude),
|
|
altitudeM: finite(found?.altitudeM),
|
|
};
|
|
}
|