mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-18 01:02:23 +00:00
Merge main into german/i18n-plurals-context
The catalogs conflicted only on neighbouring lines: no key changed on both sides, so they are merged key by key in main's order. Main removed the rail timeline, the other user of plain "Latest", so that entry is pruned and the News test no longer checks the timeline's wording.
This commit is contained in:
commit
49409ba8f1
1502 files changed
+180715
-47887
No files matched your search
+169
-149
@@ -1,3 +1,4 @@
|
||||
import { isFollowing, stopFollowing } from '../data/followed.js';
|
||||
import { interruptGlobeRotation } from '../cameraVerbs.js';
|
||||
import { normalizeDisplayText } from '../data/displayText.js';
|
||||
import {
|
||||
@@ -16,7 +17,22 @@ import { defaultGeospatial } from '../search/defaults.js';
|
||||
import { msg } from '../i18n/index.js';
|
||||
import { useProviderSettingsStore } from '../ui/stores/providerSettings.js';
|
||||
import { applicationPinia } from '../ui/vueRuntime.js';
|
||||
import * as Cesium from 'cesium';
|
||||
import {
|
||||
distance as chordM,
|
||||
fromRadians,
|
||||
toCartographicRadians,
|
||||
toDegrees,
|
||||
toLonLatH,
|
||||
toRadians,
|
||||
} from '../geo/index.js';
|
||||
import { sphereFromPoints } from '../geo/sphere.js';
|
||||
import { eyeZoomed } from '../geo/eyeMoves.js';
|
||||
import {
|
||||
cameraOf,
|
||||
canvasOf,
|
||||
findCamera,
|
||||
findQuery,
|
||||
} from '../render/rendererOf.js';
|
||||
import { CITY_POIS } from '../cityPois.js';
|
||||
import { greatCircleKm } from '../geoDistance.js';
|
||||
import { EXCLUSIVE_SURFACE_CLASSES } from '../exclusiveSurfaces.js';
|
||||
@@ -39,7 +55,7 @@ import {
|
||||
getSelectedEntityContext,
|
||||
isContextRecordActive,
|
||||
} from '../data/contextStore.js';
|
||||
import { CCTV_FOCUS_RESULT } from '../layers/cctv/index.js';
|
||||
import { CCTV_FOCUS_RESULT } from '../layers/cctv/policy.js';
|
||||
import {
|
||||
NEAREST_RADIUS_MAX_M as STREET_LEVEL_WIDE_RADIUS_M,
|
||||
STREET_LEVEL_LAYER_ID,
|
||||
@@ -452,7 +468,7 @@ export function createGevActionRunner({
|
||||
// Explicit navigation while TRACKING supersedes the follow camera —
|
||||
// otherwise the tracker drags the view back and "I flew there but can't
|
||||
// do anything" (field finding). track_entity manages its own handoff.
|
||||
if (name === 'zoom_to_globe' && viewer.trackedEntity) {
|
||||
if (name === 'zoom_to_globe' && isFollowing(viewer)) {
|
||||
stopAllTracking(viewer, dataManager);
|
||||
}
|
||||
|
||||
@@ -1258,7 +1274,7 @@ export function createGevActionRunner({
|
||||
return;
|
||||
}
|
||||
interruptCameraMotion('nav:fly_to_location');
|
||||
if (viewer.trackedEntity) stopAllTracking(viewer, dataManager);
|
||||
if (isFollowing(viewer)) stopAllTracking(viewer, dataManager);
|
||||
}),
|
||||
});
|
||||
// No flight started: nothing to wait for. A lookup that was not found,
|
||||
@@ -2946,7 +2962,7 @@ function stopAllTracking(viewer, dataManager) {
|
||||
failed.add(layerId);
|
||||
}
|
||||
}
|
||||
if (viewer) viewer.trackedEntity = undefined;
|
||||
stopFollowing(viewer);
|
||||
if (failed.size) {
|
||||
const failedLayerIds = [...failed];
|
||||
return {
|
||||
@@ -3017,7 +3033,8 @@ async function frameOverhead(viewer, dataManager, styleManager, args = {}) {
|
||||
? 120
|
||||
: 150;
|
||||
const radiusKm = clampNumber(args.radiusKm, 10, 20000, defaultRadiusKm);
|
||||
const center = getViewTargetCartesian(viewer) || viewer.camera.positionWC;
|
||||
const center =
|
||||
getViewTargetCartesian(viewer) || cameraOf(viewer).pose().position;
|
||||
|
||||
let entries = [];
|
||||
if (typeof module.getNearby === 'function') {
|
||||
@@ -3027,7 +3044,7 @@ async function frameOverhead(viewer, dataManager, styleManager, args = {}) {
|
||||
.filter((entry) => entry.position)
|
||||
.map((entry) => ({
|
||||
...entry,
|
||||
distance: Cesium.Cartesian3.distance(center, entry.position),
|
||||
distance: chordM(center, entry.position),
|
||||
}))
|
||||
.filter((entry) => entry.distance <= radiusKm * 1000)
|
||||
.sort((a, b) => a.distance - b.distance)
|
||||
@@ -3044,24 +3061,26 @@ async function frameOverhead(viewer, dataManager, styleManager, args = {}) {
|
||||
};
|
||||
}
|
||||
|
||||
const sphere = Cesium.BoundingSphere.fromPoints(
|
||||
entries.map((entry) => entry.position),
|
||||
);
|
||||
const sphere = sphereFromPoints(entries.map((entry) => entry.position));
|
||||
sphere.radius = Math.max(sphere.radius * 1.25, 8000);
|
||||
const pitch = Cesium.Math.toRadians(isSatellites ? -35 : -62);
|
||||
const pitch = toRadians(isSatellites ? -35 : -62);
|
||||
return runManagedVoiceNavigation(
|
||||
styleManager,
|
||||
'frame',
|
||||
'frame_overhead',
|
||||
() => {
|
||||
viewer.camera.flyToBoundingSphere(sphere, {
|
||||
duration: 2.0,
|
||||
offset: new Cesium.HeadingPitchRange(
|
||||
viewer.camera.heading,
|
||||
pitch,
|
||||
sphere.radius * 2.4,
|
||||
),
|
||||
});
|
||||
const camera = cameraOf(viewer);
|
||||
camera.flyToBounds(
|
||||
{ center: sphere.center, radius: sphere.radius },
|
||||
{
|
||||
durationS: 2.0,
|
||||
offset: {
|
||||
heading: camera.pose().heading,
|
||||
pitch,
|
||||
range: sphere.radius * 2.4,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
let detectionEnabled = false;
|
||||
try {
|
||||
@@ -3241,10 +3260,11 @@ function runManagedVoiceNavigation(
|
||||
export async function getBasemapLabelContext(
|
||||
viewer,
|
||||
service = defaultGeospatial,
|
||||
{ cachedOnly = false, previous = null } = {},
|
||||
{ cachedOnly = false, previous = null, camera = cameraOf(viewer) } = {},
|
||||
) {
|
||||
const cameraHeightM = viewer.camera.positionCartographic.height;
|
||||
const target = getViewTargetCartographic(viewer);
|
||||
const pose = camera.pose();
|
||||
const cameraHeightM = pose.height;
|
||||
const target = getViewTargetCartographic(viewer, camera);
|
||||
if (!target) {
|
||||
return {
|
||||
placeLabels: [],
|
||||
@@ -3255,14 +3275,14 @@ export async function getBasemapLabelContext(
|
||||
};
|
||||
}
|
||||
|
||||
const latitude = Number(Cesium.Math.toDegrees(target.latitude).toFixed(6));
|
||||
const longitude = Number(Cesium.Math.toDegrees(target.longitude).toFixed(6));
|
||||
const latitude = Number(toDegrees(target.latitude).toFixed(6));
|
||||
const longitude = Number(toDegrees(target.longitude).toFixed(6));
|
||||
const view = placeLookupView({
|
||||
latitude,
|
||||
longitude,
|
||||
rangeM: viewTargetRangeM(viewer, target, cameraHeightM),
|
||||
fovRad: viewer.camera.frustum?.fov,
|
||||
aspectRatio: viewer.camera.frustum?.aspectRatio,
|
||||
rangeM: viewTargetRangeM(pose, target, cameraHeightM),
|
||||
fovRad: widerFov(pose),
|
||||
aspectRatio: pose.aspectRatio,
|
||||
tier: basemapLookupTier(cameraHeightM),
|
||||
});
|
||||
if (
|
||||
@@ -3304,13 +3324,24 @@ function basemapLookupTier(cameraHeightM) {
|
||||
].join(':');
|
||||
}
|
||||
|
||||
/**
|
||||
* The wider of the view's two angles of view, radians: the horizontal one
|
||||
* when the view is wider than tall, else the vertical one.
|
||||
*/
|
||||
function widerFov({ fovy, aspectRatio }) {
|
||||
if (!Number.isFinite(fovy) || !Number.isFinite(aspectRatio)) return undefined;
|
||||
return aspectRatio > 1
|
||||
? 2 * Math.atan(Math.tan(fovy / 2) * aspectRatio)
|
||||
: fovy;
|
||||
}
|
||||
|
||||
/** Camera distance to the view target, or the camera height without one. */
|
||||
function viewTargetRangeM(viewer, target, cameraHeightM) {
|
||||
const position = viewer.camera.positionWC;
|
||||
function viewTargetRangeM(pose, target, cameraHeightM) {
|
||||
const position = pose.position;
|
||||
if (!position) return cameraHeightM;
|
||||
const range = Cesium.Cartesian3.distance(
|
||||
const range = chordM(
|
||||
position,
|
||||
Cesium.Cartographic.toCartesian(target),
|
||||
fromRadians(target.longitude, target.latitude, target.height),
|
||||
);
|
||||
return Number.isFinite(range) ? range : cameraHeightM;
|
||||
}
|
||||
@@ -3380,12 +3411,17 @@ async function basemapLabelsAt(
|
||||
};
|
||||
}
|
||||
|
||||
/** Viewers that already prewarm view targets on camera settle. */
|
||||
const prewarmedViewers = new WeakSet();
|
||||
|
||||
function installViewTargetPrewarm(viewer) {
|
||||
if (viewer.__gevViewTargetPrewarmInstalled) return;
|
||||
viewer.__gevViewTargetPrewarmInstalled = true;
|
||||
if (prewarmedViewers.has(viewer)) return;
|
||||
const camera = findCamera(viewer);
|
||||
if (!camera) return;
|
||||
prewarmedViewers.add(viewer);
|
||||
let timer = null;
|
||||
let reportedPrewarmFailure = false;
|
||||
viewer.camera.moveEnd.addEventListener(() => {
|
||||
camera.on('moveEnd', () => {
|
||||
if (timer) window.clearTimeout(timer);
|
||||
timer = window.setTimeout(() => {
|
||||
timer = null;
|
||||
@@ -3429,19 +3465,20 @@ function adjustCameraZoom(viewer, args) {
|
||||
}[amount];
|
||||
if (!fraction) throw new Error(`Unknown zoom amount: ${args.amount}`);
|
||||
|
||||
const camera = viewer.camera;
|
||||
const beforePosition = Cesium.Cartesian3.clone(camera.positionWC);
|
||||
const beforeHeightM = camera.positionCartographic.height;
|
||||
const camera = cameraOf(viewer);
|
||||
const before = camera.pose();
|
||||
const beforePosition = before.position;
|
||||
const beforeHeightM = before.height;
|
||||
const target = getViewTargetCartesian(viewer);
|
||||
const targetDistanceM = target
|
||||
? Cesium.Cartesian3.distance(beforePosition, target)
|
||||
? chordM(beforePosition, target)
|
||||
: Math.max(100, beforeHeightM);
|
||||
const minimumDistanceM = direction === 'in' ? 20 : 50;
|
||||
const movementM = Math.max(minimumDistanceM, targetDistanceM * fraction);
|
||||
|
||||
camera.cancelFlight();
|
||||
if (direction === 'out') {
|
||||
camera.zoomOut(movementM);
|
||||
camera.setView(eyeZoomed(before, -movementM));
|
||||
} else {
|
||||
const safeMovementM = Math.min(
|
||||
movementM,
|
||||
@@ -3456,13 +3493,12 @@ function adjustCameraZoom(viewer, args) {
|
||||
error: 'Camera is already at the minimum target distance',
|
||||
};
|
||||
}
|
||||
camera.zoomIn(safeMovementM);
|
||||
camera.setView(eyeZoomed(before, safeMovementM));
|
||||
}
|
||||
viewer.scene.requestRender();
|
||||
|
||||
const afterPosition = camera.positionWC;
|
||||
const movedM = Cesium.Cartesian3.distance(beforePosition, afterPosition);
|
||||
const afterHeightM = camera.positionCartographic.height;
|
||||
const after = camera.pose();
|
||||
const movedM = chordM(beforePosition, after.position);
|
||||
const afterHeightM = after.height;
|
||||
const moved = movedM >= 0.5;
|
||||
return {
|
||||
ok: moved,
|
||||
@@ -3504,10 +3540,12 @@ function nextIssPass(viewer, dataManager, args) {
|
||||
let latDeg = Number.isFinite(args.latitude) ? args.latitude : null;
|
||||
let lonDeg = Number.isFinite(args.longitude) ? args.longitude : null;
|
||||
if (latDeg == null || lonDeg == null) {
|
||||
const carto = viewer?.camera?.positionCartographic;
|
||||
if (!carto) throw new Error('Camera position unavailable');
|
||||
latDeg = Cesium.Math.toDegrees(carto.latitude);
|
||||
lonDeg = Cesium.Math.toDegrees(carto.longitude);
|
||||
const pose = findCamera(viewer)?.pose();
|
||||
if (!Number.isFinite(pose?.lat) || !Number.isFinite(pose?.lon)) {
|
||||
throw new Error('Camera position unavailable');
|
||||
}
|
||||
latDeg = pose.lat;
|
||||
lonDeg = pose.lon;
|
||||
}
|
||||
const minElevDeg = Number.isFinite(args.minElevationDeg)
|
||||
? args.minElevationDeg
|
||||
@@ -3731,6 +3769,10 @@ function findDataLayerRow(layerId) {
|
||||
}
|
||||
|
||||
function focusDataLayerRow(row, layerId) {
|
||||
// A row the Data Layers finder hides could not be seen: show every row
|
||||
// again (LAYER_FINDER_CLEAR_EVENT in LayerFinder.vue).
|
||||
if (row.classList.contains('is-filtered'))
|
||||
document.dispatchEvent(new CustomEvent('gev:layer-finder-clear'));
|
||||
row.scrollIntoView({ block: 'center', behavior: 'smooth' });
|
||||
row.classList.remove('gev-voice-focus');
|
||||
void row.offsetWidth;
|
||||
@@ -4411,7 +4453,7 @@ async function getEntityContext(
|
||||
const layerId = normalizeLayerId(args.layerId || args.layer);
|
||||
const limit = Math.round(clampNumber(args.limit, 1, 12, 5));
|
||||
const selected = selectedEntityContext(dataManager);
|
||||
const cameraHeightM = viewer.camera.positionCartographic.height;
|
||||
const cameraHeightM = cameraOf(viewer).pose().height;
|
||||
const viewTarget = getViewTargetCartographic(viewer);
|
||||
const scenePromise = getSceneContext(
|
||||
viewer,
|
||||
@@ -4586,7 +4628,7 @@ async function getTargetContext(
|
||||
}
|
||||
const hasPosition = Number.isFinite(lat) && Number.isFinite(lon);
|
||||
const viewTarget = hasPosition
|
||||
? Cesium.Cartographic.fromDegrees(lon, lat)
|
||||
? { longitude: toRadians(lon), latitude: toRadians(lat), height: 0 }
|
||||
: getViewTargetCartographic(viewer);
|
||||
const selected = describeTargetEntity(dataManager, target);
|
||||
const scene = await getSceneContext(
|
||||
@@ -4605,7 +4647,7 @@ async function getTargetContext(
|
||||
selected,
|
||||
};
|
||||
}
|
||||
const cameraHeightM = viewer.camera.positionCartographic.height;
|
||||
const cameraHeightM = cameraOf(viewer).pose().height;
|
||||
const visible = shouldScanVisibleEntities(cameraHeightM)
|
||||
? visibleEntityContexts(viewer, dataManager, {
|
||||
layerId: normalizeLayerId(args.layerId || args.layer),
|
||||
@@ -4710,11 +4752,10 @@ async function aircraftProximityWindowForQuery(
|
||||
let lat = record?.lat;
|
||||
let lon = record?.lon;
|
||||
if (!Number.isFinite(lat) || !Number.isFinite(lon)) {
|
||||
const carto = item.position
|
||||
? Cesium.Cartographic.fromCartesian(item.position)
|
||||
: null;
|
||||
lat = carto ? Cesium.Math.toDegrees(carto.latitude) : null;
|
||||
lon = carto ? Cesium.Math.toDegrees(carto.longitude) : null;
|
||||
const at = item.position ? toLonLatH(item.position) : null;
|
||||
const known = at && Number.isFinite(at.lat) && Number.isFinite(at.lon);
|
||||
lat = known ? at.lat : null;
|
||||
lon = known ? at.lon : null;
|
||||
}
|
||||
const row = {
|
||||
...(record || {
|
||||
@@ -4873,16 +4914,17 @@ const SUBJECT_CENTER_TOLERANCE_KM = 1;
|
||||
* ~1.5 km away — far enough to be a different place, close enough to slip
|
||||
* through and get answered as the subject's window.
|
||||
* @param {{lat: number, lon: number}} center Requested centre.
|
||||
* @param {Cesium.Cartesian3} subjectPosition Subject's world position.
|
||||
* @param {{x: number, y: number, z: number}} subjectPosition Subject's
|
||||
* world position, ECEF.
|
||||
* @returns {boolean} True when the two are the same place.
|
||||
*/
|
||||
function centerMatchesSubject(center, subjectPosition) {
|
||||
if (!Number.isFinite(center?.lat) || !Number.isFinite(center?.lon))
|
||||
return false;
|
||||
const carto = Cesium.Cartographic.fromCartesian(subjectPosition);
|
||||
if (!carto) return false;
|
||||
const subjectLat = Cesium.Math.toDegrees(carto.latitude);
|
||||
const subjectLon = Cesium.Math.toDegrees(carto.longitude);
|
||||
const at = toLonLatH(subjectPosition);
|
||||
if (!at) return false;
|
||||
const subjectLat = at.lat;
|
||||
const subjectLon = at.lon;
|
||||
return (
|
||||
greatCircleKm(
|
||||
{ lat: subjectLat, lon: subjectLon },
|
||||
@@ -4907,13 +4949,13 @@ function visibleEntityContexts(
|
||||
{ layerId = null, limit = 5, target = null } = {},
|
||||
) {
|
||||
const nearbyRecords = [];
|
||||
const canvas = viewer.scene.canvas;
|
||||
const canvas = canvasOf(viewer);
|
||||
const width = canvas.clientWidth || canvas.width || 0;
|
||||
const height = canvas.clientHeight || canvas.height || 0;
|
||||
const centerX = width / 2;
|
||||
const centerY = height / 2;
|
||||
const targetLat = target ? Cesium.Math.toDegrees(target.latitude) : null;
|
||||
const targetLon = target ? Cesium.Math.toDegrees(target.longitude) : null;
|
||||
const targetLat = target ? toDegrees(target.latitude) : null;
|
||||
const targetLon = target ? toDegrees(target.longitude) : null;
|
||||
const store = getContextStore();
|
||||
const enabledLayerIds = new Set(
|
||||
dataManager
|
||||
@@ -4925,8 +4967,8 @@ function visibleEntityContexts(
|
||||
for (const record of store.entities.values()) {
|
||||
if (layerId && record.layerId !== layerId) continue;
|
||||
if (record.layerId && !enabledLayerIds.has(record.layerId)) continue;
|
||||
if (record.entity?.show === false || record.dataSource?.show === false)
|
||||
continue;
|
||||
// Hidden from the map (its carrier or its source not shown).
|
||||
if (!isContextRecordActive(record)) continue;
|
||||
if (!Number.isFinite(record.latitude) || !Number.isFinite(record.longitude))
|
||||
continue;
|
||||
insertNearestRecord(
|
||||
@@ -4947,13 +4989,11 @@ function visibleEntityContexts(
|
||||
}
|
||||
|
||||
const candidates = [];
|
||||
const query = findQuery(viewer);
|
||||
for (const { record } of nearbyRecords) {
|
||||
const position = record.entity?.__localBaseCartesian;
|
||||
if (!position) continue;
|
||||
const screen = Cesium.SceneTransforms.worldToWindowCoordinates(
|
||||
viewer.scene,
|
||||
position,
|
||||
);
|
||||
const position = record.targetPosition;
|
||||
if (!position || !query) continue;
|
||||
const screen = query.project(position);
|
||||
if (
|
||||
!screen ||
|
||||
screen.x < 0 ||
|
||||
@@ -5004,9 +5044,7 @@ async function getSceneContext(
|
||||
viewTarget = null,
|
||||
service = defaultGeospatial,
|
||||
) {
|
||||
const cartographic = Cesium.Cartographic.fromCartesian(
|
||||
viewer.camera.positionWC,
|
||||
);
|
||||
const cartographic = cameraOf(viewer).pose();
|
||||
const basemap = await getBasemapContext(viewer, viewTarget, service);
|
||||
const enabledLayers = dataManager
|
||||
.getAll()
|
||||
@@ -5019,10 +5057,8 @@ async function getSceneContext(
|
||||
}));
|
||||
return {
|
||||
camera: {
|
||||
latitude: Number(Cesium.Math.toDegrees(cartographic.latitude).toFixed(6)),
|
||||
longitude: Number(
|
||||
Cesium.Math.toDegrees(cartographic.longitude).toFixed(6),
|
||||
),
|
||||
latitude: Number(cartographic.lat.toFixed(6)),
|
||||
longitude: Number(cartographic.lon.toFixed(6)),
|
||||
heightM: Math.round(cartographic.height),
|
||||
},
|
||||
basemap,
|
||||
@@ -5039,10 +5075,7 @@ async function getBasemapContext(
|
||||
const { reverseGeocodeCache, nearbyPlacesCache } = cachesFor(service);
|
||||
const target = viewTarget;
|
||||
const samples = sampleViewportCartographics(viewer);
|
||||
const cameraCartographic = Cesium.Cartographic.fromCartesian(
|
||||
viewer.camera.positionWC,
|
||||
);
|
||||
const cameraHeightM = cameraCartographic.height;
|
||||
const cameraHeightM = cameraOf(viewer).pose().height;
|
||||
const viewScale = classifyViewScale(cameraHeightM);
|
||||
const cachedViewportPlaces = viewportPlacesFromCache(
|
||||
samples,
|
||||
@@ -5069,8 +5102,8 @@ async function getBasemapContext(
|
||||
};
|
||||
}
|
||||
|
||||
const latitude = Number(Cesium.Math.toDegrees(target.latitude).toFixed(6));
|
||||
const longitude = Number(Cesium.Math.toDegrees(target.longitude).toFixed(6));
|
||||
const latitude = Number(toDegrees(target.latitude).toFixed(6));
|
||||
const longitude = Number(toDegrees(target.longitude).toFixed(6));
|
||||
const inferredCountry = inferCountryFromSamples(samples);
|
||||
const knownLandmarks = nearbyKnownLandmarks(
|
||||
latitude,
|
||||
@@ -5221,8 +5254,8 @@ function coarseBasemapPlace(
|
||||
};
|
||||
}
|
||||
|
||||
function getViewTargetCartographic(viewer) {
|
||||
const signature = cameraViewSignature(viewer);
|
||||
function getViewTargetCartographic(viewer, camera = cameraOf(viewer)) {
|
||||
const signature = cameraViewSignature(camera);
|
||||
const cached = viewTargetCache.get(viewer);
|
||||
if (
|
||||
cached?.signature === signature &&
|
||||
@@ -5231,11 +5264,11 @@ function getViewTargetCartographic(viewer) {
|
||||
return cached.target;
|
||||
}
|
||||
const position = getViewTargetCartesian(viewer);
|
||||
// `fromCartesian` still returns undefined for a point too near the ellipsoid
|
||||
// center to project; normalize that to the same "no target" null the callers
|
||||
// already handle for a missed pick.
|
||||
const target = position
|
||||
? Cesium.Cartographic.fromCartesian(position) || null
|
||||
// A point too near the ellipsoid center has no geodetic position: the same
|
||||
// "no target" null the callers already handle for a missed pick.
|
||||
const carto = position ? toCartographicRadians(position) : null;
|
||||
const target = carto
|
||||
? { longitude: carto.lon, latitude: carto.lat, height: carto.height }
|
||||
: null;
|
||||
viewTargetCache.set(viewer, {
|
||||
signature,
|
||||
@@ -5245,15 +5278,14 @@ function getViewTargetCartographic(viewer) {
|
||||
return target;
|
||||
}
|
||||
|
||||
function cameraViewSignature(viewer) {
|
||||
const camera = viewer.camera;
|
||||
const cartographic = camera.positionCartographic;
|
||||
function cameraViewSignature(camera) {
|
||||
const pose = camera.pose();
|
||||
return [
|
||||
Cesium.Math.toDegrees(cartographic.latitude).toFixed(5),
|
||||
Cesium.Math.toDegrees(cartographic.longitude).toFixed(5),
|
||||
Math.round(cartographic.height / 2),
|
||||
camera.heading.toFixed(3),
|
||||
camera.pitch.toFixed(3),
|
||||
pose.lat.toFixed(5),
|
||||
pose.lon.toFixed(5),
|
||||
Math.round(pose.height / 2),
|
||||
pose.heading.toFixed(3),
|
||||
pose.pitch.toFixed(3),
|
||||
].join(':');
|
||||
}
|
||||
|
||||
@@ -5261,46 +5293,38 @@ function cameraViewSignature(viewer) {
|
||||
* World position under the center of the viewport, or null when the view has no
|
||||
* target. Each stage of the cascade is validated before it is accepted: a depth
|
||||
* pick over empty sky can return a NaN or center-of-the-earth Cartesian, and
|
||||
* converting one of those throws deep inside Cesium. A degenerate pick is a
|
||||
* converting one of those throws deep inside the maths. A degenerate pick is a
|
||||
* MISSED pick, so it falls through to the next stage rather than poisoning
|
||||
* every caller downstream.
|
||||
*/
|
||||
function getViewTargetCartesian(viewer) {
|
||||
const scene = viewer.scene;
|
||||
const canvas = scene.canvas;
|
||||
const query = findQuery(viewer);
|
||||
if (!query) return null;
|
||||
const canvas = canvasOf(viewer);
|
||||
const width = canvas.clientWidth || canvas.width || 0;
|
||||
const height = canvas.clientHeight || canvas.height || 0;
|
||||
const center = new Cesium.Cartesian2(width / 2, height / 2);
|
||||
const x = width / 2;
|
||||
const y = height / 2;
|
||||
let position = null;
|
||||
|
||||
if (scene.pickPositionSupported && typeof scene.pickPosition === 'function') {
|
||||
// Depth under the pointer, where the renderer can read it.
|
||||
try {
|
||||
position = query.pickPosition(x, y);
|
||||
} catch {
|
||||
position = null;
|
||||
}
|
||||
|
||||
if (!isPickedWorldPosition(position)) {
|
||||
try {
|
||||
position = scene.pickPosition(center);
|
||||
position = query.pickEllipsoid(x, y);
|
||||
} catch {
|
||||
position = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
!isPickedWorldPosition(position) &&
|
||||
viewer.camera &&
|
||||
typeof viewer.camera.pickEllipsoid === 'function'
|
||||
) {
|
||||
if (!isPickedWorldPosition(position)) {
|
||||
try {
|
||||
position = viewer.camera.pickEllipsoid(center, Cesium.Ellipsoid.WGS84);
|
||||
} catch {
|
||||
position = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
!isPickedWorldPosition(position) &&
|
||||
viewer.camera &&
|
||||
typeof viewer.camera.getPickRay === 'function'
|
||||
) {
|
||||
try {
|
||||
const ray = viewer.camera.getPickRay(center);
|
||||
position = scene.globe?.pick(ray, scene) || null;
|
||||
position = query.pickGlobe(query.pickRay(x, y));
|
||||
} catch {
|
||||
position = null;
|
||||
}
|
||||
@@ -5310,8 +5334,7 @@ function getViewTargetCartesian(viewer) {
|
||||
}
|
||||
|
||||
function sampleViewportCartographics(viewer) {
|
||||
const scene = viewer.scene;
|
||||
const canvas = scene.canvas;
|
||||
const canvas = canvasOf(viewer);
|
||||
const width = canvas.clientWidth || canvas.width || 0;
|
||||
const height = canvas.clientHeight || canvas.height || 0;
|
||||
if (!width || !height) return [];
|
||||
@@ -5326,18 +5349,17 @@ function sampleViewportCartographics(viewer) {
|
||||
[0.5, 0.75],
|
||||
];
|
||||
|
||||
const query = findQuery(viewer);
|
||||
if (!query) return [];
|
||||
const samples = [];
|
||||
for (const [x, y] of points) {
|
||||
const cartesian = viewer.camera.pickEllipsoid(
|
||||
new Cesium.Cartesian2(width * x, height * y),
|
||||
Cesium.Ellipsoid.WGS84,
|
||||
);
|
||||
const cartesian = query.pickEllipsoid(width * x, height * y);
|
||||
if (!isPickedWorldPosition(cartesian)) continue;
|
||||
const carto = Cesium.Cartographic.fromCartesian(cartesian);
|
||||
if (!carto) continue;
|
||||
const at = toLonLatH(cartesian);
|
||||
if (!at) continue;
|
||||
samples.push({
|
||||
latitude: Number(Cesium.Math.toDegrees(carto.latitude).toFixed(4)),
|
||||
longitude: Number(Cesium.Math.toDegrees(carto.longitude).toFixed(4)),
|
||||
latitude: Number(at.lat.toFixed(4)),
|
||||
longitude: Number(at.lon.toFixed(4)),
|
||||
});
|
||||
}
|
||||
return samples;
|
||||
@@ -5599,8 +5621,7 @@ async function resolveWithin(promise, timeoutMs, fallback) {
|
||||
|
||||
function approximateCoordinateDistanceSq(latA, lonA, latB, lonB) {
|
||||
const latDelta = latB - latA;
|
||||
const lonDelta =
|
||||
(lonB - lonA) * Math.cos(Cesium.Math.toRadians((latA + latB) / 2));
|
||||
const lonDelta = (lonB - lonA) * Math.cos(toRadians((latA + latB) / 2));
|
||||
return latDelta * latDelta + lonDelta * lonDelta;
|
||||
}
|
||||
|
||||
@@ -5799,23 +5820,24 @@ function analystProviders(
|
||||
?.module?.getContextSnapshot?.();
|
||||
const subject = snapshot?.subject;
|
||||
if (!subject?.position) return null;
|
||||
const carto = Cesium.Cartographic.fromCartesian(subject.position);
|
||||
if (!carto) return null;
|
||||
const at = toLonLatH(subject.position);
|
||||
if (!at || !Number.isFinite(at.lat) || !Number.isFinite(at.lon))
|
||||
return null;
|
||||
return {
|
||||
lat: Cesium.Math.toDegrees(carto.latitude),
|
||||
lon: Cesium.Math.toDegrees(carto.longitude),
|
||||
lat: at.lat,
|
||||
lon: at.lon,
|
||||
label: subject.label || subject.id || null,
|
||||
};
|
||||
},
|
||||
getViewContext() {
|
||||
const carto = viewer.camera.positionCartographic;
|
||||
const altKm = carto.height / 1000;
|
||||
const pose = cameraOf(viewer).pose();
|
||||
const altKm = pose.height / 1000;
|
||||
// View radius scales with altitude: street-level asks stay local,
|
||||
// country-level asks sweep wide. Clamped so "in view" is never absurd.
|
||||
const viewRadiusKm = Math.max(25, Math.min(2500, altKm * 1.6));
|
||||
return {
|
||||
lat: Cesium.Math.toDegrees(carto.latitude),
|
||||
lon: Cesium.Math.toDegrees(carto.longitude),
|
||||
lat: pose.lat,
|
||||
lon: pose.lon,
|
||||
viewRadiusKm,
|
||||
};
|
||||
},
|
||||
@@ -5824,11 +5846,9 @@ function analystProviders(
|
||||
|
||||
/** The camera's view rectangle as [west, south, east, north] degrees, or null. */
|
||||
function cameraViewBox(viewer) {
|
||||
const rect = viewer?.camera?.computeViewRectangle?.();
|
||||
const rect = findCamera(viewer)?.viewRectangle?.();
|
||||
if (!rect) return null;
|
||||
return [rect.west, rect.south, rect.east, rect.north].map((radians) =>
|
||||
Cesium.Math.toDegrees(radians),
|
||||
);
|
||||
return [rect.west, rect.south, rect.east, rect.north];
|
||||
}
|
||||
|
||||
/** Identity fields every compact analyst item keeps when present. */
|
||||
|
||||
Reference in new issue
Block a user