Read the street traffic viewport through the camera and query ports

The traffic layer's camera altitude, view bounds and fetch centre come from
the renderer's camera port (its pose and view rectangle), and the reticle
footprint samples the ground with the query port's ellipsoid picks and
rays instead of the camera's own. The footprint's nadir is the pose
position in geodetic radians, as the camera's own cartographic position
was. A pixel the renderer has no ray for (a canvas of no size) samples no
direction, as the unset scratch ray did. The lifecycle part loads the
default renderer's camera factory, so a viewer of a caller's own gets
both ports.

Footprint and viewport leave the allow-list.
This commit is contained in:
Sameh Khamis committed 2026-11-07 00:09:10 -08:00
1 parent 10db177251
commit a8cf63999b
8 files changed
+204 -75

No files matched your search

+54 -5
View File
@@ -33,10 +33,7 @@ test('oblique horizon bearings are bounded and tile caps hold at city latitudes'
[51.507, -0.128],
[70, 10],
]) {
const camera = {
positionCartographic: Cesium.Cartographic.fromDegrees(lon, lat, 300),
heading: 0,
pitch: -Math.PI / 12,
const fake = {
pickEllipsoid(p, e, result) {
if (p.y < 300) return undefined;
return Cesium.Cartesian3.fromDegrees(
@@ -56,8 +53,21 @@ test('oblique horizon bearings are bounded and tile caps hold at city latitudes'
return ray;
},
};
const camera = {
pose: () => ({
position: Cesium.Cartesian3.fromDegrees(lon, lat, 300),
heading: 0,
pitch: -Math.PI / 12,
}),
};
const query = {
pickEllipsoid: (x, y) =>
fake.pickEllipsoid({ x, y }, Cesium.Ellipsoid.WGS84) ?? null,
pickRay: (x, y) =>
fake.getPickRay({ x, y }, { direction: new Cesium.Cartesian3() }),
};
const result = createReticleFootprint()(
{ camera, scene: { canvas: { width: 1280, height: 800 } } },
{ camera, query, width: 1280, height: 800 },
300,
);
assert.ok(result.coverage.coarse.length <= 16);
@@ -90,3 +100,42 @@ test('coarse roads retain far segments but never duplicate a detailed tile core'
assert.equal(roads[0].coordinates.at(-1)[0], b.west);
assert.equal(roads[1].coordinates[0][0], b.east);
});
test('without a camera or query port there is no footprint', () => {
const footprint = createReticleFootprint();
const query = { pickEllipsoid: () => null, pickRay: () => null };
assert.equal(
footprint({ camera: null, query, width: 10, height: 10 }, 300),
null,
);
assert.equal(
footprint(
{ camera: { pose: () => ({}) }, query: null, width: 10, height: 10 },
300,
),
null,
);
});
test('a pixel with no pick ray samples no direction, as before', () => {
const query = {
pickEllipsoid: () => null,
pickRay: () => {
throw new TypeError('no ray on a canvas of no size');
},
};
const camera = {
pose: () => ({
position: Cesium.Cartesian3.fromDegrees(10, 20, 300),
heading: 0,
pitch: -Math.PI / 2,
}),
};
const result = createReticleFootprint()(
{ camera, query, width: 0, height: 0 },
300,
);
assert.ok(Math.abs(result.coverage.near.lat - 20) < 1e-9);
assert.ok(Math.abs(result.coverage.near.lon - 10) < 1e-9);
assert.deepEqual(result.coverage.coarse, []);
});