mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-18 17:22:19 +00:00
Merge pull request #808 from kvnloo/exp/cctv-target-navigation
feat(cctv): focus nearest camera to an explicit point
This commit is contained in:
6 files changed
+104
-7
No files matched your search
@@ -0,0 +1,3 @@
|
||||
- Add a CCTV control method to select the catalog camera nearest an explicit
|
||||
WGS84 point, optionally flying to it. Viewer-nearest navigation uses the same
|
||||
coordinate lookup (Kevin Rajan, #808).
|
||||
@@ -2867,6 +2867,10 @@ while `_clearLayersOutsideContextMode` switches the layer off): the user
|
||||
switching CCTV off inside Contacts closes the panel as anywhere else. A panel opened by hand while the layer is off stays open, and its
|
||||
meta line reads the catalog count, not the last active camera.
|
||||
|
||||
The CCTV control `focusNearestToPoint(lat, lon, options)` selects the catalog
|
||||
camera nearest a WGS84 point and flies to it unless `focus: false`. No UI action
|
||||
calls it yet.
|
||||
|
||||
## UI disposal
|
||||
|
||||
UI disposal releases the CCTV subscription, command-dock observer, legacy drag
|
||||
|
||||
@@ -614,6 +614,7 @@
|
||||
"src/layers/cctv/ingestion.js",
|
||||
"src/layers/cctv/hover.js",
|
||||
"src/layers/cctv/navigation.js",
|
||||
"src/layers/cctv/navigation.test.mjs",
|
||||
"src/layers/cctv/index.js",
|
||||
"src/layers/cctv/model.js",
|
||||
"src/layers/cctv/geometryQueue.js",
|
||||
|
||||
Vendored
+19
@@ -335,6 +335,25 @@ export function createControls({ state: layerState, services, parts, source }) {
|
||||
return nextId;
|
||||
},
|
||||
|
||||
/**
|
||||
* Selects the camera nearest a WGS84 point and optionally flies to it.
|
||||
* @param {number} lat Latitude in degrees.
|
||||
* @param {number} lon Longitude in degrees.
|
||||
* @param {Object} [options={}]
|
||||
* @param {boolean} [options.focus=true] Whether to fly after selection.
|
||||
* @param {number} [options.durationSec] Fly-to duration in seconds.
|
||||
* @returns {string|null} Camera ID, or null (invalid point, empty catalog).
|
||||
*/
|
||||
focusNearestToPoint(lat, lon, options = {}) {
|
||||
const nearest = parts.navigation.nearestCameraIdToPoint(lat, lon);
|
||||
if (!nearest) return null;
|
||||
parts.selection.setActiveCamera(nearest);
|
||||
if (options.focus !== false) {
|
||||
parts.navigation.focusCamera(nearest, options.durationSec || 1.8);
|
||||
}
|
||||
return nearest;
|
||||
},
|
||||
|
||||
/**
|
||||
* Selects and flies to the camera nearest the current viewer position.
|
||||
* @param {Object} [options={}]
|
||||
|
||||
@@ -9,14 +9,20 @@ export function createNavigation({
|
||||
source,
|
||||
}) {
|
||||
/**
|
||||
* Finds the camera closest to the viewer's current position.
|
||||
* @returns {string|null} Camera ID of the nearest camera, or null.
|
||||
* Nearest catalog camera to a WGS84 point.
|
||||
* @param {number} lat Latitude in degrees.
|
||||
* @param {number} lon Longitude in degrees.
|
||||
* @returns {string|null} Camera ID, or null (invalid point, empty catalog).
|
||||
*/
|
||||
|
||||
function nearestCameraIdToViewer() {
|
||||
const pose = parts.model.eyePose();
|
||||
if (!pose || !layerState._records.length) return null;
|
||||
const { lat, lon } = pose;
|
||||
function nearestCameraIdToPoint(lat, lon) {
|
||||
if (
|
||||
!Number.isFinite(lat) ||
|
||||
!Number.isFinite(lon) ||
|
||||
Math.abs(lat) > 90 ||
|
||||
Math.abs(lon) > 180 ||
|
||||
!layerState._records.length
|
||||
)
|
||||
return null;
|
||||
|
||||
let best = null;
|
||||
for (const record of layerState._records) {
|
||||
@@ -33,6 +39,16 @@ export function createNavigation({
|
||||
return best?.id || null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the camera closest to the viewer's current position.
|
||||
* @returns {string|null} Camera ID of the nearest camera, or null.
|
||||
*/
|
||||
function nearestCameraIdToViewer() {
|
||||
const pose = parts.model.eyePose();
|
||||
if (!pose) return null;
|
||||
return nearestCameraIdToPoint(pose.lat, pose.lon);
|
||||
}
|
||||
|
||||
/**
|
||||
* The camera the layer opens on when none is selected: the one nearest the
|
||||
* viewer, or the first record when the viewer has no position yet.
|
||||
@@ -175,6 +191,7 @@ export function createNavigation({
|
||||
return (((Math.floor(currentIdx) + delta) % total) + total) % total;
|
||||
}
|
||||
return {
|
||||
nearestCameraIdToPoint,
|
||||
nearestCameraIdToViewer,
|
||||
openingCameraId,
|
||||
reopenNearestCamera,
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
|
||||
import { createNavigation } from './navigation.js';
|
||||
|
||||
function fixture() {
|
||||
const records = [
|
||||
{ camera: { id: 'west', lat: 40, lon: -120 } },
|
||||
{ camera: { id: 'east', lat: 40, lon: -100 } },
|
||||
];
|
||||
const state = { _records: records };
|
||||
const parts = {
|
||||
model: {
|
||||
eyePose: () => ({ lat: 40, lon: -101 }),
|
||||
haversineKm(lat1, lon1, lat2, lon2) {
|
||||
return Math.hypot(lat1 - lat2, lon1 - lon2);
|
||||
},
|
||||
},
|
||||
};
|
||||
const navigation = createNavigation({
|
||||
state,
|
||||
services: {},
|
||||
parts,
|
||||
source: {},
|
||||
});
|
||||
return { navigation };
|
||||
}
|
||||
|
||||
test('nearest camera can be resolved from an explicit WGS84 target', () => {
|
||||
const { navigation } = fixture();
|
||||
assert.equal(navigation.nearestCameraIdToPoint(40, -119), 'west');
|
||||
assert.equal(navigation.nearestCameraIdToPoint(40, -101), 'east');
|
||||
});
|
||||
|
||||
test('viewer-nearest delegates to the same target-point owner', () => {
|
||||
const { navigation } = fixture();
|
||||
assert.equal(navigation.nearestCameraIdToViewer(), 'east');
|
||||
});
|
||||
|
||||
test('invalid target coordinates fail closed', () => {
|
||||
const { navigation } = fixture();
|
||||
for (const [lat, lon] of [
|
||||
[NaN, 0],
|
||||
[null, 0],
|
||||
[0, Infinity],
|
||||
[90.00001, 0],
|
||||
[-90.00001, 0],
|
||||
[0, 180.00001],
|
||||
[0, -180.00001],
|
||||
]) {
|
||||
assert.equal(navigation.nearestCameraIdToPoint(lat, lon), null);
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user