mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
Brings in the wildlife sightings layer (#1591, iNaturalist and Acartia sightings). Its badges, density glow and privacy cells draw through the draw port: the badges and the glow are icons sets (iconCollection.js batches point writes into one upsert per task), and the privacy cells are ground-clamped shapes and lines sets swapped whole. The eye, the view rectangle, clicks, projection, ground readiness and frames come from the camera, query, input, globe and frame ports, so the layer, its card and its placement no longer import Cesium. Differences from main: the density glow is drawn as pixel-sized splats (56 px) instead of metre-sized ones with a near fade; the card's pan eases with cubicOut, the contract's nearest ease-out; ground heights are resampled when the globe's load progress settles or its surface changes, rather than on tileset load events. Also fixes two things the last merge left: a double-click that starts on the followed track and ends off it reaches the renderer's own follow again (a press that cannot end a double-click on the track gives its hold back at its release), and the Active Fires heat drapes under the weather imagery, so weather turned on after it stacks above. CURRENT-STATE notes that the 2D and Columbus scene-mode checks are gone.
102 lines
3.5 KiB
JavaScript
102 lines
3.5 KiB
JavaScript
/**
|
|
* One-click camera transfer for layer-owned world targets.
|
|
*/
|
|
import { WGS84, toRadians } from './geo/index.js';
|
|
import { findCamera } from './render/rendererOf.js';
|
|
|
|
export const WORLD_FOCUS_REQUEST_EVENT = 'gev:world-request-focus';
|
|
export const WORLD_CLICK_FOCUS_DURATION_SEC = 1.9;
|
|
|
|
export const WORLD_FOCUS_FRAMING = Object.freeze({
|
|
vessel: Object.freeze({ radiusM: 150, rangeM: 1200, pitchDeg: -30 }),
|
|
fire: Object.freeze({ radiusM: 400, rangeM: 3000, pitchDeg: -35 }),
|
|
sighting: Object.freeze({ radiusM: 250, rangeM: 2500, pitchDeg: -40 }),
|
|
'sighting-area': Object.freeze({
|
|
radiusM: 11000,
|
|
rangeM: 60000,
|
|
pitchDeg: -55,
|
|
}),
|
|
});
|
|
|
|
/** Validate a layer-owned focus target before camera policy can release tracking. */
|
|
export function isValidWorldFocusTarget(detail) {
|
|
if (!detail || !WORLD_FOCUS_FRAMING[detail.kind]) return false;
|
|
if (!String(detail.id || '').trim()) return false;
|
|
const { position } = detail;
|
|
if (
|
|
!position ||
|
|
!Number.isFinite(position.x) ||
|
|
!Number.isFinite(position.y) ||
|
|
!Number.isFinite(position.z)
|
|
)
|
|
return false;
|
|
// These targets are surface-anchored Earth positions. Merely
|
|
// finite coordinates near the ECEF origin cannot be flown to, and must be
|
|
// rejected before the camera policy releases a current follow owner.
|
|
const magnitude = Math.hypot(position.x, position.y, position.z);
|
|
return Number.isFinite(magnitude) && magnitude >= WGS84.radii.z * 0.95;
|
|
}
|
|
|
|
/** Announce a valid user-click focus request. */
|
|
export function requestWorldFocus(detail, eventTarget = globalThis.window) {
|
|
if (!isValidWorldFocusTarget(detail)) return false;
|
|
if (typeof eventTarget?.dispatchEvent !== 'function') return false;
|
|
eventTarget.dispatchEvent(
|
|
new CustomEvent(WORLD_FOCUS_REQUEST_EVENT, { detail }),
|
|
);
|
|
return true;
|
|
}
|
|
|
|
/** Register one listener and return an idempotent disposer. */
|
|
export function registerWorldFocusRequestListener(eventTarget, listener) {
|
|
if (
|
|
!eventTarget?.addEventListener ||
|
|
!eventTarget?.removeEventListener ||
|
|
typeof listener !== 'function'
|
|
)
|
|
return () => {};
|
|
eventTarget.addEventListener(WORLD_FOCUS_REQUEST_EVENT, listener);
|
|
let disposed = false;
|
|
return () => {
|
|
if (disposed) return;
|
|
disposed = true;
|
|
eventTarget.removeEventListener(WORLD_FOCUS_REQUEST_EVENT, listener);
|
|
};
|
|
}
|
|
|
|
/** Route a valid request through the UI-owned camera policy. */
|
|
export function routeWorldFocusRequest(event, runExplicitFocus, fly) {
|
|
const detail = event?.detail;
|
|
if (!isValidWorldFocusTarget(detail)) return false;
|
|
if (typeof runExplicitFocus !== 'function' || typeof fly !== 'function')
|
|
return false;
|
|
return runExplicitFocus(detail, () => fly(detail));
|
|
}
|
|
|
|
/** Fly to a world target after ownership has been released. */
|
|
export function flyToWorldTarget(viewer, target = {}) {
|
|
const camera = findCamera(viewer);
|
|
const framing = WORLD_FOCUS_FRAMING[target.kind];
|
|
if (!camera || !framing || !isValidWorldFocusTarget(target)) return false;
|
|
const poseHeading = camera.pose().heading;
|
|
const heading = Number.isFinite(poseHeading) ? poseHeading : 0;
|
|
const duration =
|
|
target.durationSec > 0
|
|
? target.durationSec
|
|
: WORLD_CLICK_FOCUS_DURATION_SEC;
|
|
camera.cancelFlight();
|
|
camera.flyToBounds(
|
|
{ center: target.position, radius: framing.radiusM },
|
|
{
|
|
offset: {
|
|
heading,
|
|
pitch: toRadians(framing.pitchDeg),
|
|
range: framing.rangeM,
|
|
},
|
|
durationS: duration,
|
|
easing: 'cubicInOut',
|
|
},
|
|
);
|
|
return true;
|
|
}
|