mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-18 01:02:23 +00:00
refactor(streetLevel,traffic,transit,firms,installations,radio,bikeshare,cables,detection): take vector maths from src/geo
Street level view/cameraFollow/groundClick/index, traffic footprint/viewport/ingestion, transit viewport/trails/state/rendering, FIRMS state/viewport, installations controls/viewport/state, radio queries/navigation/state, bikeshare viewport, submarine cable overlay and data/detection now use src/geo for Math, Cartesian2/3, Cartographic and WGS84 maths. Cesium stays for Rectangle, Ray, BoundingSphere, HeadingPitchRange, EasingFunction, EllipsoidGeodesic, EllipsoidalOccluder and the Ellipsoids passed into Cesium (pickEllipsoid, occluders). traffic/state.js keeps its Cesium lerp scratch (written per frame by Cesium.Cartesian3.lerp in animation.js; a geo scratch cost +4-7% there) and traffic/timing.js stays on Cesium (a test keeps it source-equivalent to model.parseRoads, outside this batch). street-level-layer, traffic-layer, installations-layer, bikeshare-layer and submarine-cables own the src/geo files.
This commit is contained in:
1 parent
a915bdb3e5
commit
e3061872cc
23 files changed
+231
-162
No files matched your search
Vendored
+12
-11
@@ -1,4 +1,5 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import * as geo from '../../geo/index.js';
|
||||
import { installationFeedback } from '../../data/installationFeedback.js';
|
||||
import {
|
||||
LAYER_ID,
|
||||
@@ -51,17 +52,17 @@ export function createControls({ state: layerState, services, parts, source }) {
|
||||
)
|
||||
next = { latitude: position.latitude, longitude: position.longitude };
|
||||
else {
|
||||
const carto = Cesium.Cartographic.fromCartesian(position);
|
||||
const carto = geo.cartographic.fromCartesian(position);
|
||||
if (carto)
|
||||
next = {
|
||||
latitude: Cesium.Math.toDegrees(carto.latitude),
|
||||
longitude: Cesium.Math.toDegrees(carto.longitude),
|
||||
latitude: geo.math.toDegrees(carto.latitude),
|
||||
longitude: geo.math.toDegrees(carto.longitude),
|
||||
};
|
||||
}
|
||||
}
|
||||
// Keep the live centre even when the coarse fetch anchor has not moved.
|
||||
layerState.contextPosition = next
|
||||
? Cesium.Cartesian3.fromDegrees(next.longitude, next.latitude)
|
||||
? geo.cartesian3.fromDegrees(next.longitude, next.latitude)
|
||||
: null;
|
||||
const previous = layerState.contextAnchor;
|
||||
if (!next) {
|
||||
@@ -73,8 +74,8 @@ export function createControls({ state: layerState, services, parts, source }) {
|
||||
if (
|
||||
previous &&
|
||||
parts.model.approximateSurfaceDistanceM(
|
||||
Cesium.Math.toRadians(previous.latitude),
|
||||
Cesium.Math.toRadians(previous.longitude),
|
||||
geo.math.toRadians(previous.latitude),
|
||||
geo.math.toRadians(previous.longitude),
|
||||
next.latitude,
|
||||
next.longitude,
|
||||
) < ANCHOR_REFRESH_M
|
||||
@@ -88,7 +89,7 @@ export function createControls({ state: layerState, services, parts, source }) {
|
||||
getNearby(center, rangeM, maxCount = 50) {
|
||||
if (!center) return [];
|
||||
const range = Number.isFinite(rangeM) ? rangeM : Infinity;
|
||||
const centerCartographic = Cesium.Cartographic.fromCartesian(center);
|
||||
const centerCartographic = geo.cartographic.fromCartesian(center);
|
||||
if (!centerCartographic) return [];
|
||||
const nearby = [];
|
||||
const approximateLimit = Number.isFinite(range)
|
||||
@@ -107,10 +108,10 @@ export function createControls({ state: layerState, services, parts, source }) {
|
||||
continue;
|
||||
// The awareness disk is projected onto the ground. Confirm candidates
|
||||
// with an exact ellipsoidal surface distance and reusable scratch state.
|
||||
layerState.distanceEndpointScratch.longitude = Cesium.Math.toRadians(
|
||||
layerState.distanceEndpointScratch.longitude = geo.math.toRadians(
|
||||
record.longitude,
|
||||
);
|
||||
layerState.distanceEndpointScratch.latitude = Cesium.Math.toRadians(
|
||||
layerState.distanceEndpointScratch.latitude = geo.math.toRadians(
|
||||
record.latitude,
|
||||
);
|
||||
layerState.distanceEndpointScratch.height = 0;
|
||||
@@ -122,7 +123,7 @@ export function createControls({ state: layerState, services, parts, source }) {
|
||||
if (!Number.isFinite(distanceM) || distanceM > range) continue;
|
||||
nearby.push({
|
||||
...record,
|
||||
position: Cesium.Cartesian3.fromDegrees(
|
||||
position: geo.cartesian3.fromDegrees(
|
||||
record.longitude,
|
||||
record.latitude,
|
||||
parts.rendering.installationSurfaceHeightM(record),
|
||||
@@ -150,7 +151,7 @@ export function createControls({ state: layerState, services, parts, source }) {
|
||||
if (!parts.selection.selectRecord(record.id)) return false;
|
||||
layerState.viewer.camera.flyToBoundingSphere(
|
||||
new Cesium.BoundingSphere(
|
||||
Cesium.Cartesian3.fromDegrees(
|
||||
geo.cartesian3.fromDegrees(
|
||||
record.longitude,
|
||||
record.latitude,
|
||||
parts.rendering.installationSurfaceHeightM(record),
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import * as geo from '../../geo/index.js';
|
||||
|
||||
export function createState({ services }) {
|
||||
const state = {};
|
||||
|
||||
state.distanceEndpointScratch = new Cesium.Cartographic();
|
||||
state.distanceEndpointScratch = geo.cartographic.create();
|
||||
|
||||
state.distanceGeodesicScratch = new Cesium.EllipsoidGeodesic();
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import * as geo from '../../geo/index.js';
|
||||
import { REQUEST_DEBOUNCE_MS } from './policy.js';
|
||||
import { installationAnchorBox } from './source.js';
|
||||
|
||||
@@ -27,10 +27,10 @@ export function createViewport({ state: layerState, services, parts, source }) {
|
||||
viewer.scene.globe.ellipsoid,
|
||||
);
|
||||
if (!rectangle) return null;
|
||||
const south = Cesium.Math.toDegrees(rectangle.south);
|
||||
const north = Cesium.Math.toDegrees(rectangle.north);
|
||||
const west = Cesium.Math.toDegrees(rectangle.west);
|
||||
const east = Cesium.Math.toDegrees(rectangle.east);
|
||||
const south = geo.math.toDegrees(rectangle.south);
|
||||
const north = geo.math.toDegrees(rectangle.north);
|
||||
const west = geo.math.toDegrees(rectangle.west);
|
||||
const east = geo.math.toDegrees(rectangle.east);
|
||||
// Wide and dateline views use the bundled point index.
|
||||
if (
|
||||
!Number.isFinite(south + north + west + east) ||
|
||||
|
||||
Reference in new issue
Block a user