Load the Cesium SDK and its widget styles only when a Cesium globe first starts

This commit is contained in:
German Khokhlov committed 2026-11-03 22:56:24 +04:00
1 parent 9f8381ff71
commit ae13a56f6d
27 files changed
+269 -124

No files matched your search

+8 -8
View File
@@ -68,10 +68,10 @@ 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);
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);
const STEP_PIXEL_SIZE = 8;
const STEP_SELECTED_PIXEL_SIZE = 13;
/** Route request timeout (ms) — the proxy itself gives OSRM 12 s. */
@@ -1020,10 +1020,10 @@ export function createDirectionsLayer({ services, source, createNativeRenderer }
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());
}
}
@@ -1127,9 +1127,9 @@ export function createDirectionsLayer({ services, source, createNativeRenderer }
_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
+2 -1
View File
@@ -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;
+8 -11
View File
@@ -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;
+8 -6
View File
@@ -210,11 +210,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
@@ -223,12 +219,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;
+2 -2
View File
@@ -86,11 +86,11 @@ 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; },
}),
]);
+5 -3
View File
@@ -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);
@@ -100,7 +102,7 @@ export function createReticleFootprint() {
dlon -= 360 * Math.round(dlon / 360);
dx = dlon * 111.195 * Math.cos(nadir.latitude);
} else {
const picked = engine ? camera.pickRay(p) : camera.getPickRay(p, ray) || ray;
const picked = engine ? camera.pickRay(p) : camera.getPickRay(p, (ray ??= new Cesium.Ray())) || ray;
if (!picked) continue;
const d = picked.direction;
dx =
+6 -6
View File
@@ -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,12 @@ 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);
rgbaFromCss('#f0b23e').withAlpha(0.2);
/** @const {number} Far-distance scale floor for jam dots (shipped: 0.3). */
+4 -4
View File
@@ -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 -2
View File
@@ -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 ─────────────────────────────────────────────