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
@@ -1,4 +1,5 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import * as geo from '../../geo/index.js';
|
||||
import { tilesForBounds, tileToBBox } from '../../data/tomtomTiles.js';
|
||||
|
||||
export const RETICLE_RANGE_KM = 10;
|
||||
@@ -64,17 +65,17 @@ export function footprintTiles(polygon, zoom, near) {
|
||||
|
||||
/** Reusable camera scratch; sampled only on camera events, never in the animation loop. */
|
||||
export function createReticleFootprint() {
|
||||
const pixels = Array.from({ length: 25 }, () => new Cesium.Cartesian2());
|
||||
const hits = Array.from({ length: 25 }, () => new Cesium.Cartesian3());
|
||||
const carto = new Cesium.Cartographic();
|
||||
const pixels = Array.from({ length: 25 }, () => geo.cartesian2.create());
|
||||
const hits = Array.from({ length: 25 }, () => geo.cartesian3.create());
|
||||
const carto = geo.cartographic.create();
|
||||
const ray = new Cesium.Ray();
|
||||
return (viewer, altitude) => {
|
||||
const { camera, scene } = viewer;
|
||||
if (!camera.getPickRay) return null;
|
||||
const nadir = camera.positionCartographic;
|
||||
const near = {
|
||||
lat: Cesium.Math.toDegrees(nadir.latitude),
|
||||
lon: Cesium.Math.toDegrees(nadir.longitude),
|
||||
lat: geo.math.toDegrees(nadir.latitude),
|
||||
lon: geo.math.toDegrees(nadir.longitude),
|
||||
};
|
||||
const width = scene.canvas.clientWidth || scene.canvas.width,
|
||||
height = scene.canvas.clientHeight || scene.canvas.height;
|
||||
@@ -91,9 +92,9 @@ export function createReticleFootprint() {
|
||||
const hit = camera.pickEllipsoid(p, Cesium.Ellipsoid.WGS84, hits[i]);
|
||||
let dx, dy;
|
||||
if (hit) {
|
||||
Cesium.Cartographic.fromCartesian(hit, Cesium.Ellipsoid.WGS84, carto);
|
||||
dy = (Cesium.Math.toDegrees(carto.latitude) - near.lat) * 111.195;
|
||||
let dlon = Cesium.Math.toDegrees(carto.longitude) - near.lon;
|
||||
geo.cartographic.fromCartesian(hit, geo.ellipsoid.WGS84, carto);
|
||||
dy = (geo.math.toDegrees(carto.latitude) - near.lat) * 111.195;
|
||||
let dlon = geo.math.toDegrees(carto.longitude) - near.lon;
|
||||
dlon -= 360 * Math.round(dlon / 360);
|
||||
dx = dlon * 111.195 * Math.cos(nadir.latitude);
|
||||
} else {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import * as geo from '../../geo/index.js';
|
||||
import { requestWithDeadline } from '../../sources/requestDeadline.js';
|
||||
import { resolveRoadMode, ROAD_SOURCE_LABELS } from './roadModes.js';
|
||||
import { phaseTiming } from '../../sources/phaseTiming.js';
|
||||
@@ -271,7 +271,7 @@ export function createIngestion({
|
||||
const centerLat = (clamped.south + clamped.north) / 2;
|
||||
const centerLon = (clamped.west + clamped.east) / 2;
|
||||
const scene = layerState._viewer?.scene;
|
||||
const location = Cesium.Cartographic.fromDegrees(centerLon, centerLat);
|
||||
const location = geo.cartographic.fromDegrees(centerLon, centerLat);
|
||||
let estimated = services.ground?.cachedGroundFloor?.(centerLat, centerLon);
|
||||
if (!Number.isFinite(estimated)) {
|
||||
try {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { createReticleFootprint } from './footprint.js';
|
||||
import * as Cesium from 'cesium';
|
||||
import * as geo from '../../geo/index.js';
|
||||
import {
|
||||
deriveFetchCenter,
|
||||
clampBoundsAroundCenter,
|
||||
@@ -37,10 +38,10 @@ export function createViewport({ state: layerState, services, parts, source }) {
|
||||
const rect = layerState._viewer.camera.computeViewRectangle();
|
||||
if (!rect) return null;
|
||||
return {
|
||||
south: Cesium.Math.toDegrees(rect.south),
|
||||
west: Cesium.Math.toDegrees(rect.west),
|
||||
north: Cesium.Math.toDegrees(rect.north),
|
||||
east: Cesium.Math.toDegrees(rect.east),
|
||||
south: geo.math.toDegrees(rect.south),
|
||||
west: geo.math.toDegrees(rect.west),
|
||||
north: geo.math.toDegrees(rect.north),
|
||||
east: geo.math.toDegrees(rect.east),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -61,8 +62,8 @@ export function createViewport({ state: layerState, services, parts, source }) {
|
||||
function getFetchCenter() {
|
||||
const carto = layerState._viewer.camera.positionCartographic;
|
||||
if (!carto) return null;
|
||||
const nadirLat = Cesium.Math.toDegrees(carto.latitude);
|
||||
const nadirLon = Cesium.Math.toDegrees(carto.longitude);
|
||||
const nadirLat = geo.math.toDegrees(carto.latitude);
|
||||
const nadirLon = geo.math.toDegrees(carto.longitude);
|
||||
|
||||
let hitLat;
|
||||
let hitLon;
|
||||
@@ -71,13 +72,13 @@ export function createViewport({ state: layerState, services, parts, source }) {
|
||||
const height = canvas.clientHeight || canvas.height;
|
||||
if (width > 0 && height > 0) {
|
||||
const hit = layerState._viewer.camera.pickEllipsoid(
|
||||
new Cesium.Cartesian2(width / 2, height / 2),
|
||||
geo.cartesian2.create(width / 2, height / 2),
|
||||
Cesium.Ellipsoid.WGS84,
|
||||
);
|
||||
if (hit) {
|
||||
const hitCarto = Cesium.Cartographic.fromCartesian(hit);
|
||||
hitLat = Cesium.Math.toDegrees(hitCarto.latitude);
|
||||
hitLon = Cesium.Math.toDegrees(hitCarto.longitude);
|
||||
const hitCarto = geo.cartographic.fromCartesian(hit);
|
||||
hitLat = geo.math.toDegrees(hitCarto.latitude);
|
||||
hitLon = geo.math.toDegrees(hitCarto.longitude);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user