Draw Street Level's coverage lines through the renderer's draw port

The coverage lines are draped line sets on the draw port now, not
ground polyline primitives of the layer's own. A tile draws in sets of
120 line parts, as its primitives were batched; each part is an item of
its own (its id made unique in the tile) that picks its sequence
(`meta.pick`). A filter change redraws the sets in place, so the old
lines show until the new ones are ready. The selected sequence is one
set over the coverage, redrawn in place as tiles land; the tiles hide
their own lines of it, a show change made in place, so it shows
whichever set is drawn over which. The wait for the terrain-height
table goes: the renderer builds draped lines when it is ready. A colour
the layer cannot read is handed to the renderer as given.

Clicks no longer read the renderer's pick. The click dispatcher's event
gains `windowHit(width, height)`, the wider pick read as the canonical
id, the draw-set hit and whether it is the map itself. Street Level
routes its own sets' hits by their pick, anything else (a provider's own
drawing) by its id, as before; the ground under a click comes from the
event, and the ground click is told whether the map was hit. The screen
centre is aimed through the query port, a pick that fails counting as a
miss. Street Level no longer reads the scenePick service.

The Cesium draw port no longer lets a show queued while a draped line
built override one applied once it was ready, before the swap: the
highlight hand-over now depends on that.

lineCoverage leaves the Cesium allow-list; with it every Street Level
file named in this work is off the list.

Differences the contract does not let us avoid:
- The lines draw among the scene's primitives, not its ground
  primitives: they now draw over other layers' clamped entities and
  ground primitives, and win picks against them.
- The highlight builds asynchronously: a newly selected line is not
  drawn for the frames that takes.
- Lines of other sequences in tiles that land after the highlight was
  first drawn cross over it.
This commit is contained in:
Sameh Khamis committed 2026-11-07 01:40:32 -08:00
1 parent 40ad27fb95
commit 7e07927660
19 files changed
+680 -285

No files matched your search

+33 -39
View File
@@ -198,12 +198,6 @@ export function fakeCesiumViewer({ view = false } = {}) {
flights,
scene: {
canvas,
primitives: { add: (p) => p, remove() {} },
groundPrimitives: { add: (p) => p, remove() {} },
// Enough of a scene for the position marker to clamp to the ground.
frameState: { mode: Cesium.SceneMode.SCENE3D },
updateHeight: () => () => {},
getHeight: () => undefined,
},
camera,
creditDisplay: {
@@ -286,7 +280,9 @@ export function rayCamera({
* through what its `pickEllipsoid` hits), heights from its scene's
* `sampleHeight` (3D tiles: only while its globe is hidden) and its
* globe's `getHeight` (terrain), and pre-render from its scene's
* `preRender`; drawing goes to `draw` (a fake draw port by default), and
* `preRender`; positions under a screen point from its scene's
* `pickPosition` (when `pickPositionSupported`) and its camera's
* `pickEllipsoid`; drawing goes to `draw` (a fake draw port by default), and
* with `camera` the camera is `liveCamera`'s. For `bindFakeCesiumCamera`'s
* `ports`, or `bindRenderer`.
* @param {object} viewer
@@ -319,6 +315,14 @@ export function streetPorts(
);
return { origin, direction };
},
pickPosition(x, y) {
const scene = viewer.scene ?? {};
if (!scene.pickPositionSupported) return null;
return scene.pickPosition?.({ x, y }) ?? null;
},
pickEllipsoid(x, y) {
return viewer.camera?.pickEllipsoid?.({ x, y }) ?? null;
},
sampleHeightNow(point, { against = 'surface' } = {}) {
const scene = viewer.scene ?? {};
if (against === 'terrain')
@@ -394,36 +398,13 @@ export function tileCentre(lon, lat, z = 14) {
};
}
/** A scene collection that remembers what is on the globe. */
function sceneCollection() {
const items = new Set();
return {
items,
add(primitive) {
items.add(primitive);
return primitive;
},
remove(primitive) {
return items.delete(primitive);
},
};
}
/**
* A viewer looking straight down on a 0.004° square around `view`
* (`{lon, lat, height}`, mutable), enough for line coverage to attach,
* refresh and draw. Cesium's one-time terrain-height download is skipped.
* refresh and draw, on a fake draw port (`viewer.draw`; `drawnLineSets`
* lists what it draws).
*/
export function coverageViewer(view, t) {
const initialize = Cesium.GroundPolylinePrimitive.initializeTerrainHeights;
Cesium.GroundPolylinePrimitive.initializeTerrainHeights = () =>
Promise.resolve();
t?.after(() => {
Cesium.GroundPolylinePrimitive.initializeTerrainHeights = initialize;
});
// Node has no WebGL context to report line-width limits.
Cesium.ContextLimits._minimumAliasedLineWidth = 1;
Cesium.ContextLimits._maximumAliasedLineWidth = 10;
export function coverageViewer(view) {
const listeners = () => {
const set = new Set();
return {
@@ -439,11 +420,6 @@ export function coverageViewer(view, t) {
scene: {
canvas: { clientWidth: 100, clientHeight: 100 },
globe: { show: false, ellipsoid: Cesium.Ellipsoid.WGS84 },
frameState: { mode: Cesium.SceneMode.SCENE3D },
updateHeight: () => () => {},
getHeight: () => undefined,
groundPrimitives: sceneCollection(),
primitives: sceneCollection(),
postRender: listeners(),
preRender: listeners(),
},
@@ -469,5 +445,23 @@ export function coverageViewer(view, t) {
computeViewRectangle: () => undefined,
},
};
return bindFakeCesiumCamera(viewer, streetPorts(viewer));
viewer.draw = fakeDrawPort();
return bindFakeCesiumCamera(
viewer,
streetPorts(viewer, { draw: viewer.draw }),
);
}
/**
* The live Street Level line sets on `viewer.draw`, oldest (drawn lowest)
* first: those with lines in them, or with `empty` every one.
*/
export function drawnLineSets(viewer, { empty = false } = {}) {
return [...viewer.draw.sets.values()].filter(
(set) =>
!set.disposed &&
set.kind === 'lines' &&
set.spec.id.startsWith('street-level:') &&
(empty || set.items.size > 0),
);
}