diff --git a/changelog.d/1832-firms-stand-in-focus-range.md b/changelog.d/1832-firms-stand-in-focus-range.md new file mode 100644 index 0000000000..ad49cc01b3 --- /dev/null +++ b/changelog.d/1832-firms-stand-in-focus-range.md @@ -0,0 +1,3 @@ +- The fire layer's marker stand-in can set how far the camera stands from a + fire it draws (`focusRangeM`), and a world focus request may carry its own + range (samehkhamis, #1832). diff --git a/src/data/firmsInteraction.test.mjs b/src/data/firmsInteraction.test.mjs index 483e4b00dc..14b27c1aaa 100644 --- a/src/data/firmsInteraction.test.mjs +++ b/src/data/firmsInteraction.test.mjs @@ -698,6 +698,7 @@ test('a click on a fire an application draws in place of the markers selects it fireDetectionKey(fire), 'the stand-in decides, not the hidden glow under the click', ); + assert.equal('rangeM' in h.requests[0], false, 'the usual fire framing'); assert.equal(h.layer.getSelectedInfo().id, fireDetectionKey(fire)); assert.equal(getSelectedEntityContext().label, 'Fire · FRP 1520 MW'); assert.deepEqual( @@ -716,6 +717,32 @@ test('a click on a fire an application draws in place of the markers selects it } }); +test('a stand-in that draws a fire larger says how far the camera stands from it', () => { + const fire = makeFire(); + const asked = []; + let range = 24_000; + const h = harness({ fires: [fire] }); + try { + h.layer.setMarkerStandIn({ + hitTest: () => ({ ...fire }), + focusRangeM: (record) => { + asked.push(fireDetectionKey(record)); + return range; + }, + }); + h.click(); + assert.deepEqual(asked, [fireDetectionKey(fire)]); + assert.equal(h.requests.at(-1).rangeM, 24_000); + // No range for this fire: the usual fire framing. + range = null; + h.click(); + assert.equal(h.requests.length, 2); + assert.equal('rangeM' in h.requests.at(-1), false); + } finally { + h.cleanup(); + } +}); + test('a stand-in hit on a fire the layer does not show selects nothing', () => { const fire = makeFire(); const h = harness({ fires: [fire] }); diff --git a/src/layers/firms/lifecycle.js b/src/layers/firms/lifecycle.js index e866894c3b..53aa729667 100644 --- a/src/layers/firms/lifecycle.js +++ b/src/layers/firms/lifecycle.js @@ -78,8 +78,11 @@ export function createLifecycle({ * answers a detection record from the same source, or null) selects it * and moves the camera to it as a click on its marker does, the selected * fire's card shows, and a click on empty space clears the selection. + * Its optional `focusRangeM(record)` gives how far, in metres, the camera + * stands from a fire it draws when moving to it, for fires drawn larger + * than a marker; without one, or for null, the usual fire framing holds. * `null` brings the markers back. The selection is kept either way. - * @param {?{hitTest: (screenPosition: {x: number, y: number}) => ?Object}} standIn + * @param {?{hitTest: (screenPosition: {x: number, y: number}) => ?Object, focusRangeM?: (record: Object) => ?number}} standIn */ setMarkerStandIn(standIn) { layerState._standIn = diff --git a/src/layers/firms/selection.js b/src/layers/firms/selection.js index c3e076ff37..8e8d266e49 100644 --- a/src/layers/firms/selection.js +++ b/src/layers/firms/selection.js @@ -77,11 +77,15 @@ export function createSelection({ function selectAndFocusFire(fire) { selectFire(fire); + // A stand-in that draws the fire larger than a marker says how far the + // camera stands from it (`setMarkerStandIn`). + const rangeM = layerState._standIn?.focusRangeM?.(fire); requestWorldFocus({ kind: 'fire', id: fireDetectionKey(fire), label: t('FIRE'), position: components.model.firePosition(fire), + ...(Number.isFinite(rangeM) && rangeM > 0 ? { rangeM } : {}), }); } diff --git a/src/worldFocus.js b/src/worldFocus.js index af50b2f30b..7c048fac38 100644 --- a/src/worldFocus.js +++ b/src/worldFocus.js @@ -85,7 +85,8 @@ export function routeWorldFocusRequest(event, runExplicitFocus, fly) { * `keepView` (a click on it) keeps the camera's distance and angle: the eye * moves, on a straight path, to where it sees the target in the centre with * the view it has now (`keptViewFrom`). Any other is framed by its kind - * (`WORLD_FOCUS_FRAMING`). + * (`WORLD_FOCUS_FRAMING`); a target's own `rangeM`, past the framed radius, + * stands the camera off that far instead (a target larger than its kind). */ export function flyToWorldTarget(viewer, target = {}) { const camera = findCamera(viewer); @@ -118,7 +119,10 @@ export function flyToWorldTarget(viewer, target = {}) { offset: { heading, pitch: toRadians(framing.pitchDeg), - range: framing.rangeM, + range: + Number.isFinite(target.rangeM) && target.rangeM > framing.radiusM + ? target.rangeM + : framing.rangeM, }, durationS: duration, easing: 'cubicInOut', diff --git a/src/worldFocus.test.mjs b/src/worldFocus.test.mjs index 2f90c5b6f9..fbb15000fc 100644 --- a/src/worldFocus.test.mjs +++ b/src/worldFocus.test.mjs @@ -206,6 +206,25 @@ test('fires frame wider than vessels — a fire is read by its surroundings', () ); }); +test("a target's own range stands the camera off that far, past the framed radius", () => { + const range = (rangeM) => { + const camera = stubCamera(); + flyToWorldTarget(bindFakeCesiumCamera({ camera }), { + kind: 'fire', + id: 'fire-1', + position: POSITION, + rangeM, + }); + const { sphere, options } = camera.calls.flights[0]; + assert.equal(sphere.radius, WORLD_FOCUS_FRAMING.fire.radiusM); + return options.offset.range; + }; + assert.equal(range(24_000), 24_000); + // Inside the framed sphere, or not a number: the kind's own range. + for (const value of [WORLD_FOCUS_FRAMING.fire.radiusM, 0, -5, NaN, '9000']) + assert.equal(range(value), WORLD_FOCUS_FRAMING.fire.rangeM); +}); + test('every framing is a real oblique standoff, not a nadir or an inside-out sphere', () => { const kinds = Object.keys(WORLD_FOCUS_FRAMING); assert.deepEqual(kinds.sort(), [