mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-22 03:02:20 +00:00
Create pick registries and selection dispatchers for each scene attachment, publish them through scene.services, and release their predicates and input subscriptions before parking the renderer. Resolve layer ownership with the attached engine so identical layer IDs in simultaneous scenes cannot overwrite or remove one another. Re-register retained ALPR and cyclone picks on attachment, and resolve voice pointer picks against the engine that supplied the pick. Preserve Cesium's selection, sibling ownership, inert trails, touch expansion, drag and long-press rules on both engines. Extract the unchanged gesture predicates so portable picking does not acquire a native input dependency. Exercise scene isolation, teardown and reattachment on fake and headless Cesium engines, retaining the existing layer assertions. No coupling count falls or grows. Cesium and Navara renderer lines remain 0 and 189; external Cesium imports 3; viewer lines 910; Navara kind checks 2; engine sniff calls 0; extension reads 3; ground passes 1; SDK loads 3; screen-handler files 4; engine-name lines 33.
60 lines
2.1 KiB
JavaScript
60 lines
2.1 KiB
JavaScript
import * as geo from '../geo/index.js';
|
|
import { resolvePickedContext } from '../data/pickedContext.js';
|
|
import { cameraPoseKey } from './pointerContext.js';
|
|
import * as defaultAnnotationResolver from '../annotations/annotationResolver.js';
|
|
|
|
/** "Around here" radius as a share of camera height, clamped to sane bounds. */
|
|
function pointerRadiusKm(cameraHeightM) {
|
|
const heightKm = Number(cameraHeightM) / 1000;
|
|
if (!Number.isFinite(heightKm) || heightKm <= 0) return 50;
|
|
return Math.round(Math.min(400, Math.max(5, heightKm * 0.75)));
|
|
}
|
|
|
|
/**
|
|
* The globe side of point-and-ask: one object pick (engine.picker.pick) and
|
|
* one depth-aware world pick at canvas CSS pixels, on either engine. Called
|
|
* lazily by the pointer tracker (dwell and snapshot only), never per mouse
|
|
* move.
|
|
* @param {object} options
|
|
* @param {object} options.engine The globe engine.
|
|
* @param {object} [options.dataManager] Layer lifecycle.
|
|
* @param {Function} [options.pickWorldFromScreen] Normalized-pixel world pick.
|
|
* @returns {(x: number, y: number) => {entity: object|null, ground: object|null, radiusKm: number}|null}
|
|
*/
|
|
export function createPointerPicker({
|
|
engine,
|
|
dataManager = null,
|
|
pickWorldFromScreen = defaultAnnotationResolver.pickWorldFromScreen,
|
|
}) {
|
|
return function pickPointer(x, y) {
|
|
if (!engine || engine.isDestroyed?.()) return null;
|
|
const { width, height } = engine.host.size();
|
|
if (!width || !height) return null;
|
|
let picked = null;
|
|
try {
|
|
picked = engine.picker.pick(geo.cartesian2.create(x, y)) ?? null;
|
|
} catch {
|
|
picked = null;
|
|
}
|
|
const entity = resolvePickedContext(picked, { dataManager, engine });
|
|
let ground = null;
|
|
try {
|
|
const hit = pickWorldFromScreen(engine, x / width, y / height);
|
|
if (hit && Number.isFinite(hit.lat) && Number.isFinite(hit.lon))
|
|
ground = {
|
|
lat: hit.lat,
|
|
lon: hit.lon,
|
|
heightM: Number.isFinite(hit.height) ? Math.round(hit.height) : null,
|
|
};
|
|
} catch {
|
|
ground = null;
|
|
}
|
|
return {
|
|
entity,
|
|
ground,
|
|
radiusKm: pointerRadiusKm(engine.camera.height()),
|
|
cameraKey: cameraPoseKey(engine),
|
|
};
|
|
};
|
|
}
|