mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-18 01:02:23 +00:00
Run the Navara paths without the Cesium SDK, and load it on demand for the features that still build on it
Every Cesium read that a Navara page made was surveyed with the strict acceptance (GEV_QA_CESIUM_TRAP=record). Math on those paths now uses src/geo: screen annotations, weather and wind center readings, cyclone picks, scene data pack polygons and images (new navaraGeometry.js), the awareness subject, the orbit offset of camera verbs, voice frame_overhead, the agent world packet and Directions colours and ground picks. The celestial ring's Sun and Moon come from a bit-identical port of Cesium's Simon1994 model, JulianDate and TEME rotation (src/geo/simon1994.js, julianDate.js, transforms.js); a Cesium globe still applies its ICRF rotation once loaded. Traffic, Street Level, the Nepal event and locator and geo import build on Cesium's math or entity model on either globe; their enable (or the import) now loads the SDK first through src/app/loadCesium.js, synchronously when it is already there. A production page guards the global so a missed read is reported and starts the load. No module reads Cesium while it loads (scripts/check-cesium-load-time.mjs, run by npm test). Cesium.js is still loaded by index.html here.
This commit is contained in:
1 parent
f87da8523e
commit
b8305de14b
58 files changed
+2130
-325
No files matched your search
@@ -43,7 +43,9 @@ test('passive Contacts releases its installation anchor and subject refresh cann
|
||||
const subject = createSubject({ state, services, parts });
|
||||
subject.refreshSelectedSubject();
|
||||
assert.equal(anchors.length, 1);
|
||||
assert.ok(anchors[0] instanceof Cesium.Cartesian3);
|
||||
// A copy of the subject's position, not the live one.
|
||||
assert.notEqual(anchors[0], position);
|
||||
assert.deepEqual({ ...anchors[0] }, { ...position });
|
||||
controls.setParams({ passive: true });
|
||||
assert.equal(anchors.at(-1), null);
|
||||
const released = anchors.length;
|
||||
@@ -57,5 +59,5 @@ test('passive Contacts releases its installation anchor and subject refresh cann
|
||||
controls.setParams({ passive: false });
|
||||
assert.equal(activations, 1);
|
||||
subject.refreshSelectedSubject();
|
||||
assert.ok(anchors.at(-1) instanceof Cesium.Cartesian3);
|
||||
assert.deepEqual({ ...anchors.at(-1) }, { ...position });
|
||||
});
|
||||
@@ -2,7 +2,6 @@ import {
|
||||
AWARENESS_RADIUS_M,
|
||||
AWARENESS_RELATIONSHIP,
|
||||
} from '../../data/militaryAwarenessEngine.js';
|
||||
import * as Cesium from 'cesium';
|
||||
import * as geo from '../../geo/index.js';
|
||||
import { t } from '../../i18n/index.js';
|
||||
import {
|
||||
@@ -265,7 +264,7 @@ export function createSubject({ state: layerState, services, parts, source }) {
|
||||
layerState.display?.trackedEntity?.gevDisplayPosition?.();
|
||||
if (trackedPosition) {
|
||||
return {
|
||||
position: Cesium.Cartesian3.clone(trackedPosition),
|
||||
position: geo.cartesian3.clone(trackedPosition),
|
||||
// Only the follow camera's own contact proves presence this way; a
|
||||
// different tracked entity says nothing about this subject.
|
||||
presence:
|
||||
@@ -280,7 +279,7 @@ export function createSubject({ state: layerState, services, parts, source }) {
|
||||
// awareness position instead of allocating/scanning up to 1,000 contacts.
|
||||
if (!allowCollectionMaterialization) {
|
||||
return {
|
||||
position: Cesium.Cartesian3.clone(subject.position),
|
||||
position: geo.cartesian3.clone(subject.position),
|
||||
presence: SUBJECT_PRESENCE.UNCHECKED,
|
||||
};
|
||||
}
|
||||
@@ -295,7 +294,7 @@ export function createSubject({ state: layerState, services, parts, source }) {
|
||||
if (subject.layerId === 'ais-live-vessels') {
|
||||
if (!allowCollectionMaterialization) {
|
||||
return {
|
||||
position: Cesium.Cartesian3.clone(subject.position),
|
||||
position: geo.cartesian3.clone(subject.position),
|
||||
presence: SUBJECT_PRESENCE.UNCHECKED,
|
||||
};
|
||||
}
|
||||
@@ -308,7 +307,7 @@ export function createSubject({ state: layerState, services, parts, source }) {
|
||||
// Mapped installations come from static geometry, not a live feed: there is
|
||||
// nothing to be culled from.
|
||||
return {
|
||||
position: Cesium.Cartesian3.clone(subject.position),
|
||||
position: geo.cartesian3.clone(subject.position),
|
||||
presence: SUBJECT_PRESENCE.LIVE,
|
||||
};
|
||||
}
|
||||
@@ -343,8 +342,8 @@ export function createSubject({ state: layerState, services, parts, source }) {
|
||||
: SUBJECT_PRESENCE.UNCHECKED;
|
||||
return {
|
||||
position: current?.position
|
||||
? Cesium.Cartesian3.clone(current.position)
|
||||
: Cesium.Cartesian3.clone(subject.position),
|
||||
? geo.cartesian3.clone(current.position)
|
||||
: geo.cartesian3.clone(subject.position),
|
||||
presence,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ export function createCyclonesLayer({
|
||||
feed,
|
||||
hitTestOverlay = hitTestWorldOverlay,
|
||||
overlayHost,
|
||||
cesium = Cesium,
|
||||
cesium = null,
|
||||
createRendering = createCycloneRendering,
|
||||
createNativeRendering = null,
|
||||
matchMedia = globalThis.matchMedia?.bind(globalThis),
|
||||
@@ -99,24 +99,27 @@ export function createCyclonesLayer({
|
||||
selectedId = id;
|
||||
rendering?.setSelection(id);
|
||||
}
|
||||
// The SDK, on Cesium only: the production build's Cesium global loads with
|
||||
// the first Cesium globe, so a Navara page has none.
|
||||
const sdk = () => cesium ?? (engine?.kind === 'navara' ? null : Cesium);
|
||||
// Photorealistic 3D Tiles pick as tileset content without an entity id;
|
||||
// that is empty map, the same as no pick at all on the globe.
|
||||
const isSurfacePick = (picked) =>
|
||||
!picked ||
|
||||
(picked.id === undefined &&
|
||||
(picked.content !== undefined ||
|
||||
(typeof cesium.Cesium3DTileset === 'function' &&
|
||||
picked.primitive instanceof cesium.Cesium3DTileset)));
|
||||
(typeof sdk()?.Cesium3DTileset === 'function' &&
|
||||
picked.primitive instanceof sdk().Cesium3DTileset)));
|
||||
function installSelection() {
|
||||
const canvas = engine?.host.canvas ?? viewer?.scene?.canvas;
|
||||
const native = engine?.kind === 'navara';
|
||||
if (
|
||||
clickHandler ||
|
||||
!canvas ||
|
||||
(!native && typeof cesium.ScreenSpaceEventHandler !== 'function')
|
||||
(!native && typeof sdk()?.ScreenSpaceEventHandler !== 'function')
|
||||
)
|
||||
return;
|
||||
const owner = native ? {} : new cesium.ScreenSpaceEventHandler(canvas);
|
||||
const owner = native ? {} : new (sdk().ScreenSpaceEventHandler)(canvas);
|
||||
clickHandler = owner;
|
||||
let capturedHit = null;
|
||||
const overlayHit = (x, y) => {
|
||||
@@ -192,7 +195,7 @@ export function createCyclonesLayer({
|
||||
};
|
||||
if (native)
|
||||
owner.destroy = engine.input.on('click', onClick, { pick: true });
|
||||
else owner.setInputAction(onClick, cesium.ScreenSpaceEventType.LEFT_CLICK);
|
||||
else owner.setInputAction(onClick, sdk().ScreenSpaceEventType.LEFT_CLICK);
|
||||
}
|
||||
function removeSelection() {
|
||||
const owner = clickHandler;
|
||||
@@ -217,7 +220,7 @@ export function createCyclonesLayer({
|
||||
rendering =
|
||||
engine?.kind === 'navara'
|
||||
? createNativeRendering(engine, { overlayHost })
|
||||
: createRendering({ viewer, cesium, overlayHost });
|
||||
: createRendering({ viewer, cesium: sdk(), overlayHost });
|
||||
if (!enabled) return;
|
||||
installSelection();
|
||||
if (snapshot && !snapshot.unavailable) {
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
*/
|
||||
|
||||
import * as Cesium from 'cesium';
|
||||
import * as geo from '../../geo/index.js';
|
||||
import { WHITE, rgbaFromCss } from '../shared/color.js';
|
||||
import { roadLabel } from '../../data/routeSteps.js';
|
||||
import {
|
||||
t,
|
||||
@@ -68,10 +70,12 @@ export function presentRoutingFailure(error) {
|
||||
|
||||
/** Route colour — the annotation palette's cyan, so voice routes and Directions match. */
|
||||
export const DIRECTIONS_ROUTE_COLOR = '#39d0ff';
|
||||
const MARKER_A_COLOR = Cesium.Color.fromCssColorString('#5dff9f');
|
||||
const MARKER_B_COLOR = Cesium.Color.fromCssColorString('#ff6b6b');
|
||||
const STEP_COLOR = Cesium.Color.WHITE.withAlpha(0.95);
|
||||
const STEP_OUTLINE = Cesium.Color.fromCssColorString(DIRECTIONS_ROUTE_COLOR);
|
||||
// Engine-neutral colours (src/layers/shared/color.js): a Navara page has no
|
||||
// Cesium SDK.
|
||||
const MARKER_A_COLOR = () => rgbaFromCss('#5dff9f');
|
||||
const MARKER_B_COLOR = () => rgbaFromCss('#ff6b6b');
|
||||
const STEP_COLOR = () => WHITE.withAlpha(0.95);
|
||||
const STEP_OUTLINE = () => rgbaFromCss(DIRECTIONS_ROUTE_COLOR);
|
||||
const STEP_PIXEL_SIZE = 8;
|
||||
const STEP_SELECTED_PIXEL_SIZE = 13;
|
||||
/** Route request timeout (ms) — the proxy itself gives OSRM 12 s. */
|
||||
@@ -978,11 +982,11 @@ export function createDirectionsLayer({
|
||||
? _engine.picker.pickGlobe(screenPosition)
|
||||
: services.scenePick.pickGroundPosition(_viewer, screenPosition);
|
||||
if (!cartesian) return null;
|
||||
const carto = Cesium.Cartographic.fromCartesian(cartesian);
|
||||
const carto = geo.cartographic.fromCartesian(cartesian);
|
||||
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),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1026,10 +1030,10 @@ export function createDirectionsLayer({
|
||||
if (!_viewer && !_native) return;
|
||||
if (letter === 'a') {
|
||||
removeEntity(_markerA);
|
||||
_markerA = markerEntity('A', point, MARKER_A_COLOR);
|
||||
_markerA = markerEntity('A', point, MARKER_A_COLOR());
|
||||
} else {
|
||||
removeEntity(_markerB);
|
||||
_markerB = markerEntity('B', point, MARKER_B_COLOR);
|
||||
_markerB = markerEntity('B', point, MARKER_B_COLOR());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1136,9 +1140,9 @@ export function createDirectionsLayer({
|
||||
_stepPoints.add({
|
||||
id: `directions:step:${index}`,
|
||||
position: Cesium.Cartesian3.fromDegrees(step.lon, step.lat, 0),
|
||||
color: STEP_COLOR,
|
||||
color: STEP_COLOR(),
|
||||
pixelSize: STEP_PIXEL_SIZE,
|
||||
outlineColor: STEP_OUTLINE,
|
||||
outlineColor: STEP_OUTLINE(),
|
||||
outlineWidth: 2,
|
||||
show: false,
|
||||
// The shared ground floor is a coarse cell, and on the photoreal stack
|
||||
|
||||
@@ -4,7 +4,8 @@ import {
|
||||
horizonOccluder,
|
||||
} from '../../../data/render/cesiumProjection.js';
|
||||
|
||||
export const FIRMS_LEFT_CLICK = Cesium.ScreenSpaceEventType.LEFT_CLICK;
|
||||
// Cesium ScreenSpaceEventType.LEFT_CLICK; available before the SDK loads.
|
||||
export const FIRMS_LEFT_CLICK = 2;
|
||||
export const projectFirmsWindow = worldToWindowCoordinates;
|
||||
export const firmsHorizonOccluder = horizonOccluder;
|
||||
|
||||
|
||||
@@ -1,17 +1,6 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { GNSS_LEVEL_COLORS } from '../records.js';
|
||||
|
||||
/**
|
||||
* GroundPrimitive allowPicking:false suppresses ids but still submits stencil
|
||||
* commands in Cesium's pick pass, erasing picks of overlapping ground geometry.
|
||||
* This fill participates only in rendering, so sibling polygons remain pickable.
|
||||
*/
|
||||
class GnssGroundFill extends Cesium.GroundPrimitive {
|
||||
update(frameState) {
|
||||
if (!frameState.passes.pick) super.update(frameState);
|
||||
}
|
||||
}
|
||||
|
||||
/** Degrees at the centre of the current view, or null before the camera settles. */
|
||||
export function defaultGnssViewAnchor(viewer) {
|
||||
const canvas = viewer?.scene?.canvas;
|
||||
@@ -44,6 +33,14 @@ export function createGnssCesiumRenderer({
|
||||
viewer,
|
||||
viewAnchor = defaultGnssViewAnchor,
|
||||
}) {
|
||||
// GroundPrimitive allowPicking:false still submits stencil commands in
|
||||
// the pick pass. Keep this fill from erasing overlapping geometry's picks.
|
||||
class GnssGroundFill extends Cesium.GroundPrimitive {
|
||||
update(frameState) {
|
||||
if (!frameState.passes.pick) super.update(frameState);
|
||||
}
|
||||
}
|
||||
|
||||
const primitives = new Cesium.PrimitiveCollection();
|
||||
primitives.id = 'gnss-integrity';
|
||||
primitives.show = false;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import * as geo from '../../geo/index.js';
|
||||
import { whenCesiumSdk } from '../../app/loadCesium.js';
|
||||
import { createState } from './state.js';
|
||||
import { createMarker } from './marker.js';
|
||||
import { createCameraFraming } from './cameraFraming.js';
|
||||
@@ -549,15 +550,19 @@ export function createStreetLevelLayer({
|
||||
mapStack = null;
|
||||
state.viewer = null;
|
||||
},
|
||||
enable(viewer) {
|
||||
state.enabled = true;
|
||||
if (viewer) state.viewer = viewer;
|
||||
parts.marker.setVisible(true);
|
||||
parts.selection.install(state.viewer);
|
||||
for (const entry of activeEntries()) activate(entry);
|
||||
watchCamera(state.viewer);
|
||||
remeasureGround();
|
||||
notify();
|
||||
enable(viewer, { signal } = {}) {
|
||||
// The marker, cones, coverage and ground picks use Cesium's math and
|
||||
// primitives on either globe: a Navara page loads the Cesium SDK first.
|
||||
return whenCesiumSdk(() => {
|
||||
state.enabled = true;
|
||||
if (viewer) state.viewer = viewer;
|
||||
parts.marker.setVisible(true);
|
||||
parts.selection.install(state.viewer);
|
||||
for (const entry of activeEntries()) activate(entry);
|
||||
watchCamera(state.viewer);
|
||||
remeasureGround();
|
||||
notify();
|
||||
}, signal);
|
||||
},
|
||||
|
||||
disable() {
|
||||
|
||||
@@ -227,11 +227,7 @@ export function viewFocus(
|
||||
* (NYC −22 m), and an occluder at 0 m would hide the cones around it.
|
||||
*/
|
||||
const HORIZON_CULL_DEPTH_M = 1000;
|
||||
const HORIZON_CULL_ELLIPSOID = new Cesium.Ellipsoid(
|
||||
Cesium.Ellipsoid.WGS84.radii.x - HORIZON_CULL_DEPTH_M,
|
||||
Cesium.Ellipsoid.WGS84.radii.y - HORIZON_CULL_DEPTH_M,
|
||||
Cesium.Ellipsoid.WGS84.radii.z - HORIZON_CULL_DEPTH_M,
|
||||
);
|
||||
let HORIZON_CULL_ELLIPSOID;
|
||||
|
||||
/**
|
||||
* Hide billboards and points behind the horizon: they skip the depth test, so
|
||||
@@ -240,12 +236,18 @@ const HORIZON_CULL_ELLIPSOID = new Cesium.Ellipsoid(
|
||||
* @param {{getViewer: () => object|null, items: () => Iterable<{position: object, show: boolean}>, onChange?: () => void}} options
|
||||
*/
|
||||
export function createHorizonCull({ getViewer, items, onChange }) {
|
||||
const occluder = new Cesium.EllipsoidalOccluder(HORIZON_CULL_ELLIPSOID);
|
||||
let occluder;
|
||||
let from = null;
|
||||
let stopListening = null;
|
||||
|
||||
/** Show what is in front of the horizon, hide the rest; the count seen. */
|
||||
function cull(list, position) {
|
||||
HORIZON_CULL_ELLIPSOID ??= new Cesium.Ellipsoid(
|
||||
Cesium.Ellipsoid.WGS84.radii.x - HORIZON_CULL_DEPTH_M,
|
||||
Cesium.Ellipsoid.WGS84.radii.y - HORIZON_CULL_DEPTH_M,
|
||||
Cesium.Ellipsoid.WGS84.radii.z - HORIZON_CULL_DEPTH_M,
|
||||
);
|
||||
occluder ??= new Cesium.EllipsoidalOccluder(HORIZON_CULL_ELLIPSOID);
|
||||
occluder.cameraPosition = position;
|
||||
let seen = 0;
|
||||
let changed = false;
|
||||
|
||||
@@ -86,11 +86,15 @@ export const CABLE_GLOBE_STACK_IDS = Object.freeze(
|
||||
export const MARKER_COLLECTION_EXPECTATIONS = Object.freeze([
|
||||
Object.freeze({
|
||||
key: '_billboardCollection',
|
||||
type: Cesium.BillboardCollection,
|
||||
get type() {
|
||||
return Cesium.BillboardCollection;
|
||||
},
|
||||
}),
|
||||
Object.freeze({
|
||||
key: '_pointCollection',
|
||||
type: Cesium.PointPrimitiveCollection,
|
||||
get type() {
|
||||
return Cesium.PointPrimitiveCollection;
|
||||
},
|
||||
}),
|
||||
]);
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ export function createReticleFootprint() {
|
||||
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();
|
||||
let ray;
|
||||
return (viewer, altitude, engine) => {
|
||||
const camera = engine?.camera ?? viewer?.camera;
|
||||
if (!camera?.getPickRay && !camera?.pickRay) return null;
|
||||
@@ -91,7 +91,9 @@ export function createReticleFootprint() {
|
||||
p = pixels[i];
|
||||
p.x = left + (side * col) / 4;
|
||||
p.y = top + (side * row) / 4;
|
||||
const hit = camera.pickEllipsoid(p, Cesium.Ellipsoid.WGS84, hits[i]);
|
||||
const hit = engine
|
||||
? camera.pickEllipsoid(p)
|
||||
: camera.pickEllipsoid(p, Cesium.Ellipsoid.WGS84, hits[i]);
|
||||
let dx, dy;
|
||||
if (hit) {
|
||||
geo.cartographic.fromCartesian(hit, geo.ellipsoid.WGS84, carto);
|
||||
@@ -102,7 +104,7 @@ export function createReticleFootprint() {
|
||||
} else {
|
||||
const picked = engine
|
||||
? camera.pickRay(p)
|
||||
: camera.getPickRay(p, ray) || ray;
|
||||
: camera.getPickRay(p, (ray ??= new Cesium.Ray())) || ray;
|
||||
if (!picked) continue;
|
||||
const d = picked.direction;
|
||||
dx =
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
claimCameraSensitivity,
|
||||
releaseCameraSensitivity,
|
||||
} from '../../data/cameraSensitivity.js';
|
||||
import { whenCesiumSdk } from '../../app/loadCesium.js';
|
||||
|
||||
export function createLifecycle({
|
||||
state: layerState,
|
||||
@@ -245,36 +246,40 @@ export function createLifecycle({
|
||||
*
|
||||
* @param {Cesium.Viewer} viewer - The Cesium viewer instance.
|
||||
*/
|
||||
enable(viewer) {
|
||||
if (layerState._enabled) return;
|
||||
if (viewer) layerState._viewer = viewer;
|
||||
layerState._enabled = true;
|
||||
if (layerState._roadMode !== 'tomtom') source.prefetch?.();
|
||||
bindScene();
|
||||
// Enabling is explicit intent, not a camera gesture that needs settling.
|
||||
parts.viewport.onCameraChanged({ immediate: true });
|
||||
enable(viewer, { signal } = {}) {
|
||||
// The simulation's math is Cesium's on either globe: a Navara page
|
||||
// loads the Cesium SDK first.
|
||||
return whenCesiumSdk(() => {
|
||||
if (layerState._enabled) return;
|
||||
if (viewer) layerState._viewer = viewer;
|
||||
layerState._enabled = true;
|
||||
if (layerState._roadMode !== 'tomtom') source.prefetch?.();
|
||||
bindScene();
|
||||
// Enabling is explicit intent, not a camera gesture that needs settling.
|
||||
parts.viewport.onCameraChanged({ immediate: true });
|
||||
|
||||
// Boot-order guard (field-test round 1: layer sat empty until the user
|
||||
// moved): when the persisted layer state re-enables traffic during the
|
||||
// intro flyTo, the initial check bails at high altitude — and a camera
|
||||
// that then parks never re-fires camera.changed. Retry cheaply until the
|
||||
// first load commits, then self-clear. Also acts as a safety kick if a
|
||||
// failed first fetch left the viewport unloaded while parked.
|
||||
clearInterval(layerState._enableKickTimer);
|
||||
layerState._enableKickTimer = setInterval(() => {
|
||||
if (
|
||||
!layerState._enabled ||
|
||||
layerState._lastUpdate ||
|
||||
layerState._roadRetryStopped ||
|
||||
layerState._retryAttempts >= 3
|
||||
) {
|
||||
clearInterval(layerState._enableKickTimer);
|
||||
layerState._enableKickTimer = null;
|
||||
return;
|
||||
}
|
||||
if (!layerState._fetching && !layerState._retryTimer)
|
||||
parts.viewport.onCameraChanged();
|
||||
}, 1500);
|
||||
// Boot-order guard (field-test round 1: layer sat empty until the user
|
||||
// moved): when the persisted layer state re-enables traffic during the
|
||||
// intro flyTo, the initial check bails at high altitude — and a camera
|
||||
// that then parks never re-fires camera.changed. Retry cheaply until the
|
||||
// first load commits, then self-clear. Also acts as a safety kick if a
|
||||
// failed first fetch left the viewport unloaded while parked.
|
||||
clearInterval(layerState._enableKickTimer);
|
||||
layerState._enableKickTimer = setInterval(() => {
|
||||
if (
|
||||
!layerState._enabled ||
|
||||
layerState._lastUpdate ||
|
||||
layerState._roadRetryStopped ||
|
||||
layerState._retryAttempts >= 3
|
||||
) {
|
||||
clearInterval(layerState._enableKickTimer);
|
||||
layerState._enableKickTimer = null;
|
||||
return;
|
||||
}
|
||||
if (!layerState._fetching && !layerState._retryTimer)
|
||||
parts.viewport.onCameraChanged();
|
||||
}, 1500);
|
||||
}, signal);
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { rgbaFromCss } from '../shared/color.js';
|
||||
|
||||
/**
|
||||
* @file Street Traffic selects TomTom, OpenMapTiles or Hybrid motor roads,
|
||||
@@ -112,9 +112,9 @@ export const SIZE_BY_TYPE = {
|
||||
*/
|
||||
|
||||
export const FLOW_BUCKET_COLORS = {
|
||||
free: Cesium.Color.fromCssColorString('#2ecc71').withAlpha(0.9),
|
||||
slow: Cesium.Color.fromCssColorString('#f0b23e').withAlpha(0.9),
|
||||
jam: Cesium.Color.fromCssColorString('#e05252').withAlpha(0.9),
|
||||
free: rgbaFromCss('#2ecc71').withAlpha(0.9),
|
||||
slow: rgbaFromCss('#f0b23e').withAlpha(0.9),
|
||||
jam: rgbaFromCss('#e05252').withAlpha(0.9),
|
||||
};
|
||||
|
||||
// ─── Jam-viz prototype (live mode only — see 2026-07-21 design doc) ────────
|
||||
@@ -140,12 +140,11 @@ export const HEAT_JAM_PULSE_ALPHA = 0.2;
|
||||
|
||||
/** @const {Cesium.Color} Jam corridor color (bucket red, alpha pulsed live). */
|
||||
|
||||
export const HEAT_JAM_COLOR = Cesium.Color.fromCssColorString('#e05252');
|
||||
export const HEAT_JAM_COLOR = rgbaFromCss('#e05252');
|
||||
|
||||
/** @const {Cesium.Color} Slow corridor color (bucket amber, faint + static). */
|
||||
|
||||
export const HEAT_SLOW_COLOR =
|
||||
Cesium.Color.fromCssColorString('#f0b23e').withAlpha(0.2);
|
||||
export const HEAT_SLOW_COLOR = rgbaFromCss('#f0b23e').withAlpha(0.2);
|
||||
|
||||
/** @const {number} Far-distance scale floor for jam dots (shipped: 0.3). */
|
||||
|
||||
|
||||
@@ -12,10 +12,10 @@ export function roadIdentity(road) {
|
||||
/** Retain one road and its dot population across tile and surface publications. */
|
||||
export function createRetention({ state, parts }) {
|
||||
const records = new Map();
|
||||
const heightStep = new Cesium.Cartesian3();
|
||||
const screenFrom = new Cesium.Cartesian2();
|
||||
const screenTo = new Cesium.Cartesian2();
|
||||
const eye = new Cesium.Cartesian3();
|
||||
const heightStep = { x: 0, y: 0, z: 0 };
|
||||
const screenFrom = { x: 0, y: 0 };
|
||||
const screenTo = { x: 0, y: 0 };
|
||||
const eye = { x: 0, y: 0, z: 0 };
|
||||
function projectSafely(scene, point, screen) {
|
||||
if (scene.project) return Boolean(scene.project(point, screen));
|
||||
if (scene.camera.viewMatrix) {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { normalizeRoadMode } from './roadModes.js';
|
||||
import * as Cesium from 'cesium';
|
||||
import { FLOW_BUCKET_COLORS } from './policy.js';
|
||||
|
||||
export function createState({ services }) {
|
||||
@@ -294,7 +293,7 @@ export function createState({ services }) {
|
||||
|
||||
/** Reusable scratch Cartesian3 to avoid per-frame allocation / GC pressure */
|
||||
|
||||
layerState._scratchLerp = new Cesium.Cartesian3();
|
||||
layerState._scratchLerp = { x: 0, y: 0, z: 0 };
|
||||
|
||||
// ─── Animation ─────────────────────────────────────────────
|
||||
|
||||
|
||||
+24
-16
@@ -1,4 +1,5 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import * as geo from '../../geo/index.js';
|
||||
import { createWeatherRendering } from './rendering.js';
|
||||
import { imageryHostStatus } from './imageryHost.js';
|
||||
import { weatherDisplay, insideExtent } from './display.js';
|
||||
@@ -57,7 +58,7 @@ export function createWeatherLayer({
|
||||
feed,
|
||||
clock,
|
||||
id = 'weather-radar',
|
||||
cesium = Cesium,
|
||||
cesium = null,
|
||||
createRendering = createWeatherRendering,
|
||||
createNativeRendering = null,
|
||||
documentRef = globalThis.document,
|
||||
@@ -311,11 +312,13 @@ export function createWeatherLayer({
|
||||
attachRenderer(nextViewer, { engine = null } = {}) {
|
||||
viewer = nextViewer;
|
||||
sceneEngine = engine;
|
||||
const options = { viewer, cesium, getHost, onChange: notify };
|
||||
const options = { viewer, getHost, onChange: notify };
|
||||
// The SDK is read here, on Cesium only: the production build's Cesium
|
||||
// global loads with the first Cesium globe.
|
||||
rendering =
|
||||
engine?.kind === 'navara'
|
||||
? createNativeRendering(engine, options)
|
||||
: createRendering(options);
|
||||
: createRendering({ ...options, cesium: cesium ?? Cesium });
|
||||
checkHost(false);
|
||||
eventTarget?.addEventListener?.(
|
||||
'gev:map-stack-changed',
|
||||
@@ -530,12 +533,20 @@ export function createWeatherLayer({
|
||||
: manifest.bounds);
|
||||
runNavigation(() =>
|
||||
(sceneEngine?.camera ?? viewer.camera).flyTo({
|
||||
destination: cesium.Rectangle.fromDegrees(
|
||||
b.west,
|
||||
b.south,
|
||||
b.east,
|
||||
b.north,
|
||||
),
|
||||
// The engine camera takes a plain rectangle in radians.
|
||||
destination: sceneEngine
|
||||
? {
|
||||
west: geo.math.toRadians(b.west),
|
||||
south: geo.math.toRadians(b.south),
|
||||
east: geo.math.toRadians(b.east),
|
||||
north: geo.math.toRadians(b.north),
|
||||
}
|
||||
: (cesium ?? Cesium).Rectangle.fromDegrees(
|
||||
b.west,
|
||||
b.south,
|
||||
b.east,
|
||||
b.north,
|
||||
),
|
||||
duration: motion?.matches ? 0 : 1.4,
|
||||
}),
|
||||
);
|
||||
@@ -634,20 +645,17 @@ export function createWeatherLayer({
|
||||
const point =
|
||||
canvas &&
|
||||
(sceneEngine?.camera ?? viewer.camera).pickEllipsoid?.(
|
||||
new cesium.Cartesian2(
|
||||
geo.cartesian2.create(
|
||||
canvas.clientWidth / 2,
|
||||
canvas.clientHeight / 2,
|
||||
),
|
||||
viewer?.scene?.globe?.ellipsoid,
|
||||
);
|
||||
const camera = point
|
||||
? cesium.Cartographic.fromCartesian(
|
||||
point,
|
||||
viewer?.scene?.globe?.ellipsoid,
|
||||
)
|
||||
? geo.cartographic.fromCartesian(point, viewer?.scene?.globe?.ellipsoid)
|
||||
: null;
|
||||
const lon = camera ? cesium.Math.toDegrees(camera.longitude) : 0;
|
||||
const lat = camera ? cesium.Math.toDegrees(camera.latitude) : 0;
|
||||
const lon = camera ? geo.math.toDegrees(camera.longitude) : 0;
|
||||
const lat = camera ? geo.math.toDegrees(camera.latitude) : 0;
|
||||
const outside =
|
||||
b &&
|
||||
camera &&
|
||||
|
||||
@@ -7,22 +7,9 @@ import { inspectWindAtCenter } from './inspection.js';
|
||||
import { windReadingResult } from './presentation.js';
|
||||
import { sampleWind, windColor, windSpeed } from './model.js';
|
||||
import { windStats } from './index.js';
|
||||
import * as geo from '../../geo/index.js';
|
||||
|
||||
const cesium = {
|
||||
Cartesian2: class {
|
||||
constructor(x, y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
},
|
||||
Ellipsoid: { WGS84: {} },
|
||||
Cartographic: { fromCartesian: (p) => p },
|
||||
Math: { toDegrees: (x) => (x * 180) / Math.PI },
|
||||
};
|
||||
const at = (lonDeg, latDeg) => ({
|
||||
longitude: (lonDeg * Math.PI) / 180,
|
||||
latitude: (latDeg * Math.PI) / 180,
|
||||
});
|
||||
const at = (lonDeg, latDeg) => geo.cartesian3.fromDegrees(lonDeg, latDeg);
|
||||
const grid = { nx: 4, ny: 3, lo1: 0, la1: 90, dx: 90, dy: 90 };
|
||||
const field = (u, v) => ({
|
||||
grid,
|
||||
@@ -44,11 +31,10 @@ const viaViewer = (snapshot, point) =>
|
||||
camera: { pickEllipsoid: () => point },
|
||||
scene: { canvas: { clientWidth: 800, clientHeight: 600 } },
|
||||
},
|
||||
cesium,
|
||||
options,
|
||||
);
|
||||
const viaPosition = (snapshot, point) =>
|
||||
inspectWindAtCenter(snapshot, null, cesium, { ...options, position: point });
|
||||
inspectWindAtCenter(snapshot, null, { ...options, position: point });
|
||||
const windLine = (reading) =>
|
||||
windReadingResult(reading).lines.find(({ id }) => id === 'wind').text;
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ export function windStats(manifest) {
|
||||
export function createWindLayer({
|
||||
feed,
|
||||
clock,
|
||||
cesium = Cesium,
|
||||
cesium = null,
|
||||
container,
|
||||
createRendering = createWindRendering,
|
||||
createNativeRendering,
|
||||
@@ -90,7 +90,7 @@ export function createWindLayer({
|
||||
y: canvas.clientHeight / 2,
|
||||
});
|
||||
}
|
||||
reading = inspectWindAtCenter(manifest, viewer, cesium, {
|
||||
reading = inspectWindAtCenter(manifest, viewer, {
|
||||
position,
|
||||
units,
|
||||
overlay,
|
||||
@@ -129,7 +129,9 @@ export function createWindLayer({
|
||||
engine?.kind === 'navara'
|
||||
? createNativeRendering(engine)
|
||||
: createRendering({
|
||||
cesium,
|
||||
// Read on Cesium only: the production build's Cesium global
|
||||
// loads with the first Cesium globe.
|
||||
cesium: cesium ?? Cesium,
|
||||
container: container ?? nextViewer.container,
|
||||
getViewer: () => viewer,
|
||||
getHost: () =>
|
||||
@@ -147,7 +149,7 @@ export function createWindLayer({
|
||||
inspectionMarker = createWindInspectionMarker({
|
||||
container: target,
|
||||
viewer,
|
||||
cesium,
|
||||
cesium: engine ? null : (cesium ?? Cesium),
|
||||
engine,
|
||||
});
|
||||
if (enabled && manifest && !manifest.unavailable) {
|
||||
|
||||
@@ -3,6 +3,7 @@ import assert from 'node:assert/strict';
|
||||
import { createWindLayer, formatWindValidTime, windStats } from './index.js';
|
||||
import { useWindInspectionStore } from '../../ui/stores/windInspection.js';
|
||||
import { applicationPinia } from '../../ui/vueRuntime.js';
|
||||
import * as geo from '../../geo/index.js';
|
||||
|
||||
const snapshot = (model) => ({
|
||||
model,
|
||||
@@ -314,7 +315,7 @@ test('sample stays fixed across model, field and unit changes; dismissal and dis
|
||||
};
|
||||
const viewer = {
|
||||
container,
|
||||
camera: { positionWC: {}, pickEllipsoid: () => { samples++; return { longitude: 0, latitude: 0 }; } },
|
||||
camera: { positionWC: {}, pickEllipsoid: () => { samples++; return geo.cartesian3.fromDegrees(0, 0); } },
|
||||
scene: {
|
||||
mode: 3,
|
||||
canvas: { clientWidth: 800, clientHeight: 600, getBoundingClientRect: () => ({ left: 0, top: 0 }) },
|
||||
@@ -352,7 +353,7 @@ test('sample stays fixed across model, field and unit changes; dismissal and dis
|
||||
assert.deepEqual(layer.getRowControls().summary.settings.map(({ label }) => label), ['MODEL', 'FIELD', 'UNITS', 'MOTION']);
|
||||
assert.ok(marker());
|
||||
assert.equal(typeof listener, 'function');
|
||||
viewer.camera.pickEllipsoid = () => { samples++; return { longitude: 70, latitude: 20 }; };
|
||||
viewer.camera.pickEllipsoid = () => { samples++; return geo.cartesian3.fromDegrees(70, 20); };
|
||||
layer.setParams({ overlay: 'speed' });
|
||||
assert.equal(layer.getRowControls().summary.reading.coordinates, captured.coordinates);
|
||||
layer.setParams({ model: 'ifs' });
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { sampleWind, windSpeed } from './model.js';
|
||||
import { sampleScalar } from './fields.js';
|
||||
import * as geo from '../../geo/index.js';
|
||||
|
||||
// The reading stays English: AI tools read it too. Text is marked for i18n
|
||||
// extraction and translated where the WEATHER card shows it (presentation.js).
|
||||
@@ -45,17 +46,17 @@ export function formatWindSpeed(speed, units = 'km/h') {
|
||||
export function inspectWindAtCenter(
|
||||
snapshot,
|
||||
viewer,
|
||||
cesium,
|
||||
{ units, overlay, model, validTime, status, position } = {},
|
||||
) {
|
||||
const scene = viewer?.scene;
|
||||
const canvas = scene?.canvas;
|
||||
const ellipsoid = scene?.globe?.ellipsoid || cesium.Ellipsoid?.WGS84;
|
||||
// The globe's own ellipsoid, else WGS84 (geo's default).
|
||||
const ellipsoid = scene?.globe?.ellipsoid;
|
||||
const point =
|
||||
position ||
|
||||
(canvas &&
|
||||
viewer.camera?.pickEllipsoid?.(
|
||||
new cesium.Cartesian2(canvas.clientWidth / 2, canvas.clientHeight / 2),
|
||||
geo.cartesian2.create(canvas.clientWidth / 2, canvas.clientHeight / 2),
|
||||
ellipsoid,
|
||||
));
|
||||
const noReading = () => ({
|
||||
@@ -69,9 +70,9 @@ export function inspectWindAtCenter(
|
||||
),
|
||||
});
|
||||
if (!point || !snapshot?.u || !snapshot?.v) return noReading();
|
||||
const location = cesium.Cartographic.fromCartesian(point, ellipsoid);
|
||||
const lon = cesium.Math.toDegrees(location.longitude);
|
||||
const lat = cesium.Math.toDegrees(location.latitude);
|
||||
const location = geo.cartographic.fromCartesian(point, ellipsoid);
|
||||
const lon = geo.math.toDegrees(location.longitude);
|
||||
const lat = geo.math.toDegrees(location.latitude);
|
||||
const vector = sampleWind(
|
||||
{ ...snapshot.grid, u: snapshot.u, v: snapshot.v },
|
||||
lon,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import * as geo from '../../geo/index.js';
|
||||
import {
|
||||
windFrom,
|
||||
formatWindSpeed,
|
||||
@@ -27,21 +28,10 @@ test('center inspection uses a fixed forecast reading without double-converting
|
||||
},
|
||||
};
|
||||
const viewer = {
|
||||
camera: { pickEllipsoid: () => ({ longitude: 0, latitude: 0 }) },
|
||||
camera: { pickEllipsoid: () => geo.cartesian3.fromDegrees(0, 0) },
|
||||
scene: { canvas: { clientWidth: 800, clientHeight: 600 } },
|
||||
};
|
||||
const cesium = {
|
||||
Cartesian2: class {
|
||||
constructor(x, y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
},
|
||||
Ellipsoid: { WGS84: {} },
|
||||
Cartographic: { fromCartesian: (p) => p },
|
||||
Math: { toDegrees: (x) => (x * 180) / Math.PI },
|
||||
};
|
||||
const result = inspectWindAtCenter(snapshot, viewer, cesium, {
|
||||
const result = inspectWindAtCenter(snapshot, viewer, {
|
||||
overlay: 'temperature',
|
||||
units: 'km/h',
|
||||
model: 'GFS',
|
||||
@@ -54,7 +44,7 @@ test('center inspection uses a fixed forecast reading without double-converting
|
||||
assert.equal(result.coordinates, '0.00°N · 0.00°E');
|
||||
viewer.camera.pickEllipsoid = () => null;
|
||||
assert.equal(
|
||||
inspectWindAtCenter(snapshot, viewer, cesium).coordinates,
|
||||
inspectWindAtCenter(snapshot, viewer).coordinates,
|
||||
'No surface reading',
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user