Draw Street Level's marker and cones through the renderer's draw port

The photo marker and every provider's image cones are icon sets on the
draw port now, not billboard collections of their own. Each keeps its
pick id as the item id, so clicks route as before; each set is drawn
(empty) as soon as it is made, so the cones stay drawn over the marker
whichever is first given something to show. The horizon cull still runs
in the layer, against the ellipsoid lowered 1,000 m, and sends only the
items whose show changed; a quiet first cull of items about to be drawn
replaces the flags that held its callback back.

marker and sequenceCones leave the Cesium allow-list. The Panoramax line
click reads the camera height from the camera port.

A difference the contract does not let us avoid: the icons turn to their
bearing about local north (the contract's `course`), where the
billboards used the Earth's axis. Looking straight down nothing changes;
in a tilted view a cone now points along its true bearing on the ground
instead of leaning toward the pole.
This commit is contained in:
Sameh Khamis committed 2026-11-07 01:40:32 -08:00
1 parent a10f3a16e1
commit 40ad27fb95
14 files changed
+432 -233

No files matched your search

+84 -46
View File
@@ -4,6 +4,7 @@ import * as Cesium from 'cesium';
import { createMarker } from './marker.js';
import { bindRenderer } from '../../render/rendererOf.js';
import { streetPorts } from '../../testSupport/streetLevelFakes.mjs';
import { fakeDrawPort } from '../../testSupport/fakeDrawPort.mjs';
/** A viewer whose camera is 20,000 km over `view`, and its pre-render listeners. */
function setup() {
@@ -16,7 +17,6 @@ function setup() {
},
},
scene: {
primitives: { add: (p) => p, remove() {} },
preRender: {
addEventListener(listener) {
preRender.add(listener);
@@ -25,91 +25,129 @@ function setup() {
},
},
};
bindRenderer(viewer, streetPorts(viewer, { camera: true }));
const draw = fakeDrawPort();
bindRenderer(viewer, streetPorts(viewer, { camera: true, draw }));
/** Sprite-order registrations: setId → the entry handed out. */
const sprites = new Map();
const state = {
services: {},
viewer,
marker: {
// Stands in for the billboard collection; ensure() keeps it.
collection: {
show: true,
add: (options) => ({ ...options }),
remove() {},
removeAll() {},
services: {
sprites: {
registerSpriteSet(layerId, setId) {
const entry = { layerId, setId };
sprites.set(setId, entry);
return entry;
},
unregisterSpriteCollection(layerId, entry) {
if (sprites.get(entry?.setId) === entry) sprites.delete(entry.setId);
},
},
billboard: null,
},
viewer,
marker: { set: null, sprite: null, placed: null, look: null },
};
const marker = createMarker({ state });
marker.ensure(viewer);
const frame = () => {
for (const listener of [...preRender]) listener();
};
return { state, view, preRender, marker, frame };
/** The marker's drawn icon, or undefined. */
const icon = () => draw.find('street-level:marker:')?.items.get('sl:pos');
return { state, viewer, view, preRender, marker, frame, draw, icon, sprites };
}
test('the photo marker is hidden behind the globe, and shows from its side', () => {
const { state, view, preRender, marker, frame } = setup();
const { view, preRender, marker, frame, icon } = setup();
// Placed on the far side of the Earth from the camera.
marker.set({ lon: 58.51, lat: -38.58 }, 90);
const billboard = state.marker.billboard;
assert.equal(billboard.show, false, 'not drawn through the globe');
assert.equal(icon().show, false, 'not drawn through the globe');
// Fly round to its side: it shows.
view.lon = 58.51;
view.lat = -38.58;
frame();
assert.equal(billboard.show, true);
assert.equal(icon().show, true);
// Moved to the far side again, without the camera moving.
marker.set({ lon: -121.49, lat: 38.58 }, 0);
assert.equal(billboard.show, false, 'culled where it now stands');
assert.equal(icon().show, false, 'culled where it now stands');
marker.clear();
assert.equal(icon(), undefined, 'cleared');
assert.equal(preRender.size, 0, 'the cull listener is gone');
});
test('destroying the marker stops the horizon cull', () => {
const { marker, preRender } = setup();
test('destroying the marker stops the horizon cull and lets its set go', () => {
const { marker, preRender, draw } = setup();
marker.set({ lon: -121.49, lat: 38.58 }, 0);
assert.equal(preRender.size, 1);
marker.destroy();
assert.equal(preRender.size, 0);
assert.equal(draw.find('street-level:marker:'), undefined, 'disposed');
});
const SPOT = { lon: -121.49, lat: 38.58 };
test('the marker is clamped to the ground and turned to the bearing', () => {
const { state, marker } = setup();
const { marker, icon, draw } = setup();
marker.set(SPOT, 45);
const billboard = state.marker.billboard;
assert.equal(
billboard.heightReference,
Cesium.HeightReference.CLAMP_TO_GROUND,
);
assert.equal(billboard.rotation, -Cesium.Math.toRadians(45));
// Moving it keeps the same billboard.
assert.equal(icon().height, 'clampGround');
assert.equal(icon().rotationMode, 'course');
assert.equal(icon().course, 45);
assert.equal(icon().disableDepthTest, Number.POSITIVE_INFINITY);
// Moving it keeps the one item, updated in place.
marker.set({ lon: -121.5, lat: 38.6 }, 90);
assert.equal(state.marker.billboard, billboard);
const placed = Cesium.Cartographic.fromCartesian(billboard.position);
assert.ok(Math.abs(Cesium.Math.toDegrees(placed.longitude) + 121.5) < 1e-9);
assert.equal(billboard.rotation, -Cesium.Math.toRadians(90));
const set = draw.find('street-level:marker:');
assert.equal(set.items.size, 1);
assert.deepEqual(icon().pos, { lon: -121.5, lat: 38.6 });
assert.equal(icon().course, 90);
});
test('a Street View photo gets a blue view cone; a Mapillary photo GEV\u2019s pin', () => {
const { state, marker } = setup();
const removed = [];
state.marker.collection.remove = (billboard) => removed.push(billboard);
const { marker, icon, state } = setup();
const streetView = { kind: 'view-cone', color: '#4285f4' };
marker.set({ lon: -121.49, lat: 38.58 }, 45, streetView);
const cone = state.marker.billboard;
assert.equal(cone.imageId, 'sl-position:view-cone:#4285f4');
assert.equal(
cone.rotation,
-Cesium.Math.toRadians(45),
'it turns with the view',
);
// Dragging the panorama keeps the look and the billboard.
const cone = icon().image;
assert.equal(state.marker.look, 'view-cone:#4285f4');
assert.deepEqual(icon().size, [48, 48]);
assert.equal(icon().course, 45, 'it turns with the view');
// Dragging the panorama keeps the look.
marker.set({ lon: -121.49, lat: 38.58 }, 90, streetView);
assert.equal(state.marker.billboard, cone);
assert.equal(icon().image, cone);
// A Mapillary photo next (its provider has no marker): the pin.
marker.set({ lon: -121.49, lat: 38.58 }, 90, undefined);
assert.equal(state.marker.billboard.imageId, 'sl-position:pin');
assert.deepEqual(removed, [cone]);
assert.equal(state.marker.look, 'pin');
assert.notEqual(icon().image, cone);
assert.deepEqual(icon().size, [40, 40]);
});
test('hiding the layer hides the marker set', () => {
const { marker, draw } = setup();
marker.set(SPOT, 0);
marker.setVisible(false);
assert.equal(draw.find('street-level:marker:').show, false);
marker.setVisible(true);
assert.equal(draw.find('street-level:marker:').show, true);
});
test('each placement is one write, culled before it is sent', () => {
const { marker, draw, icon } = setup();
const set = draw.find('street-level:marker:');
const before = set.writes;
// Past the horizon: culled, and still sent once.
marker.set({ lon: 58.51, lat: -38.58 }, 0);
assert.equal(set.writes, before + 1);
assert.equal(icon().show, false);
marker.set(SPOT, 0);
assert.equal(set.writes, before + 2);
});
test('a marker destroyed and made again draws in a new set, registered once', () => {
const { marker, viewer, draw, sprites, icon } = setup();
const first = draw.find('street-level:marker:').spec.id;
assert.deepEqual([...sprites.keys()], [first]);
marker.destroy();
assert.equal(sprites.size, 0, 'its sprite order entry goes with it');
marker.ensure(viewer);
const second = draw.find('street-level:marker:').spec.id;
assert.notEqual(second, first);
assert.deepEqual([...sprites.keys()], [second]);
marker.set(SPOT, 30);
assert.equal(icon().course, 30);
});