mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
fix(earthquakes, cyclones): an item that goes takes its double-click follow with it
Removing a followed entity ended the default renderer's follow. A disc gone from the feed, or a storm point gone from the advisory (or a cleared one), now ends it too.
This commit is contained in:
1 parent
def2e1ecca
commit
fbc40ef3b6
6 files changed
+46
-2
No files matched your search
+11
-1
@@ -100,7 +100,8 @@ export function followViewFrom(sphere, at, camera) {
|
|||||||
* radius 0 by default, and the holder whose entity record shows it, as
|
* radius 0 by default, and the holder whose entity record shows it, as
|
||||||
* `entityFollowTarget` reads one), or zoomed to (`zoomTo`); null for
|
* `entityFollowTarget` reads one), or zoomed to (`zoomTo`); null for
|
||||||
* anything else.
|
* anything else.
|
||||||
* @returns {{readonly following: object|null, stop(): void, destroy(): void}}
|
* @returns {{readonly following: object|null, retain(drawn: (key: string) => boolean): void,
|
||||||
|
* stop(): void, destroy(): void}}
|
||||||
*/
|
*/
|
||||||
export function followOnDoubleClick({
|
export function followOnDoubleClick({
|
||||||
viewer,
|
viewer,
|
||||||
@@ -160,6 +161,15 @@ export function followOnDoubleClick({
|
|||||||
get following() {
|
get following() {
|
||||||
return follow && findCamera(viewer)?.followed === follow ? follow : null;
|
return follow && findCamera(viewer)?.followed === follow ? follow : null;
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* Stop a follow this started of something no longer drawn, as removing
|
||||||
|
* an entity ended the default renderer's follow of it.
|
||||||
|
* @param {(key: string) => boolean} drawn Whether the item keyed so is.
|
||||||
|
*/
|
||||||
|
retain(drawn) {
|
||||||
|
const key = this.following?.key;
|
||||||
|
if (key && !drawn(key)) this.stop();
|
||||||
|
},
|
||||||
/** Stop a follow this started, if the camera still keeps it. */
|
/** Stop a follow this started, if the camera still keeps it. */
|
||||||
stop() {
|
stop() {
|
||||||
const camera = findCamera(viewer);
|
const camera = findCamera(viewer);
|
||||||
|
|||||||
@@ -240,6 +240,7 @@ export function createCyclonesLayer({
|
|||||||
enabled: () => enabled && !destroyed && selectionOwner === owner,
|
enabled: () => enabled && !destroyed && selectionOwner === owner,
|
||||||
targetFor: (hit) => rendering?.followTargetFor?.(hit) ?? null,
|
targetFor: (hit) => rendering?.followTargetFor?.(hit) ?? null,
|
||||||
});
|
});
|
||||||
|
owner.follow = follow;
|
||||||
owner.unsubscribe = () => {
|
owner.unsubscribe = () => {
|
||||||
unsubscribe();
|
unsubscribe();
|
||||||
follow.destroy();
|
follow.destroy();
|
||||||
@@ -312,6 +313,7 @@ export function createCyclonesLayer({
|
|||||||
if (next.unavailable) {
|
if (next.unavailable) {
|
||||||
// An expired advisory must not remain presented as current hazard context.
|
// An expired advisory must not remain presented as current hazard context.
|
||||||
rendering.clear();
|
rendering.clear();
|
||||||
|
selectionOwner?.follow?.stop();
|
||||||
snapshot = next;
|
snapshot = next;
|
||||||
selectedId = null;
|
selectedId = null;
|
||||||
++navigationGeneration;
|
++navigationGeneration;
|
||||||
@@ -331,6 +333,8 @@ export function createCyclonesLayer({
|
|||||||
return false;
|
return false;
|
||||||
snapshot = next;
|
snapshot = next;
|
||||||
error = null;
|
error = null;
|
||||||
|
// A storm point no longer in the advisory takes its follow with it.
|
||||||
|
selectionOwner?.follow?.retain((key) => rendering.drawsFollowKey(key));
|
||||||
if (!snapshot.storms.some((storm) => storm.id === selectedId))
|
if (!snapshot.storms.some((storm) => storm.id === selectedId))
|
||||||
select(
|
select(
|
||||||
selectionIntent === 'cleared'
|
selectionIntent === 'cleared'
|
||||||
@@ -348,6 +352,7 @@ export function createCyclonesLayer({
|
|||||||
error = cause?.message || ADVISORIES_UNAVAILABLE;
|
error = cause?.message || ADVISORIES_UNAVAILABLE;
|
||||||
// Failed acquisition has no bounded last-good age guarantee at this layer.
|
// Failed acquisition has no bounded last-good age guarantee at this layer.
|
||||||
rendering?.clear();
|
rendering?.clear();
|
||||||
|
selectionOwner?.follow?.stop();
|
||||||
snapshot = null;
|
snapshot = null;
|
||||||
selectedId = null;
|
selectedId = null;
|
||||||
++navigationGeneration;
|
++navigationGeneration;
|
||||||
|
|||||||
@@ -269,6 +269,13 @@ export function createCycloneRendering({ viewer, overlayHost }) {
|
|||||||
const at = place.at;
|
const at = place.at;
|
||||||
return { key: `${hit.set}:${hit.id}`, position: () => ({ ...at }) };
|
return { key: `${hit.set}:${hit.id}`, position: () => ({ ...at }) };
|
||||||
},
|
},
|
||||||
|
/** Whether the item a follow's key (`<set>:<item>`) names is drawn now. */
|
||||||
|
drawsFollowKey(key) {
|
||||||
|
for (const set of setIds)
|
||||||
|
if (key.startsWith(`${set}:`))
|
||||||
|
return committed && itemPlaces.has(key.slice(set.length + 1));
|
||||||
|
return false;
|
||||||
|
},
|
||||||
getFocusSphere(id) {
|
getFocusSphere(id) {
|
||||||
return spheres.get(id) || null;
|
return spheres.get(id) || null;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -480,7 +480,11 @@ test('a double-click follows a storm’s points and zooms to its tracks and cone
|
|||||||
}),
|
}),
|
||||||
null,
|
null,
|
||||||
);
|
);
|
||||||
|
const key = `${h.sets.points.spec.id}:cyclone:ep152026:center`;
|
||||||
|
assert.equal(h.rendering.drawsFollowKey(key), true);
|
||||||
|
assert.equal(h.rendering.drawsFollowKey(`other:points:x`), false);
|
||||||
h.rendering.clear();
|
h.rendering.clear();
|
||||||
|
assert.equal(h.rendering.drawsFollowKey(key), false, 'cleared: not drawn');
|
||||||
assert.equal(
|
assert.equal(
|
||||||
h.rendering.followTargetFor(h.hit('points', 'cyclone:ep152026:center')),
|
h.rendering.followTargetFor(h.hit('points', 'cyclone:ep152026:center')),
|
||||||
null,
|
null,
|
||||||
|
|||||||
@@ -181,6 +181,10 @@ export function createEarthquakesLayer({
|
|||||||
|
|
||||||
_discs.set(nextDiscs);
|
_discs.set(nextDiscs);
|
||||||
_discsById = nextById;
|
_discsById = nextById;
|
||||||
|
// A disc no longer reported takes its follow with it.
|
||||||
|
_stockFollow?.retain((key) =>
|
||||||
|
_discsById.has(key.slice(_discs.id.length + 1)),
|
||||||
|
);
|
||||||
_events = nextEvents;
|
_events = nextEvents;
|
||||||
if (_enabled) {
|
if (_enabled) {
|
||||||
overlayHost.setEntries(
|
overlayHost.setEntries(
|
||||||
|
|||||||
@@ -178,9 +178,10 @@ test('a double-click follows a disc, framed to fit it, as its entity was', async
|
|||||||
const viewer = { isDestroyed: () => false };
|
const viewer = { isDestroyed: () => false };
|
||||||
const unbind = bindRenderer(viewer, renderer);
|
const unbind = bindRenderer(viewer, renderer);
|
||||||
const layer = createEarthquakesLayer({
|
const layer = createEarthquakesLayer({
|
||||||
source: { getSnapshot: async () => [row] },
|
source: { getSnapshot: async () => rows },
|
||||||
overlayHost: { setEntries() {}, setVisible() {}, clearSource() {} },
|
overlayHost: { setEntries() {}, setVisible() {}, clearSource() {} },
|
||||||
});
|
});
|
||||||
|
let rows = [row];
|
||||||
t.after(() => {
|
t.after(() => {
|
||||||
layer.destroy(viewer);
|
layer.destroy(viewer);
|
||||||
unbind();
|
unbind();
|
||||||
@@ -203,6 +204,19 @@ test('a double-click follows a disc, framed to fit it, as its entity was', async
|
|||||||
const p = followed.position(0);
|
const p = followed.position(0);
|
||||||
const lon = (Math.atan2(p.y, p.x) * 180) / Math.PI;
|
const lon = (Math.atan2(p.y, p.x) * 180) / Math.PI;
|
||||||
assert.ok(Math.abs(lon - row.lon) < 1e-9, String(lon));
|
assert.ok(Math.abs(lon - row.lon) < 1e-9, String(lon));
|
||||||
|
await layer.update(viewer);
|
||||||
|
assert.ok(renderer.camera.followed, 'still reported: still followed');
|
||||||
|
rows = [{ ...row, stableId: 'event-b', usgsId: 'event-b' }];
|
||||||
|
await layer.update(viewer);
|
||||||
|
assert.equal(
|
||||||
|
renderer.camera.followed,
|
||||||
|
null,
|
||||||
|
'gone from the feed: not followed',
|
||||||
|
);
|
||||||
|
rows = [row];
|
||||||
|
await layer.update(viewer);
|
||||||
|
renderer.testing.pointer('dblclick', 10, 10);
|
||||||
|
assert.ok(renderer.camera.followed);
|
||||||
layer.disable(viewer);
|
layer.disable(viewer);
|
||||||
assert.equal(renderer.camera.followed, null, 'hiding the layer stops it');
|
assert.equal(renderer.camera.followed, null, 'hiding the layer stops it');
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user