diff --git a/src/layers/cctv/navigation.js b/src/layers/cctv/navigation.js index aa5ba463e5..6b2ba96aaf 100644 --- a/src/layers/cctv/navigation.js +++ b/src/layers/cctv/navigation.js @@ -15,15 +15,11 @@ export function createNavigation({ * @returns {string|null} Camera ID, or null (invalid point, empty catalog). */ function nearestCameraIdToPoint(lat, lon) { - const latitude = Number(lat); - const longitude = Number(lon); if ( - !Number.isFinite(latitude) || - !Number.isFinite(longitude) || - latitude < -90 || - latitude > 90 || - longitude < -180 || - longitude > 180 || + !Number.isFinite(lat) || + !Number.isFinite(lon) || + Math.abs(lat) > 90 || + Math.abs(lon) > 180 || !layerState._records.length ) return null; @@ -31,8 +27,8 @@ export function createNavigation({ let best = null; for (const record of layerState._records) { const distKm = parts.model.haversineKm( - latitude, - longitude, + lat, + lon, record.camera.lat, record.camera.lon, ); diff --git a/src/layers/cctv/navigation.test.mjs b/src/layers/cctv/navigation.test.mjs index dd34b72553..486f897843 100644 --- a/src/layers/cctv/navigation.test.mjs +++ b/src/layers/cctv/navigation.test.mjs @@ -9,30 +9,21 @@ function fixture() { { camera: { id: 'east', lat: 40, lon: -100 } }, ]; const state = { _records: records }; - const eye = { pose: { lat: 40, lon: -101 } }; const parts = { model: { - eyePose: () => eye.pose, + eyePose: () => ({ lat: 40, lon: -101 }), haversineKm(lat1, lon1, lat2, lon2) { return Math.hypot(lat1 - lat2, lon1 - lon2); }, }, }; - const selected = []; - parts.selection = { - setActiveCamera(cameraId) { - selected.push(cameraId); - state._activeCameraId = cameraId; - state._openingCameraProvisional = false; - }, - }; const navigation = createNavigation({ state, services: {}, parts, source: {}, }); - return { state, eye, navigation, selected }; + return { navigation }; } test('nearest camera can be resolved from an explicit WGS84 target', () => { @@ -50,6 +41,7 @@ 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], @@ -59,31 +51,3 @@ test('invalid target coordinates fail closed', () => { assert.equal(navigation.nearestCameraIdToPoint(lat, lon), null); } }); - -test('opening camera keeps viewer-nearest and first-record fallback', () => { - const { state, eye, navigation } = fixture(); - assert.equal(navigation.openingCameraId(), 'east'); - eye.pose = null; - assert.equal(navigation.openingCameraId(), 'west'); - state._records = []; - assert.equal(navigation.openingCameraId(), null); -}); - -test('settled move retargets only a provisional opening camera', () => { - const { state, navigation, selected } = fixture(); - state._enabled = true; - state._openingCameraProvisional = true; - state._activeCameraId = 'west'; - assert.equal(navigation.reopenNearestCamera(), true); - assert.deepEqual(selected, ['east']); - assert.equal(state._activeCameraId, 'east'); - assert.equal(state._openingCameraProvisional, true); - assert.equal(navigation.reopenNearestCamera(), false); - state._activeCameraId = 'west'; - state._openingCameraProvisional = false; - assert.equal(navigation.reopenNearestCamera(), false); - state._openingCameraProvisional = true; - state._enabled = false; - assert.equal(navigation.reopenNearestCamera(), false); - assert.deepEqual(selected, ['east']); -});