mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-18 09:12:18 +00:00
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:
1 parent
a10f3a16e1
commit
40ad27fb95
14 files changed
+432
-233
No files matched your search
@@ -1,10 +1,14 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { positionMarkerGlyph, viewConeMarkerGlyph } from './glyphs.js';
|
||||
import { COLORS, POSITION_PICK_ID } from './policy.js';
|
||||
import { createHorizonCull } from './view.js';
|
||||
import { fromDegrees } from '../../geo/ellipsoid.js';
|
||||
import { drawOf } from '../../render/rendererOf.js';
|
||||
|
||||
const SPRITE_ID = 'street-level:marker';
|
||||
|
||||
/** Draw-set ids of the markers made so far, so every layer instance has its own. */
|
||||
let markerSets = 0;
|
||||
|
||||
function markerLook(style) {
|
||||
if (style?.kind === 'view-cone') {
|
||||
const color = style.color || COLORS.position;
|
||||
@@ -21,6 +25,24 @@ function markerLook(style) {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The marker's icon: clamped to the ground, turned to the bearing, drawn
|
||||
* over everything near it (the horizon cull hides it past the horizon).
|
||||
*/
|
||||
function markerIcon(position, bearing, look) {
|
||||
return {
|
||||
id: POSITION_PICK_ID,
|
||||
pos: { lon: position.lon, lat: position.lat },
|
||||
height: 'clampGround',
|
||||
image: look.image,
|
||||
size: [look.size, look.size],
|
||||
rotationMode: 'course',
|
||||
course: bearing || 0,
|
||||
anchor: 'center',
|
||||
disableDepthTest: Number.POSITIVE_INFINITY,
|
||||
};
|
||||
}
|
||||
|
||||
/** On-globe marker for the open image, clamped to the ground. */
|
||||
export function createMarker({ state }) {
|
||||
const { render, sprites } = state.services;
|
||||
@@ -29,74 +51,72 @@ export function createMarker({ state }) {
|
||||
render?.governorRequestRender?.('street-level-marker');
|
||||
}
|
||||
|
||||
/** The drawn marker: `{icon, position, show}`, or null. */
|
||||
const placed = () => state.marker.placed;
|
||||
|
||||
// It skips the depth test: hide it while it is behind the globe.
|
||||
const horizon = createHorizonCull({
|
||||
getViewer: () => state.viewer,
|
||||
items: () => (state.marker.billboard ? [state.marker.billboard] : []),
|
||||
onChange: requestRender,
|
||||
items: () => (placed() ? [placed()] : []),
|
||||
onChange: () => {
|
||||
const marker = placed();
|
||||
if (!marker) return;
|
||||
state.marker.set?.upsert([{ ...marker.icon, show: marker.show }]);
|
||||
requestRender();
|
||||
},
|
||||
});
|
||||
|
||||
function ensure(viewer) {
|
||||
if (state.marker.collection) return;
|
||||
state.marker.collection = new Cesium.BillboardCollection({
|
||||
scene: viewer.scene,
|
||||
if (state.marker.set) return;
|
||||
state.marker.set = drawOf(viewer).icons({
|
||||
id: `${SPRITE_ID}:${++markerSets}`,
|
||||
});
|
||||
viewer.scene.primitives.add(state.marker.collection);
|
||||
sprites?.registerSpriteCollection?.(SPRITE_ID, state.marker.collection);
|
||||
// Drawn from now, empty: the marker keeps its place under the cones
|
||||
// (made after it), whichever is first given something to draw.
|
||||
state.marker.set.set([]);
|
||||
state.marker.sprite =
|
||||
sprites?.registerSpriteSet?.(SPRITE_ID, state.marker.set.id) ?? null;
|
||||
}
|
||||
|
||||
/** Move (or create) the marker; null removes it. `style`: the provider's `marker`. */
|
||||
function set(position, bearing, style = null) {
|
||||
const collection = state.marker.collection;
|
||||
if (!collection) return;
|
||||
const markers = state.marker.set;
|
||||
if (!markers) return;
|
||||
if (!position) {
|
||||
collection.removeAll();
|
||||
state.marker.billboard = null;
|
||||
markers.clear();
|
||||
state.marker.placed = null;
|
||||
horizon.stop();
|
||||
requestRender();
|
||||
return;
|
||||
}
|
||||
const cartesian = Cesium.Cartesian3.fromDegrees(position.lon, position.lat);
|
||||
const look = markerLook(style);
|
||||
if (state.marker.billboard && state.marker.look !== look.key) {
|
||||
collection.remove?.(state.marker.billboard);
|
||||
state.marker.billboard = null;
|
||||
}
|
||||
if (!state.marker.billboard) {
|
||||
state.marker.look = look.key;
|
||||
state.marker.billboard = collection.add({
|
||||
id: POSITION_PICK_ID,
|
||||
position: cartesian,
|
||||
image: look.image,
|
||||
imageId: `sl-position:${look.key}`,
|
||||
width: look.size,
|
||||
height: look.size,
|
||||
alignedAxis: Cesium.Cartesian3.UNIT_Z,
|
||||
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
|
||||
disableDepthTestDistance: Number.POSITIVE_INFINITY,
|
||||
verticalOrigin: Cesium.VerticalOrigin.CENTER,
|
||||
});
|
||||
} else {
|
||||
state.marker.billboard.position = cartesian;
|
||||
}
|
||||
state.marker.billboard.rotation = -Cesium.Math.toRadians(bearing || 0);
|
||||
horizon.update([state.marker.billboard]);
|
||||
state.marker.look = look.key;
|
||||
// Culled before it is drawn, so a marker past the horizon never shows.
|
||||
const marker = {
|
||||
position: fromDegrees(position.lon, position.lat),
|
||||
show: placed()?.show ?? true,
|
||||
icon: markerIcon(position, bearing, look),
|
||||
};
|
||||
state.marker.placed = marker;
|
||||
horizon.update([marker], { quiet: true });
|
||||
markers.upsert([{ ...marker.icon, show: marker.show }]);
|
||||
requestRender();
|
||||
}
|
||||
|
||||
function setVisible(visible) {
|
||||
if (state.marker.collection) state.marker.collection.show = visible;
|
||||
if (state.marker.set) state.marker.set.show = visible;
|
||||
requestRender();
|
||||
}
|
||||
|
||||
function destroy(viewer) {
|
||||
function destroy() {
|
||||
horizon.stop();
|
||||
const collection = state.marker.collection;
|
||||
if (!collection) return;
|
||||
sprites?.unregisterSpriteCollection?.(SPRITE_ID, collection);
|
||||
viewer?.scene?.primitives?.remove(collection);
|
||||
state.marker.collection = null;
|
||||
state.marker.billboard = null;
|
||||
const markers = state.marker.set;
|
||||
if (!markers) return;
|
||||
sprites?.unregisterSpriteCollection?.(SPRITE_ID, state.marker.sprite);
|
||||
markers.dispose();
|
||||
state.marker.set = null;
|
||||
state.marker.sprite = null;
|
||||
state.marker.placed = null;
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
Reference in new issue
Block a user