Draw Street Level, traffic and directions through one display each

- Street Level: coverage sequences are ground corridor sets of up to
  120, draped on terrain and tiles as Cesium's ground polylines were;
  the marker and view cones are sprite movers turned to their compass
  bearing on screen and culled 1 km under WGS84. The layer no longer
  loads the Cesium SDK on Navara.
- Traffic: vehicles are two point mover sets (an outline disc under each
  fill) scaled and faded with Cesium's NearFarScalar maths; congestion
  heat lines are ground corridor sets draped on tiles. Heights, depth,
  readiness and the surface key go through the engine, and Navara no
  longer loads the Cesium SDK for traffic.
- Directions: the route is one ground corridor set in the annotation
  route's dash pattern, maneuvers are point movers and the A/B markers a
  disc and a letter sprite; the in-layer Navara branch and the Cesium
  point collection go.

Known gaps against Cesium, to close in the contract: the traffic heat
lines lose their glow and pulse and the route its flowing dashes
(no animated ground fills yet), and dense Street Level coverage on
Navara is costly as ground corridors (about 80 to 190 ms a frame at
6,000 to 14,400 sequences) until corridors are binned set-wide.

Coupling: Navara renderer lines fall from 3349 to 2767, Cesium-importing
files from 51 to 32, `viewer` lines from 1591 to 1373, Cesium SDK loads
on Navara from 6 to 4.
This commit is contained in:
German Khokhlov committed 2026-11-07 08:03:25 +04:00
1 parent 2fbdca62be
commit 1559bd57f4
78 files changed
+4762 -3719

No files matched your search

