Files
gods-eye-view/src/globe/cesium/picker.js
T
German Khokhlov d831cbd23a feat(globe): implement the engine on Cesium
createCesiumEngine wraps an existing viewer without changing it: camera, picker, projector, frames, render (through the render governor), surface, input, credits and maps, with geo values out and Cesium values in at the boundary. Map and surface code is shared with src/maps and services/groundSnap instead of copied. scripts/qa-globe-contract.mjs runs the contract suite against the engine in headless Chrome; the camera-events check now waits for the previous move to end, as Cesium's moveStart marks a move from rest.
2026-10-15 17:43:05 +04:00

40 lines
1.2 KiB
JavaScript

// GlobePicker on a Cesium scene. Pick results keep Cesium's `id` and
// `primitive`; the untouched Cesium result rides along as `object` for
// Cesium-only callers.
import { toCesium2, toGeo3 } from './convert.js';
const normalise = (picked) =>
picked == null
? undefined
: { id: picked.id, primitive: picked.primitive, object: picked };
/**
* @param {Cesium.Viewer} viewer
* @returns {{ picker: object, destroy: () => void }}
*/
export function createCesiumPicker(viewer) {
const { scene } = viewer;
const picker = {
pick(screen, width, height) {
return normalise(scene.pick(toCesium2(screen), width, height));
},
drillPick(screen, limit) {
return scene.drillPick(toCesium2(screen), limit).map(normalise);
},
pickPosition(screen) {
if (!scene.pickPositionSupported) return undefined;
try {
// A new Cesium.Cartesian2 per call: Cesium caches by its toString().
return toGeo3(scene.pickPosition(toCesium2(screen)));
} catch {
return undefined;
}
},
get pickPositionSupported() {
return Boolean(scene.pickPositionSupported);
},
};
return { picker, destroy() {} };
}