mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
refactor(ui,voice,annotations,scenes): take vector maths from src/geo
Move the Cartesian3/Cartographic/Matrix4/Transforms/Ellipsoid/Math calls of the second batch (cockpit camera, context and controller; camera orientation controls; application shell; location navigation; the annotation resolver and engine; voice actions and pointer pick; the scene director; the embed app) to src/geo. Behaviour is unchanged: same argument order, same `result` semantics. Kept on Cesium: out-of-scope classes (HeadingPitchRange, BoundingSphere, Intersect, EllipsoidalOccluder, EasingFunction, SceneTransforms, JulianDate), WGS84 where it goes into pickEllipsoid or EllipsoidalOccluder, Matrix4.IDENTITY handed to lookAtTransform, and the Cartesian2 window positions that reach scene.pickPosition: Cesium keys its per-frame pick cache on windowPosition.toString(), which a plain object would collapse to one "[object Object]" key. The Contacts-subject harness in gevActions.test stubbed Cesium.Cartographic.fromCartesian to place its subject; it now builds a real subject position at the same coordinates with geo.cartesian3.fromDegrees. The cockpit-controls and scenes package-boundary groups now own the src/geo files.
This commit is contained in:
1 parent
d886be68a8
commit
1a69368ae6
14 files changed
+216
-200
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { isUnavailableCapability } from '../sources/capability.js';
|
||||
import { defaultGeospatial } from '../search/defaults.js';
|
||||
import * as Cesium from 'cesium';
|
||||
import * as geo from '../geo/index.js';
|
||||
import {
|
||||
holdContinuousRender,
|
||||
releaseContinuousRender,
|
||||
@@ -1013,13 +1014,13 @@ export function createAnnotationEngine({
|
||||
return;
|
||||
}
|
||||
const cart = points.map((p) =>
|
||||
Cesium.Cartesian3.fromDegrees(p.lon, p.lat, p.height || 0),
|
||||
geo.cartesian3.fromDegrees(p.lon, p.lat, p.height || 0),
|
||||
);
|
||||
const sphere = Cesium.BoundingSphere.fromPoints(cart);
|
||||
viewer.camera.flyToBoundingSphere(sphere, {
|
||||
offset: new Cesium.HeadingPitchRange(
|
||||
viewer.camera.heading,
|
||||
Cesium.Math.toRadians(-35),
|
||||
geo.math.toRadians(-35),
|
||||
Math.max(900, sphere.radius * 2.6),
|
||||
),
|
||||
duration: 1.6,
|
||||
@@ -1034,7 +1035,7 @@ export function createAnnotationEngine({
|
||||
function isPointOnScreen(p) {
|
||||
try {
|
||||
const camera = viewer.camera;
|
||||
const pos = Cesium.Cartesian3.fromDegrees(p.lon, p.lat, p.height || 0);
|
||||
const pos = geo.cartesian3.fromDegrees(p.lon, p.lat, p.height || 0);
|
||||
const cv = camera.frustum.computeCullingVolume(
|
||||
camera.position,
|
||||
camera.direction,
|
||||
@@ -1075,7 +1076,7 @@ export function createAnnotationEngine({
|
||||
: viewportRange(anno.viewport) || 600;
|
||||
viewer.camera.flyToBoundingSphere(
|
||||
new Cesium.BoundingSphere(
|
||||
Cesium.Cartesian3.fromDegrees(
|
||||
geo.cartesian3.fromDegrees(
|
||||
target.lon,
|
||||
target.lat,
|
||||
anno.anchor.height || 0,
|
||||
@@ -1085,7 +1086,7 @@ export function createAnnotationEngine({
|
||||
{
|
||||
offset: new Cesium.HeadingPitchRange(
|
||||
viewer.camera.heading,
|
||||
Cesium.Math.toRadians(-35),
|
||||
geo.math.toRadians(-35),
|
||||
range * 2.4,
|
||||
),
|
||||
duration: 1.8,
|
||||
@@ -1275,10 +1276,10 @@ export function createAnnotationEngine({
|
||||
if (destroyed) return;
|
||||
try {
|
||||
viewer.camera.flyTo({
|
||||
destination: Cesium.Cartesian3.fromDegrees(lon, lat, height),
|
||||
destination: geo.cartesian3.fromDegrees(lon, lat, height),
|
||||
orientation: {
|
||||
heading: Cesium.Math.toRadians(heading),
|
||||
pitch: Cesium.Math.toRadians(pitch),
|
||||
heading: geo.math.toRadians(heading),
|
||||
pitch: geo.math.toRadians(pitch),
|
||||
roll: 0,
|
||||
},
|
||||
duration,
|
||||
@@ -1395,9 +1396,9 @@ const VIEWPORT_ASSIST_RANGE_CAP_M = 120000;
|
||||
function viewportRange(vp) {
|
||||
if (!vp?.low || !vp?.high) return null;
|
||||
try {
|
||||
const span = Cesium.Cartesian3.distance(
|
||||
Cesium.Cartesian3.fromDegrees(vp.low.longitude, vp.low.latitude),
|
||||
Cesium.Cartesian3.fromDegrees(vp.high.longitude, vp.high.latitude),
|
||||
const span = geo.cartesian3.distance(
|
||||
geo.cartesian3.fromDegrees(vp.low.longitude, vp.low.latitude),
|
||||
geo.cartesian3.fromDegrees(vp.high.longitude, vp.high.latitude),
|
||||
);
|
||||
return Number.isFinite(span) && span > 0
|
||||
? Math.max(300, Math.min(span * 0.7, VIEWPORT_ASSIST_RANGE_CAP_M))
|
||||
@@ -1422,9 +1423,9 @@ function ringRange(ring) {
|
||||
if (lon < minLon) minLon = lon;
|
||||
if (lon > maxLon) maxLon = lon;
|
||||
}
|
||||
const span = Cesium.Cartesian3.distance(
|
||||
Cesium.Cartesian3.fromDegrees(minLon, minLat),
|
||||
Cesium.Cartesian3.fromDegrees(maxLon, maxLat),
|
||||
const span = geo.cartesian3.distance(
|
||||
geo.cartesian3.fromDegrees(minLon, minLat),
|
||||
geo.cartesian3.fromDegrees(maxLon, maxLat),
|
||||
);
|
||||
return Math.max(300, span * 0.7);
|
||||
}
|
||||
|
||||
+14
-13
@@ -14,6 +14,7 @@ import {
|
||||
} from '../sources/featureGeometry.js';
|
||||
import { defaultGeospatial } from '../search/defaults.js';
|
||||
import * as Cesium from 'cesium';
|
||||
import * as geo from '../geo/index.js';
|
||||
import { lookupNeighborhoodRing } from '../data/neighborhoodPolygons.js';
|
||||
import {
|
||||
lookupNaturalRegionOutline,
|
||||
@@ -1835,8 +1836,8 @@ export function createAnnotationResolver({
|
||||
try {
|
||||
const carto = viewer?.camera?.positionCartographic;
|
||||
if (!carto) return null;
|
||||
const lat = Cesium.Math.toDegrees(carto.latitude);
|
||||
const lon = Cesium.Math.toDegrees(carto.longitude);
|
||||
const lat = geo.math.toDegrees(carto.latitude);
|
||||
const lon = geo.math.toDegrees(carto.longitude);
|
||||
const radiusKm = Math.max((carto.height / 1000) * 3, 5);
|
||||
if (![lat, lon, radiusKm].every(Number.isFinite)) return null;
|
||||
return { lat, lon, radiusKm };
|
||||
@@ -1850,10 +1851,10 @@ export function createAnnotationResolver({
|
||||
try {
|
||||
const rect = viewer?.camera?.computeViewRectangle?.();
|
||||
if (!rect) return null;
|
||||
const swLat = Cesium.Math.toDegrees(rect.south).toFixed(4);
|
||||
const swLng = Cesium.Math.toDegrees(rect.west).toFixed(4);
|
||||
const neLat = Cesium.Math.toDegrees(rect.north).toFixed(4);
|
||||
const neLng = Cesium.Math.toDegrees(rect.east).toFixed(4);
|
||||
const swLat = geo.math.toDegrees(rect.south).toFixed(4);
|
||||
const swLng = geo.math.toDegrees(rect.west).toFixed(4);
|
||||
const neLat = geo.math.toDegrees(rect.north).toFixed(4);
|
||||
const neLng = geo.math.toDegrees(rect.east).toFixed(4);
|
||||
if ([swLat, swLng, neLat, neLng].some((v) => v === 'NaN')) return null;
|
||||
return `${swLat},${swLng}|${neLat},${neLng}`;
|
||||
} catch {
|
||||
@@ -1953,11 +1954,11 @@ export function createAnnotationResolver({
|
||||
}
|
||||
}
|
||||
if (!isPickedWorldPosition(cart)) return null;
|
||||
const carto = Cesium.Cartographic.fromCartesian(cart);
|
||||
const carto = geo.cartographic.fromCartesian(cart);
|
||||
if (!carto) return null;
|
||||
return {
|
||||
lat: Cesium.Math.toDegrees(carto.latitude),
|
||||
lon: Cesium.Math.toDegrees(carto.longitude),
|
||||
lat: geo.math.toDegrees(carto.latitude),
|
||||
lon: geo.math.toDegrees(carto.longitude),
|
||||
// The height the pick actually landed on — a roof, a hillside, or 0 on
|
||||
// the ellipsoid. Callers that only want a coordinate ignore it; the draw
|
||||
// tool's live preview needs it, or the rubber band sinks to sea level
|
||||
@@ -1979,11 +1980,11 @@ export function createAnnotationResolver({
|
||||
scene.clampToHeightSupported &&
|
||||
typeof scene.clampToHeight === 'function'
|
||||
) {
|
||||
const carto = Cesium.Cartographic.fromDegrees(lon, lat);
|
||||
const surface = Cesium.Cartographic.toCartesian(carto);
|
||||
const carto = geo.cartographic.fromDegrees(lon, lat);
|
||||
const surface = geo.cartographic.toCartesian(carto);
|
||||
const clamped = scene.clampToHeight(surface);
|
||||
if (clamped) {
|
||||
const h = Cesium.Cartographic.fromCartesian(clamped).height;
|
||||
const h = geo.cartographic.fromCartesian(clamped).height;
|
||||
if (Number.isFinite(h)) return h;
|
||||
}
|
||||
}
|
||||
@@ -1991,7 +1992,7 @@ export function createAnnotationResolver({
|
||||
/* tiles not ready — fall through */
|
||||
}
|
||||
const globeHeight = scene.globe?.getHeight?.(
|
||||
Cesium.Cartographic.fromDegrees(lon, lat),
|
||||
geo.cartographic.fromDegrees(lon, lat),
|
||||
);
|
||||
return Number.isFinite(globeHeight) && globeHeight > 0 ? globeHeight : 0;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user