mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
fix(street-level): load the coverage in view, and name a rejected token
Tilted views: the visible box came from screen rays against the bare
ellipsoid and the 9 tiles kept were the ones nearest its centre, so a view
over high ground (Denver, 1,600 m up) or near the horizon dropped the
streets in front of the camera. At street zooms the rays now meet an
ellipsoid raised to the ground under the camera, hits beyond a range tied
to camera height are ignored, tilted views also keep the ground around the
camera, and tiles are ranked along the line of sight (nadir to screen
centre). Simulated with real Cesium ray maths over Sacramento and Denver
from 2 m to 1,000 m: the nearest visible ground and the screen centre are
always loaded.
Rejected token: Mapillary's 401/403 reached the panel as a raw "Mapillary
tiles HTTP 403" while the pill said ON, and every pan asked Mapillary again.
The proxy now answers a refusal as {keyRejected: true} and holds it for that
token (5 min), and a 429 with its Retry-After (held until then). The panel
reads KEY REJECTED, names MAPILLARY_CLIENT_TOKEN and Provider Settings,
gates its controls like KEY REQUIRED, requests nothing more, and clears the
message when the layer goes off. A rate limit keeps the drawn tiles and
refreshes once the wait is over.
Found in the IC8 review of #768 (P1 tile selection, P2 rejected token).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
57c58a862a
commit
63280e22c0
19 files changed
+728
-43
No files matched your search
+125
-17
@@ -1,15 +1,14 @@
|
||||
import * as Cesium from 'cesium';
|
||||
|
||||
/**
|
||||
* Camera height above the surface under the camera, in metres. The globe's
|
||||
* terrain answers when the globe is shown; Google 3D hides the globe, so
|
||||
* there the bare-earth height from `groundAt(lon, lat)` answers instead
|
||||
* (without it a camera over a city 1,600 m up reads 1,600 m too high). Falls
|
||||
* back to the ellipsoidal height when neither has a sample yet.
|
||||
* Height of the surface under the camera above the ellipsoid, in metres. The
|
||||
* globe's terrain answers when the globe is shown; Google 3D hides the globe,
|
||||
* so there the bare-earth height from `groundAt(lon, lat)` answers instead.
|
||||
* Null when neither has a sample yet.
|
||||
* @param {object} viewer
|
||||
* @param {{groundAt?: (lon: number, lat: number) => number|null}} [options]
|
||||
*/
|
||||
export function cameraHeightAboveGround(viewer, { groundAt } = {}) {
|
||||
export function groundUnderCamera(viewer, { groundAt } = {}) {
|
||||
const carto = viewer?.camera?.positionCartographic;
|
||||
if (!carto) return null;
|
||||
const globe = viewer.scene?.globe;
|
||||
@@ -19,7 +18,48 @@ export function cameraHeightAboveGround(viewer, { groundAt } = {}) {
|
||||
Cesium.Math.toDegrees(carto.longitude),
|
||||
Cesium.Math.toDegrees(carto.latitude),
|
||||
);
|
||||
return carto.height - (Number.isFinite(ground) ? ground : 0);
|
||||
return Number.isFinite(ground) ? ground : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Camera height above the surface under the camera, in metres (without a
|
||||
* ground sample a camera over a city 1,600 m up would read 1,600 m too
|
||||
* high). Falls back to the ellipsoidal height when nothing has a sample yet.
|
||||
* @param {object} viewer
|
||||
* @param {{groundAt?: (lon: number, lat: number) => number|null}} [options]
|
||||
*/
|
||||
export function cameraHeightAboveGround(viewer, options = {}) {
|
||||
const carto = viewer?.camera?.positionCartographic;
|
||||
if (!carto) return null;
|
||||
return carto.height - (groundUnderCamera(viewer, options) ?? 0);
|
||||
}
|
||||
|
||||
/** The ellipsoid `height` metres above `ellipsoid` (the ground at that height). */
|
||||
function raisedEllipsoid(ellipsoid, height) {
|
||||
if (!Number.isFinite(height) || Math.abs(height) < 1) return ellipsoid;
|
||||
const { x, y, z } = ellipsoid.radii;
|
||||
return new Cesium.Ellipsoid(x + height, y + height, z + height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Where a screen point's ray meets the ground, as a Cartographic, or null.
|
||||
* `maxRange` (metres from the camera) drops hits near the horizon.
|
||||
*/
|
||||
function groundHit(camera, point, ellipsoid, maxRange) {
|
||||
let cartesian = null;
|
||||
try {
|
||||
cartesian = camera.pickEllipsoid(point, ellipsoid);
|
||||
} catch {
|
||||
cartesian = null;
|
||||
}
|
||||
if (!cartesian) return null;
|
||||
if (
|
||||
Number.isFinite(maxRange) &&
|
||||
camera.positionWC &&
|
||||
Cesium.Cartesian3.distance(cartesian, camera.positionWC) > maxRange
|
||||
)
|
||||
return null;
|
||||
return Cesium.Cartographic.fromCartesian(cartesian, ellipsoid) || null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -28,8 +68,18 @@ export function cameraHeightAboveGround(viewer, { groundAt } = {}) {
|
||||
* and only the rays that hit count, so a view that includes the horizon (or a
|
||||
* canvas whose frustum is stale) cannot inflate the box to the whole world;
|
||||
* `computeViewRectangle` is the fallback when too few rays land.
|
||||
*
|
||||
* `groundHeight` raises the ellipsoid to the ground under the camera: Google
|
||||
* 3D hides the globe, and a city 1,600 m up otherwise puts every hit
|
||||
* kilometres ahead of where the rays really meet the streets. `maxRange`
|
||||
* (metres) drops hits near the horizon, which a street-level view would
|
||||
* otherwise stretch into a box far bigger than anything it can show.
|
||||
* `nearRange` (metres) always includes the ground that far around the camera.
|
||||
*/
|
||||
export function visibleBbox(viewer, { grid = 5 } = {}) {
|
||||
export function visibleBbox(
|
||||
viewer,
|
||||
{ grid = 5, groundHeight = null, maxRange = null, nearRange = null } = {},
|
||||
) {
|
||||
const scene = viewer?.scene;
|
||||
const camera = viewer?.camera;
|
||||
if (!scene || !camera) return null;
|
||||
@@ -37,24 +87,42 @@ export function visibleBbox(viewer, { grid = 5 } = {}) {
|
||||
const height = scene.canvas?.clientHeight || scene.canvas?.height || 0;
|
||||
const hits = [];
|
||||
if (width > 0 && height > 0) {
|
||||
const ellipsoid = scene.globe?.ellipsoid || Cesium.Ellipsoid.WGS84;
|
||||
const ellipsoid = raisedEllipsoid(
|
||||
scene.globe?.ellipsoid || Cesium.Ellipsoid.WGS84,
|
||||
groundHeight,
|
||||
);
|
||||
const point = new Cesium.Cartesian2();
|
||||
for (let i = 0; i <= grid; i++) {
|
||||
for (let j = 0; j <= grid; j++) {
|
||||
point.x = (width * i) / grid;
|
||||
point.y = (height * j) / grid;
|
||||
let cartesian = null;
|
||||
try {
|
||||
cartesian = camera.pickEllipsoid(point, ellipsoid);
|
||||
} catch {
|
||||
cartesian = null;
|
||||
}
|
||||
if (!cartesian) continue;
|
||||
const carto = Cesium.Cartographic.fromCartesian(cartesian, ellipsoid);
|
||||
const carto = groundHit(camera, point, ellipsoid, maxRange);
|
||||
if (carto) hits.push(carto);
|
||||
}
|
||||
}
|
||||
}
|
||||
// The ground around the camera always counts: a street-level view's screen
|
||||
// rows skip from the horizon to the first few metres, and turning the
|
||||
// camera should not wait for a reload.
|
||||
const nadir = camera.positionCartographic;
|
||||
if (Number.isFinite(nearRange) && nearRange > 0 && nadir) {
|
||||
const dLat = nearRange / 111_320;
|
||||
const dLon = dLat / Math.max(0.05, Math.cos(nadir.latitude));
|
||||
const lat = Cesium.Math.toDegrees(nadir.latitude);
|
||||
const lon = Cesium.Math.toDegrees(nadir.longitude);
|
||||
for (const [dx, dy] of [
|
||||
[-1, -1],
|
||||
[-1, 1],
|
||||
[1, -1],
|
||||
[1, 1],
|
||||
])
|
||||
hits.push(
|
||||
Cesium.Cartographic.fromDegrees(
|
||||
lon + dx * dLon,
|
||||
Math.max(-85, Math.min(85, lat + dy * dLat)),
|
||||
),
|
||||
);
|
||||
}
|
||||
if (hits.length >= 4) {
|
||||
let west = Infinity;
|
||||
let south = Infinity;
|
||||
@@ -115,3 +183,43 @@ export function viewCentre(viewer) {
|
||||
lon: Cesium.Math.toDegrees(carto.longitude),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The ground the camera is looking at, for ranking coverage tiles: the point
|
||||
* under the camera (`nadir`) and the ground hit at the centre of the screen
|
||||
* (`ahead`, null when the centre ray misses or is out of `maxRange`).
|
||||
* @returns {{nadir: {lon: number, lat: number}, ahead: {lon: number, lat: number}|null}|null}
|
||||
*/
|
||||
export function viewFocus(
|
||||
viewer,
|
||||
{ groundHeight = null, maxRange = null } = {},
|
||||
) {
|
||||
const camera = viewer?.camera;
|
||||
const carto = camera?.positionCartographic;
|
||||
if (!carto) return null;
|
||||
const nadir = {
|
||||
lon: Cesium.Math.toDegrees(carto.longitude),
|
||||
lat: Cesium.Math.toDegrees(carto.latitude),
|
||||
};
|
||||
const canvas = viewer.scene?.canvas;
|
||||
const width = canvas?.clientWidth || canvas?.width || 0;
|
||||
const height = canvas?.clientHeight || canvas?.height || 0;
|
||||
let ahead = null;
|
||||
if (width > 0 && height > 0) {
|
||||
const hit = groundHit(
|
||||
camera,
|
||||
new Cesium.Cartesian2(width / 2, height / 2),
|
||||
raisedEllipsoid(
|
||||
viewer.scene?.globe?.ellipsoid || Cesium.Ellipsoid.WGS84,
|
||||
groundHeight,
|
||||
),
|
||||
maxRange,
|
||||
);
|
||||
if (hit)
|
||||
ahead = {
|
||||
lon: Cesium.Math.toDegrees(hit.longitude),
|
||||
lat: Cesium.Math.toDegrees(hit.latitude),
|
||||
};
|
||||
}
|
||||
return { nadir, ahead };
|
||||
}
|
||||
Reference in new issue
Block a user