mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
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.
40 lines
1.2 KiB
JavaScript
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() {} };
|
|
}
|