Move the bikeshare layer onto the renderer's draw and camera ports

Station dots and the selected-station highlight are now two point draw
sets, picked through the draw hit, and the layer follows the camera
through the camera port at its own threshold instead of the shared
percentageChanged ledger. Altitude and view centre come from the camera
pose and view rectangle. All five bikeshare files leave the Cesium
allow-list.

The Cesium draw port now keeps a rebuilt host in its place in the scene
instead of re-adding it on top, tags hosts with their set id so sprite
order can raise a draw set (registerSpriteSet), and restyles unclamped
points in place when they have not moved, so a status poll or selection
no longer rebuilds every station. Other draw-port layers (cyclone
markers, earthquake discs) now also keep their first-build slot rather
than jumping above the sprite layers on each rebuild.
This commit is contained in:
Sameh Khamis committed 2026-11-06 20:26:35 -08:00
1 parent 2b66c46a30
commit 8c6fa6258b
22 files changed
+732 -249

No files matched your search

+26 -50
View File
@@ -1,9 +1,9 @@
import * as Cesium from 'cesium';
import { t } from '../../i18n/index.js';
import { inputFor } from '../../input/dispatcher.js';
import {
BIKESHARE_SELECTED_OVERLAY_SOURCE_ID,
BIKESHARE_SELECTED_OVERLAY_SOURCE_OPTIONS,
SELECTED_POINT_STYLE,
} from './policy.js';
export function createSelection({
@@ -63,7 +63,7 @@ export function createSelection({
*/
function createBikeshareSelectedOverlayEntry(key, record) {
const position = record?.point?.position;
const position = record?.position;
if (!key || !position) return null;
const [title, ...details] = buildSelectionLabel(record).split('\n');
return {
@@ -91,29 +91,22 @@ export function createSelection({
/**
* Clear the current station selection.
* Re-shows the hidden point primitive and removes the highlight entity.
* Shows the station's own dot again and removes the highlight.
*/
function _clearSelection() {
if (layerState._selectedKey) {
const record = layerState._stationRenderMap.get(layerState._selectedKey);
if (record?.point) {
record.point.show = true;
}
}
if (layerState._selectedEntity && layerState._viewer) {
layerState._viewer.entities.remove(layerState._selectedEntity);
}
const key = layerState._selectedKey;
layerState._selectedKey = null;
layerState._selectedEntity = null;
const record = key ? layerState._stationRenderMap.get(key) : null;
if (record?.position)
layerState._stationSet?.upsert([parts.rendering.stationItem(record)]);
if (layerState._selectedSet?.size()) layerState._selectedSet.clear();
layerState._overlayHost.clearSource(BIKESHARE_SELECTED_OVERLAY_SOURCE_ID);
}
/**
* Select a station by key: hides the original point primitive and adds a
* highlighted cyan entity plus a protected shared-host availability card.
* Select a station by key: hides its own dot and draws a highlighted cyan
* one in its place, plus a protected shared-host availability card.
* @param {string} key - Composite "cityId:stationId" key.
*/
@@ -121,22 +114,14 @@ export function createSelection({
_clearSelection();
const record = layerState._stationRenderMap.get(key);
if (!record || !record.point?.position || !layerState._viewer) return;
if (!record || !record.position || !layerState._stationSet) return;
layerState._selectedKey = key;
// Hide the base point so the highlight entity replaces it visually
record.point.show = false;
layerState._selectedEntity = layerState._viewer.entities.add({
position: record.point.position,
point: {
pixelSize: 14,
color: Cesium.Color.CYAN,
outlineColor: Cesium.Color.BLACK,
outlineWidth: 2,
disableDepthTestDistance: Number.POSITIVE_INFINITY,
},
});
// Hide the base dot so the highlight replaces it visually
layerState._stationSet.upsert([parts.rendering.stationItem(record)]);
layerState._selectedSet?.set([
{ id: 'selected', pos: record.position, ...SELECTED_POINT_STYLE },
]);
const entry = createBikeshareSelectedOverlayEntry(key, record);
if (entry) {
layerState._overlayHost.setEntries(
@@ -151,39 +136,30 @@ export function createSelection({
* Install a screen-space click handler for station selection/deselection.
* Also registers a global keydown listener for Escape-to-deselect.
* Idempotent — does nothing if a handler is already installed.
* @param {Cesium.Viewer} viewer - Cesium viewer instance.
* @param {object} viewer - The viewer the layer draws on.
*/
function _installClickHandler(viewer) {
if (layerState._clickSubscription) return;
layerState._clickSubscription = inputFor(viewer).onClick((event) => {
const picked = event.pick;
const hit = event.drawHit;
if (picked) {
// Clicking selected entity itself — ignore (don't deselect).
if (picked.id === layerState._selectedEntity) return;
if (hit) {
// Clicking the selected highlight itself — ignore (don't deselect).
if (hit.set === layerState._selectedSet?.id) return;
// Check if the picked primitive or entity id matches a station key
const primitive = picked.primitive;
// A station dot of this layer's own set
if (
primitive &&
typeof primitive.id === 'string' &&
layerState._stationRenderMap.has(primitive.id)
hit.set === layerState._stationSet?.id &&
layerState._stationRenderMap.has(hit.id)
) {
_selectStation(primitive.id);
return;
}
if (
typeof picked.id === 'string' &&
layerState._stationRenderMap.has(picked.id)
) {
_selectStation(picked.id);
_selectStation(hit.id);
return;
}
}
// Clicked empty space — deselect.
// Clicked anything else — deselect.
if (layerState._selectedKey) _clearSelection();
});