Draw directions through the draw port

The directions layer draws its endpoint markers, its flowing route and
its maneuver dots through draw-port sets, takes clicks from the draw hit
and ground picks from the click's ground position, and leaves the Cesium
allow-list. The route keeps the annotation's flowing dashes, draped on
terrain and tiles; the maneuver dots keep their place in the sprite
order through the steps set.
This commit is contained in:
Sameh Khamis committed 2026-11-07 05:42:26 -08:00
1 parent d18fae43c2
commit 9de93b8d31
8 files changed
+361 -180

No files matched your search

+5 -9
View File
@@ -4,20 +4,18 @@ import { createDirectionsSource } from '../layers/directions/source.js';
* @description Service bundle for the Directions layer.
*
* The layer itself lives in `src/layers/directions/`, which imports nothing
* but Cesium and the pure step formatter. This module is the one place that
* names the application's shared services — the render governor, sprite order,
* the pick registry, the world overlay, the annotation material, the camera
* verbs, the shared ground floor and the pointer arbiter — and it re-exports
* the layer's pure helpers for the tests and the share-link code.
* but the renderer's draw port, geodesy and the pure step formatter. This
* module is the one place that names the application's shared services —
* the render governor, sprite order, the pick registry, the world overlay,
* the camera verbs, the shared ground floor and the pointer arbiter — and it
* re-exports the layer's pure helpers for the tests and the share-link code.
*/
import * as credits from './dataCredits.js';
import * as render from '../renderGovernor.js';
import * as sprites from './spriteOrder.js';
import * as picking from './pickRegistry.js';
import * as scenePick from './scenePick.js';
import * as overlays from '../overlays/worldOverlay.js';
import * as annotations from '../annotations/worldAnnotationRenderer.js';
import * as camera from '../cameraVerbs.js';
import * as ground from './groundFloor.js';
import * as input from './inputOwnership.js';
@@ -29,9 +27,7 @@ const directionsServices = Object.freeze({
render,
sprites,
picking,
scenePick,
overlays,
annotations,
camera,
ground,
input,
+12 -19
View File
@@ -1,6 +1,7 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import * as Cesium from 'cesium';
import { bindFakeDraw } from '../testSupport/fakeDrawPort.mjs';
import {
DEFAULT_DIRECTIONS_MODE,
DIRECTIONS_MODES,
@@ -969,7 +970,6 @@ test('a placed endpoint draws its letter through the overlay, not as entity text
const published = [];
const cleared = [];
const visibility = [];
const entities = [];
const markerVisibility = () =>
visibility
.filter(([source]) => source === DIRECTIONS_MARKER_OVERLAY_SOURCE_ID)
@@ -983,23 +983,11 @@ test('a placed endpoint draws its letter through the overlay, not as entity text
resetPointerOwnership();
const viewer = {
isDestroyed: () => false,
entities: {
add: (spec) => (entities.push(spec), spec),
remove() {},
},
scene: {
requestRender() {},
primitives: {
add: (primitive) => primitive,
remove() {},
raiseToTop() {},
lowerToBottom() {},
contains: () => true,
length: 0,
},
},
scene: { requestRender() {} },
};
const { draw, unbind } = bindFakeDraw(viewer);
t.after(() => {
unbind();
directionsLayer.destroy(viewer);
directionsLayer._setOverlayHostForTest(null);
resetPointerOwnership();
@@ -1008,9 +996,13 @@ test('a placed endpoint draws its letter through the overlay, not as entity text
assert.equal(markerVisibility(), false, 'hidden until enabled');
directionsLayer.placeEndpoint('a', { lat: 37.7955, lon: -122.3937 });
assert.equal(entities.length, 1);
assert.equal(entities[0].label, undefined, 'no Cesium label on the marker');
assert.ok(entities[0].point, 'the marker keeps its point');
const markers = [...draw.sets.values()].find(
(set) => !set.disposed && set.spec.id.endsWith(':markers'),
);
assert.deepEqual([...markers.items.keys()], ['directions:marker:A']);
const marker = markers.items.get('directions:marker:A');
assert.equal(marker.label, undefined, 'no renderer label on the marker');
assert.equal(marker.height, 'clampGround', 'a dot on the ground');
const [source, entries] = published.at(-1);
assert.equal(source, DIRECTIONS_MARKER_OVERLAY_SOURCE_ID);
assert.deepEqual(
@@ -1027,6 +1019,7 @@ test('a placed endpoint draws its letter through the overlay, not as entity text
assert.ok(Math.abs(Cesium.Math.toDegrees(anchor.latitude) - 37.7955) < 1e-9);
directionsLayer.setParams({ clear: true });
assert.equal(markers.items.size, 0, 'CLEAR takes the markers');
assert.ok(cleared.includes(DIRECTIONS_MARKER_OVERLAY_SOURCE_ID));
cleared.length = 0;
directionsLayer.destroy(viewer);
+7 -5
View File
@@ -2,11 +2,12 @@ import test from 'node:test';
import assert from 'node:assert/strict';
import * as C from 'cesium';
import { showOsmCredit, hideOsmCredit } from './dataCredits.js';
import { bindFakeCesiumCredits } from '../testSupport/fakeCreditsPort.mjs';
import { bindFakeCesiumCredits, fakeCesiumCredits } from '../testSupport/fakeCreditsPort.mjs';
import { fakeDrawPort } from '../testSupport/fakeDrawPort.mjs';
import { bindRenderer } from '../render/rendererOf.js';
import { createInfrastructureLayers } from './infrastructure.js';
import { createBhoteKoshiLocatorLayer } from './bhoteKoshiLocator.js';
import { createWorldAnnotationRenderer } from '../annotations/worldAnnotationRenderer.js';
import * as annotations from '../annotations/worldAnnotationRenderer.js';
import { createDirectionsLayer } from '../layers/directions/index.js';
import { createDirectionsSource } from '../layers/directions/source.js';
import { createLifecycle as createCctvLifecycle } from '../layers/cctv/lifecycle.js';
@@ -15,7 +16,7 @@ import { createOverpassAlprSource } from '../layers/alpr/source.js';
const noop = () => {};
const overlayHost = { setEntries: noop, setVisible: noop, clearSource: noop };
function viewer(t) {
function viewer(t, ports = null) {
t.mock.timers.enable({ apis: ['setTimeout'] });
for (const name of ['HTMLCanvasElement', 'HTMLImageElement', 'ImageBitmap', 'OffscreenCanvas']) {
const original = globalThis[name];
@@ -32,6 +33,7 @@ function viewer(t) {
scene: { requestRender: noop, canvas: { addEventListener: noop, removeEventListener: noop }, preRender: new C.Event(),
primitives: { add: (p) => p, remove: noop }, screenSpaceCameraController: { enableInputs: true } },
};
if (ports) bindRenderer(v, { credits: fakeCesiumCredits(v), ...ports });
return bindFakeCesiumCredits(v);
}
function assertCredit(v) {
@@ -64,10 +66,10 @@ test('voice route geometry introduces the shared OSM credit', (t) => {
});
test('Directions introduces the shared OSM credit when the requested route draws', async (t) => {
const v = viewer(t);
const v = viewer(t, { draw: fakeDrawPort() });
t.mock.method(globalThis, 'fetch', async () => Response.json({ ok: true, geometry: [[0, 0], [0.01, 0.01]], steps: [] }));
const layer = createDirectionsLayer({ source: createDirectionsSource(), services: {
credits: { showOsmCredit, hideOsmCredit }, annotations, input, scenePick: {}, camera: {},
credits: { showOsmCredit, hideOsmCredit }, input, camera: {},
overlays: { setOverlayEntries: noop, setOverlaySourceVisible: noop, clearOverlaySource: noop },
render: { governorRequestRender: noop, holdContinuousRender: noop, releaseContinuousRender: noop },
sprites: { registerSpriteCollection: noop, unregisterSpriteCollection: noop, restoreSpriteOrder: noop },