mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-18 17:22:19 +00:00
Merge branch 'main' into perf/imagery-stale-thumbnail-cancellation-20260929
# Conflicts: # docs/CURRENT-STATE.md
This commit is contained in:
commit
3348e3517e
2055 files changed
+320058
-46434
No files matched your search
@@ -20,7 +20,7 @@ import {
|
||||
PRODUCTS,
|
||||
boxCentre,
|
||||
boxFromPin,
|
||||
boxFromRectangle,
|
||||
boxFromDegrees,
|
||||
boxSideKm,
|
||||
dequantizeBox,
|
||||
fitViewHeightM,
|
||||
@@ -33,7 +33,14 @@ import {
|
||||
viewTooLargeMessage,
|
||||
} from './model.js';
|
||||
import { msg, t } from '../../i18n/index.js';
|
||||
import { fromDegrees, toLonLatH } from '../../geo/ellipsoid.js';
|
||||
import { READOUT_WORDS, displayDay, displayMetres } from './display.js';
|
||||
import {
|
||||
canvasOf,
|
||||
findCamera,
|
||||
findGlobe,
|
||||
findQuery,
|
||||
} from '../../render/rendererOf.js';
|
||||
|
||||
/**
|
||||
* Quiet time after the last arrow key before the focused day previews, so a
|
||||
@@ -66,10 +73,6 @@ const clampUnit = (value, fallback) => {
|
||||
const boxSignature = (box) =>
|
||||
box ? BOX_EDGES.map((edge) => Number(box[edge]).toFixed(6)).join(',') : '';
|
||||
const sourceOf = (product) => PRODUCTS[product]?.source || null;
|
||||
const toDegrees = (radians) => (radians * 180) / Math.PI;
|
||||
const toRadians = (degrees) => (degrees * Math.PI) / 180;
|
||||
const ellipsoidOf = (viewer) =>
|
||||
viewer?.scene?.ellipsoid || viewer?.scene?.globe?.ellipsoid || null;
|
||||
|
||||
/**
|
||||
* The ground under the canvas centre, in degrees; null when the centre is
|
||||
@@ -78,20 +81,14 @@ const ellipsoidOf = (viewer) =>
|
||||
* @returns {{ lon: number, lat: number } | null}
|
||||
*/
|
||||
function viewCentre(viewer) {
|
||||
const ellipsoid = ellipsoidOf(viewer);
|
||||
const canvas = viewer?.scene?.canvas;
|
||||
const query = findQuery(viewer);
|
||||
const canvas = canvasOf(viewer);
|
||||
const width = Number(canvas?.clientWidth);
|
||||
const height = Number(canvas?.clientHeight);
|
||||
if (!ellipsoid?.cartesianToCartographic || !(width > 0) || !(height > 0))
|
||||
return null;
|
||||
const hit = viewer.camera?.pickEllipsoid?.(
|
||||
{ x: width / 2, y: height / 2 },
|
||||
ellipsoid,
|
||||
);
|
||||
const ground = hit ? ellipsoid.cartesianToCartographic(hit) : null;
|
||||
return ground
|
||||
? { lon: toDegrees(ground.longitude), lat: toDegrees(ground.latitude) }
|
||||
: null;
|
||||
if (!query || !(width > 0) || !(height > 0)) return null;
|
||||
const hit = query.pickEllipsoid(width / 2, height / 2);
|
||||
const ground = hit ? toLonLatH(hit) : null;
|
||||
return ground ? { lon: ground.lon, lat: ground.lat } : null;
|
||||
}
|
||||
const modeFrom = (value) =>
|
||||
MODES.includes(value)
|
||||
@@ -102,13 +99,14 @@ const modeFrom = (value) =>
|
||||
|
||||
/**
|
||||
* Create the layer.
|
||||
* @param {{ catalog?: { searchHls: Function }, renderer: object, thumbnails: object, host?: Function, now?: () => Date, days?: number, setTimeoutImpl?: Function, clearTimeoutImpl?: Function }} options
|
||||
* @param {{ catalog?: { searchHls: Function }, renderer: object, thumbnails: object, host?: Function, globeOf?: Function, now?: () => Date, days?: number, setTimeoutImpl?: Function, clearTimeoutImpl?: Function }} options
|
||||
*/
|
||||
export function createRecentImageryLayer({
|
||||
catalog = { searchHls },
|
||||
renderer,
|
||||
thumbnails,
|
||||
host = resolveImageryHost,
|
||||
globeOf = findGlobe,
|
||||
now = () => new Date(),
|
||||
days = CATALOG_DAYS,
|
||||
setTimeoutImpl = (fn, ms) => globalThis.setTimeout(fn, ms),
|
||||
@@ -379,7 +377,13 @@ export function createRecentImageryLayer({
|
||||
const changed =
|
||||
next.collection !== _hostInfo.collection || next.kind !== _hostInfo.kind;
|
||||
_hostInfo = next;
|
||||
renderer.rebind(next);
|
||||
// The layers drape through the viewer's globe port, on the tileset too
|
||||
// when that is the host.
|
||||
renderer.rebind({
|
||||
...next,
|
||||
globe: next.kind === 'none' ? null : globeOf(_viewer),
|
||||
tileset: next.kind === 'tileset' ? _tileset : null,
|
||||
});
|
||||
return changed;
|
||||
}
|
||||
|
||||
@@ -970,10 +974,10 @@ export function createRecentImageryLayer({
|
||||
* @returns {boolean}
|
||||
*/
|
||||
useCurrentView(viewer = _viewer) {
|
||||
const rectangle = viewer?.camera?.computeViewRectangle?.();
|
||||
const rectangle = findCamera(viewer)?.viewRectangle();
|
||||
if (!rectangle)
|
||||
return refuseBox('Point the camera at the ground to use the view');
|
||||
const box = boxFromRectangle(rectangle);
|
||||
const box = boxFromDegrees(rectangle);
|
||||
if (validateBox(box).reason === 'too-large') {
|
||||
const { width, height } = boxSideKm(box);
|
||||
return refuseBox(
|
||||
@@ -992,24 +996,19 @@ export function createRecentImageryLayer({
|
||||
*/
|
||||
zoomToFit() {
|
||||
const target = _boxError ? _refusalTarget : null;
|
||||
const camera = _viewer?.camera;
|
||||
const ellipsoid = ellipsoidOf(_viewer);
|
||||
if (!target || !camera?.flyTo || !ellipsoid?.cartographicToCartesian)
|
||||
return null;
|
||||
const canvas = _viewer.scene?.canvas;
|
||||
// No camera port: a viewer of the caller's own whose renderer did not
|
||||
// bring the camera factory (GEV's own imagery renderer does).
|
||||
const port = findCamera(_viewer);
|
||||
if (!target || !port) return null;
|
||||
const canvas = canvasOf(_viewer);
|
||||
const height = fitViewHeightM({
|
||||
width: canvas?.clientWidth,
|
||||
height: canvas?.clientHeight,
|
||||
fovy: camera.frustum?.fovy,
|
||||
fovy: port.pose().fovy,
|
||||
});
|
||||
camera.flyTo({
|
||||
destination: ellipsoid.cartographicToCartesian({
|
||||
longitude: toRadians(target.lon),
|
||||
latitude: toRadians(target.lat),
|
||||
height,
|
||||
}),
|
||||
port.flyTo(fromDegrees(target.lon, target.lat, height), {
|
||||
orientation: { heading: 0, pitch: -Math.PI / 2, roll: 0 },
|
||||
duration: ZOOM_FIT_SECONDS,
|
||||
durationS: ZOOM_FIT_SECONDS,
|
||||
});
|
||||
return height;
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user