World annotation renderer draws through the renderer's ports

Areas, buildings, routes, arrows, pins and labels are draw-port shapes,
lines and points, one set per mark, faded by upserting their colours.
Pins pulse their ring and size it by camera height; arrows drape.
Ground heights come from the heights service. The module leaves the
Cesium allow-list.
This commit is contained in:
Sameh Khamis committed 2026-11-09 10:34:53 -08:00
1 parent 6b4b04d082
commit d9e72dfc8b
10 files changed
+791 -630

No files matched your search

+26 -19
View File
@@ -9,6 +9,7 @@ import * as Cesium from 'cesium';
import { FEATURE_SOURCE_METHODS } from '../sources/featureSource.js';
import { createAnnotationResolver } from '../annotations/resolver.js';
import { bindFakeCesiumCamera } from '../testSupport/fakeCameraPort.mjs';
import { fakeDrawPort } from '../testSupport/fakeDrawPort.mjs';
import { createWorldAnnotationRenderer } from '../annotations/worldAnnotationRenderer.js';
const read = (path) => readFileSync(new URL(path, import.meta.url), 'utf8');
@@ -22,7 +23,7 @@ const DATA_MODULES = [
'./local_data/wof_neighborhoods/files.js',
];
/** Modules that use Cesium for outlines but must not draw text with it. */
/** Modules that draw outlines but must not draw text with Cesium. */
const CESIUM_MODULES = [
'../annotations/resolver.js',
'../annotations/worldAnnotationRenderer.js',
@@ -110,22 +111,22 @@ test('drawing bundled place and neighborhood outlines creates no Cesium label',
featureSource,
});
const primitives = [];
const dataSources = [];
// The resolver reads the camera through the renderer's camera port.
const viewer = bindFakeCesiumCamera({
camera: {
positionCartographic: Cesium.Cartographic.fromDegrees(
-97.7431,
30.2672,
3000,
),
const draw = fakeDrawPort();
// The resolver reads the camera through the renderer's camera port; the
// world renderer draws through its draw port.
const viewer = bindFakeCesiumCamera(
{
camera: {
positionCartographic: Cesium.Cartographic.fromDegrees(
-97.7431,
30.2672,
3000,
),
},
scene: { primitives: { add: (p) => primitives.push(p) } },
},
scene: { primitives: { add: (p) => primitives.push(p) } },
dataSources: {
add: (ds) => dataSources.push(ds),
remove() {},
},
});
{ draw },
);
const renderer = createWorldAnnotationRenderer(viewer);
for (const [target, lon, lat] of [
['Austin', -97.7431, 30.2672],
@@ -157,8 +158,14 @@ test('drawing bundled place and neighborhood outlines creates no Cesium label',
});
}
assert.equal(primitives.length, 0, 'no primitive collections');
const entities = dataSources.flatMap((ds) => ds.entities.values);
assert.ok(entities.length >= 2, 'the outlines were drawn');
for (const entity of entities) assert.equal(entity.label, undefined);
const live = [...draw.sets.values()].filter((record) => !record.disposed);
const items = live.flatMap((record) => [...record.items.values()]);
assert.ok(items.length >= 2, 'the outlines were drawn');
// Fills and lines only: no point, text or label is drawn for a name.
assert.deepEqual([...new Set(live.map((record) => record.kind))].sort(), [
'lines',
'shapes',
]);
for (const item of items) assert.equal(item.label, undefined);
renderer.destroy();
});
+4 -1
View File
@@ -14,6 +14,9 @@ import { createDirectionsSource } from '../layers/directions/source.js';
import { createLifecycle as createCctvLifecycle } from '../layers/cctv/lifecycle.js';
import * as input from './inputOwnership.js';
import { createOverpassAlprSource } from '../layers/alpr/source.js';
// The infrastructure layers take clicks through the input port, which their
// fake renderer leaves to the Cesium adapter's factories.
import '../render/cesium/camera.js';
const noop = () => {};
const overlayHost = { setEntries: noop, setVisible: noop, clearSource: noop };
@@ -64,7 +67,7 @@ test('Nepal locator introduces the shared OSM credit', async (t) => {
});
test('voice route geometry introduces the shared OSM credit', (t) => {
const v = viewer(t), renderer = createWorldAnnotationRenderer(v);
const v = viewer(t, { draw: fakeDrawPort() }), renderer = createWorldAnnotationRenderer(v);
renderer.add({ id: 'route', type: 'route', color: 'primary', anchor: { lat: 0, lon: 0 }, path: [{ lat: 0, lon: 0 }, { lat: 0.01, lon: 0.01 }] });
assertCredit(v); renderer.destroy();
assert.equal(v.credits.filter(c => c.showOnScreen).length, 0);