mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-18 09:12:18 +00:00
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.
88 lines
3.0 KiB
JavaScript
88 lines
3.0 KiB
JavaScript
import {
|
|
CLICK_PICK_WINDOW_PX,
|
|
STREET_LEVEL_LAYER_ID,
|
|
STREET_LEVEL_SET_PREFIX,
|
|
} from './policy.js';
|
|
import { inputFor } from '../../input/dispatcher.js';
|
|
import { toLonLatH } from '../../geo/index.js';
|
|
|
|
/** One click handler for every provider's lines and cones, and the marker. */
|
|
export function createSelection({ state, parts }) {
|
|
const { picking } = state.services;
|
|
|
|
/**
|
|
* The pick id a click hit: a line part of ours answers for its sequence
|
|
* (`meta.pick`); anything else by its own id.
|
|
*/
|
|
function pickIdOf({ drawHit, id }) {
|
|
if (drawHit?.set.startsWith(STREET_LEVEL_SET_PREFIX))
|
|
return drawHit.meta?.pick ?? drawHit.id;
|
|
return id;
|
|
}
|
|
|
|
/** The id carries a provider's prefix: that provider handles the pick. */
|
|
function onClick(event) {
|
|
if (!state.viewer || !state.enabled) return;
|
|
const hit = event.windowHit(CLICK_PICK_WINDOW_PX, CLICK_PICK_WINDOW_PX);
|
|
const route = parts.router.resolve(pickIdOf(hit));
|
|
// Not ours: the ground handler decides whether it is the map itself.
|
|
if (!route) {
|
|
parts.openAtGround?.({ surface: hit.surface, ground: groundOf(event) });
|
|
return;
|
|
}
|
|
// The position marker is the core's own: nothing to select.
|
|
if (!route.instance) return;
|
|
route.instance.handlePick(route.id, {
|
|
groundPoint: () => groundPointOf(event),
|
|
});
|
|
}
|
|
|
|
/** The world position under a click, measured when first asked; null over the sky. */
|
|
const groundOf = (event) => () => event.ground();
|
|
|
|
/** Lon/lat of the ground under a click, or null (sky). */
|
|
function groundPointOf(event) {
|
|
const position = event.ground();
|
|
const ground = position && toLonLatH(position);
|
|
return ground ? { lon: ground.lon, lat: ground.lat } : null;
|
|
}
|
|
|
|
/**
|
|
* Esc clears the selected sequence, but only once nothing closer to the
|
|
* user wants it: an expanded viewer, an open panel or a text field.
|
|
*/
|
|
function onKeyDown(event) {
|
|
if (event.key !== 'Escape' || event.defaultPrevented) return;
|
|
// A text field keeps its Esc, rich-text editors (contenteditable) included.
|
|
const target = event.target;
|
|
if (
|
|
target?.isContentEditable === true ||
|
|
target?.closest?.(
|
|
'.panel-collapsible, [role="dialog"], input, textarea, select',
|
|
)
|
|
)
|
|
return;
|
|
if (!parts.hasSelectedSequence()) return;
|
|
event.preventDefault();
|
|
parts.clearSequences();
|
|
}
|
|
|
|
function install(viewer) {
|
|
if (state.clickSubscription) return;
|
|
state.clickSubscription = inputFor(viewer).onClick(onClick);
|
|
document.addEventListener('keydown', onKeyDown);
|
|
picking?.registerPickOwner?.(STREET_LEVEL_LAYER_ID, parts.router.ownsPick);
|
|
}
|
|
|
|
function uninstall() {
|
|
// Nothing to undo for a layer that was never enabled.
|
|
if (!state.clickSubscription) return;
|
|
state.clickSubscription();
|
|
state.clickSubscription = null;
|
|
document.removeEventListener('keydown', onKeyDown);
|
|
picking?.unregisterPickOwner?.(STREET_LEVEL_LAYER_ID);
|
|
}
|
|
|
|
return { install, uninstall, ownsPick: parts.router.ownsPick };
|
|
}
|