+29 -58
View File
@@ -1,12 +1,16 @@
import * as Cesium from 'cesium';
import { imageConeGlyph } from './glyphs.js';
import { passesImageryFilter } from './filter.js';
import { createHorizonCull, metresBetween } from './view.js';
import { metresBetween } from './view.js';
import { CONE_SPRITE_ORDER } from './policy.js';
import { msg } from '../../i18n/index.js';
/** Cones closer than this to the previous kept one are dropped. */
const IMAGE_CONE_MIN_SPACING_M = 3;
const IMAGE_CONE_SIZE_PX = 26;
/** NearFarScalar [nearM, nearScale, farM, farScale]: cones shrink with distance. */
export const IMAGE_CONE_SCALE_BY_DISTANCE = Object.freeze([
200, 1.1, 6000, 0.35,
]);
/**
* @typedef {object} ConeImage One image of a sequence, as the cones draw it.
@@ -32,8 +36,8 @@ export function thinImages(images, spacingM = IMAGE_CONE_MIN_SPACING_M) {
}
/**
* Image cones for one selected sequence, any provider's, clamped to the
* ground. A cone's pick id is `pickPrefix` + the image id; 360° images draw
* Image cones for one selected sequence, any provider's, on the ground
* (sprites of the display, render/display.js). A cone's pick id is `pickPrefix` + the image id; 360° images draw
* as rings. Why a sequence could not load stays in `state.sequence.error`
* until it goes.
*
@@ -43,7 +47,7 @@ export function thinImages(images, spacingM = IMAGE_CONE_MIN_SPACING_M) {
* The sequence's images in capture order, thinned (see `thinImages`).
* @param {{coverage: string}} options.colors
* @param {string} options.pickPrefix Pick-id prefix of the cones.
* @param {string} options.spriteId Sprite-order id of the cone collection.
* @param {string} options.spriteId Id of the cone sprites.
* @param {string} options.renderKey Render-governor reason.
* @param {(sequenceId: string|null) => void} [options.onHighlight]
* Highlight the sequence's coverage line (null: none).
@@ -60,7 +64,7 @@ export function createSequenceCones({
onHighlight = () => {},
passes = passesImageryFilter,
}) {
const { render, sprites } = state.services;
const { render } = state.services;
function requestRender() {
render?.governorRequestRender?.(renderKey);
@@ -70,41 +74,22 @@ export function createSequenceCones({
state.context.notify();
}
/** Drawn cone billboards. */
let cones = [];
// The cones skip the depth test: hide the ones behind the globe.
const horizon = createHorizonCull({
getViewer: () => state.viewer,
items: () => cones,
onChange: requestRender,
});
function ensureCollections(viewer) {
if (state.sequence.collection) return;
if (viewer?.engine) {
state.sequence.collection = viewer.billboards(spriteId);
return;
}
state.sequence.collection = new Cesium.BillboardCollection({
scene: viewer.scene,
function ensureCollections(view) {
if (state.sequence.collection || !view?.sprites) return;
state.sequence.collection = view.sprites(spriteId, {
order: CONE_SPRITE_ORDER,
});
viewer.scene.primitives.add(state.sequence.collection);
sprites?.registerSpriteCollection?.(spriteId, state.sequence.collection);
}
function clearCones() {
state.sequence.collection?.removeAll();
state.sequence.images = [];
cones = [];
horizon.stop();
}
function renderCones(images) {
const collection = state.sequence.collection;
if (!collection) return;
collection.removeAll();
cones = [];
// One colour per source; 360° images keep the ring shape.
const cone = imageConeGlyph({ size: 32, color: colors.coverage });
const ring = imageConeGlyph({
@@ -116,24 +101,17 @@ export function createSequenceCones({
const filter = state.context.getFilter();
for (const image of images) {
if (!passes(image, filter)) continue;
const billboard = collection.add({
id: `${pickPrefix}${image.id}`,
position: Cesium.Cartesian3.fromDegrees(image.lon, image.lat),
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
collection.add({
pickId: `${pickPrefix}${image.id}`,
lon: image.lon,
lat: image.lat,
bearing: image.compassAngle,
image: image.isPano ? ring : cone,
imageId: image.isPano ? `${spriteId}:pano` : `${spriteId}:flat`,
width: IMAGE_CONE_SIZE_PX,
height: IMAGE_CONE_SIZE_PX,
rotation: -Cesium.Math.toRadians(image.compassAngle),
alignedAxis: Cesium.Cartesian3.UNIT_Z,
disableDepthTestDistance: Number.POSITIVE_INFINITY,
verticalOrigin: Cesium.VerticalOrigin.CENTER,
scaleByDistance: new Cesium.NearFarScalar(200, 1.1, 6000, 0.35),
imageKey: image.isPano ? 'pano' : 'flat',
sizePx: IMAGE_CONE_SIZE_PX,
scaleByDistance: IMAGE_CONE_SCALE_BY_DISTANCE,
});
cones.push(billboard);
}
if (state.viewer?.engine) collection.changed();
else horizon.update();
requestRender();
}
@@ -142,7 +120,7 @@ export function createSequenceCones({
* reloads a selected one (a provider that loads part of a sequence moved on).
*/
async function select(sequenceId, { force = false } = {}) {
if (!sequenceId || (!state.viewer && !state.context.waitingForView?.()))
if (!sequenceId || (!state.map && !state.context.waitingForView?.()))
return;
// Already on screen, or already on its way.
if (
@@ -208,24 +186,17 @@ export function createSequenceCones({
}
function setVisible(visible) {
if (state.sequence.collection) state.sequence.collection.show = visible;
state.sequence.collection?.show(visible);
requestRender();
}
function releaseCollection(viewer) {
horizon.stop();
cones = [];
const collection = state.sequence.collection;
if (collection) {
sprites?.unregisterSpriteCollection?.(spriteId, collection);
if (viewer?.engine) collection.destroy();
else viewer?.scene?.primitives?.remove(collection);
state.sequence.collection = null;
}
function releaseCollection() {
state.sequence.collection?.destroy();
state.sequence.collection = null;
}
function destroy(viewer) {
function destroy() {
state.sequence.abort?.abort();
releaseCollection(viewer);
releaseCollection();
state.sequence.images = [];
state.sequence.selectedId = null;
}