mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Share links read the current follow handle and displayed position through engine.camera and restore their ENU offset with follow's swingTo option. Cesium retains its first-frame wait, displayed-position cache, 60-degree frame limit and range interpolation. Navara and the fake engine apply the same swing. Cancellation, camera handoff and destruction release it; an externally tracked Cesium entity keeps its existing handle. Draw uses one surface with engine input, geodesic lines and point movers. An exclusive pointer claim suppresses ambient subscriptions and deferred picks across ownership changes. Cesium owns suspension and exact restoration of its stock select and track actions. Camera gestures remain enabled. Detaching releases the sketch and preview and retains shape and colour. The separate Navara surface and Cesium data-source preview are removed. Cesium remains the reference for clicked heights, line width and dash, vertex size and outline, keyboard handling and completed annotations. One deliberate visual fix is that the occluded rubber band uses the selected colour instead of retaining the initial amber: it now identifies the same sketch as its visible segment. Navara adopts Cesium's geodesic preview edges. Finished annotation drapes are unchanged. External Cesium import files fall from 7 to 5, viewer lines from 1005 to 953, and engine-name lines from 39 to 37. No coupling metric grows. The full unit suite, import directions, package boundaries, formatting and coupling checks pass. Checked in the browser, keyless: the contract suite passes on Navara and on Cesium apart from the camera-events check that also fails intermittently before; qa-navara-draw passes; qa-draw-tool passes apart from its hidden-line pixel check, which fails the same way before this change. Its destroy check now expects no preview data source, since the preview has none.
60 lines
1.9 KiB
JavaScript
60 lines
1.9 KiB
JavaScript
import * as geo from '../geo/index.js';
|
|
import { enuOffset } from '../globe/follow.js';
|
|
import {
|
|
SHARE_VIEW_ENTITY_KINDS,
|
|
followOffsetFromEnu,
|
|
followOffsetToEnu,
|
|
} from '../share/follow.js';
|
|
|
|
const KIND_BY_LAYER = new Map(
|
|
SHARE_VIEW_ENTITY_KINDS.map((entry) => [entry.layerId, entry.kind]),
|
|
);
|
|
|
|
/** The followed subject, camera offset and displayed fix in share format. */
|
|
export function readShareFollowSubject({ engine, nowMs = Date.now() }) {
|
|
const handle = engine?.camera.following();
|
|
const trackedId = String(
|
|
handle?.label?.id || handle?.native?.gevTrackedId || '',
|
|
);
|
|
const separator = trackedId.indexOf(':');
|
|
if (separator <= 0) return null;
|
|
const kind = KIND_BY_LAYER.get(trackedId.slice(0, separator));
|
|
const id = trackedId.slice(separator + 1);
|
|
const target = kind ? (handle.label?.position?.() ?? handle.target()) : null;
|
|
if (!kind || !id || !target) return null;
|
|
const local = enuOffset(target, engine.camera.pose().position);
|
|
const offset = followOffsetFromEnu({
|
|
east: local.x,
|
|
north: local.y,
|
|
up: local.z,
|
|
});
|
|
const fix = geo.cartographic.fromCartesian(target);
|
|
if (!offset || !fix) return null;
|
|
return {
|
|
kind,
|
|
id,
|
|
offset,
|
|
lastKnown: {
|
|
lat: geo.math.toDegrees(fix.latitude),
|
|
lon: geo.math.toDegrees(fix.longitude),
|
|
alt: fix.height,
|
|
observedAtMs: nowMs,
|
|
},
|
|
};
|
|
}
|
|
|
|
/** Swing the current follow to a shared ENU offset; return its cancellation. */
|
|
export function applyShareFollowOffset(engine, handle, offset) {
|
|
if (!handle || engine?.camera.following() !== handle || !(offset?.range > 0))
|
|
return () => {};
|
|
const local = followOffsetToEnu(offset);
|
|
handle.retarget({ swingTo: { x: local.east, y: local.north, z: local.up } });
|
|
let stopped = false;
|
|
return () => {
|
|
if (stopped) return;
|
|
stopped = true;
|
|
if (engine.camera.following() === handle)
|
|
handle.retarget({ swingTo: null });
|
|
};
|
|
}
|