mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-18 17:22:19 +00:00
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:
1 parent
2b66c46a30
commit
8c6fa6258b
22 files changed
+732
-249
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { negativePiToPi, toDegrees, toRadians } from '../../geo/vector.js';
|
||||
import { findCamera } from '../../render/rendererOf.js';
|
||||
import { GBFS_CITY_REGISTRY } from './registry.js';
|
||||
import {
|
||||
ACTIVATION_EXIT_ALTITUDE_M,
|
||||
@@ -12,44 +13,42 @@ export function createViewport({ state: layerState, services, parts, source }) {
|
||||
|
||||
/**
|
||||
* Get the camera's current altitude in meters above the ellipsoid.
|
||||
* @param {Cesium.Viewer} viewer - Cesium viewer instance.
|
||||
* @param {object} viewer - The viewer the layer draws on.
|
||||
* @returns {number} Altitude in meters, or Infinity if unavailable.
|
||||
*/
|
||||
|
||||
function getCameraAltitude(viewer) {
|
||||
const carto = viewer?.camera?.positionCartographic;
|
||||
return carto && Number.isFinite(carto.height) ? carto.height : Infinity;
|
||||
const height = findCamera(viewer)?.pose().height;
|
||||
return Number.isFinite(height) ? height : Infinity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the lat/lon the camera is currently looking at.
|
||||
* Prefers the center of the computed view rectangle; falls back to the
|
||||
* camera's own cartographic position when the rectangle is unavailable.
|
||||
* @param {Cesium.Viewer} viewer - Cesium viewer instance.
|
||||
* Prefers the center of the view rectangle; falls back to the camera's
|
||||
* own position when the rectangle is unavailable.
|
||||
* @param {object} viewer - The viewer the layer draws on.
|
||||
* @returns {{ lat: number, lon: number }|null} Center coordinates in degrees, or null.
|
||||
*/
|
||||
|
||||
function getCameraCenterLatLon(viewer) {
|
||||
const camera = findCamera(viewer);
|
||||
// Try view rectangle center first (more accurate for tilted views)
|
||||
const rect = viewer?.camera?.computeViewRectangle?.(
|
||||
viewer.scene.globe?.ellipsoid,
|
||||
);
|
||||
const rect = camera?.viewRectangle();
|
||||
if (rect) {
|
||||
const center = Cesium.Rectangle.center(rect);
|
||||
// Across the antimeridian the east edge is west of the west one.
|
||||
let east = toRadians(rect.east);
|
||||
const west = toRadians(rect.west);
|
||||
if (east < west) east += 2 * Math.PI;
|
||||
return {
|
||||
lat: Cesium.Math.toDegrees(center.latitude),
|
||||
lon: Cesium.Math.toDegrees(center.longitude),
|
||||
lat: (rect.south + rect.north) * 0.5,
|
||||
lon: toDegrees(negativePiToPi((west + east) * 0.5)),
|
||||
};
|
||||
}
|
||||
|
||||
// Fallback: use the camera's own position
|
||||
const carto = viewer?.camera?.positionCartographic;
|
||||
if (carto) {
|
||||
return {
|
||||
lat: Cesium.Math.toDegrees(carto.latitude),
|
||||
lon: Cesium.Math.toDegrees(carto.longitude),
|
||||
};
|
||||
}
|
||||
const pose = camera?.pose();
|
||||
if (pose && Number.isFinite(pose.lat) && Number.isFinite(pose.lon))
|
||||
return { lat: pose.lat, lon: pose.lon };
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user