mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
fix(air-quality): a double-click follows a station again
The stations were entities, which the default renderer's double-click followed, framed to fit the disc; one no longer reported took the follow with it. As draw-port items they took no part in it.
This commit is contained in:
1 parent
fbc40ef3b6
commit
37a1e1500b
2 files changed
+71
-2
No files matched your search
@@ -1,6 +1,11 @@
|
||||
import { fromDegrees } from '../../geo/ellipsoid.js';
|
||||
import { cssColor } from '../../render/color.js';
|
||||
import { drawOf, findCamera } from '../../render/rendererOf.js';
|
||||
import { drawOf, findCamera, findInput } from '../../render/rendererOf.js';
|
||||
import {
|
||||
drawnItemTarget,
|
||||
followOnDoubleClick,
|
||||
} from '../../data/stockFollow.js';
|
||||
import { inputFor as defaultInputFor } from '../../input/dispatcher.js';
|
||||
import { msg, t, tn } from '../../i18n/index.js';
|
||||
import { translateFeedError } from '../../ui/statusText.js';
|
||||
import {
|
||||
@@ -34,7 +39,11 @@ function withAlpha(css, alpha) {
|
||||
}
|
||||
|
||||
/** Own one air-quality display, its refresh lifecycle, and its readout card. */
|
||||
export function createAirQualityLayer({ source, overlayHost } = {}) {
|
||||
export function createAirQualityLayer({
|
||||
source,
|
||||
overlayHost,
|
||||
inputFor = defaultInputFor,
|
||||
} = {}) {
|
||||
if (typeof source?.getSnapshot !== 'function')
|
||||
throw new TypeError('Air quality requires a snapshot source');
|
||||
if (!overlayHost) throw new TypeError('Air quality requires an overlay host');
|
||||
@@ -46,6 +55,9 @@ export function createAirQualityLayer({ source, overlayHost } = {}) {
|
||||
let _lastUpdate = null;
|
||||
let _lastError = null;
|
||||
let _enabled = false;
|
||||
// Each drawn station by id, and the follow a double-click on one started.
|
||||
let _drawn = new Map();
|
||||
let _stockFollow = null;
|
||||
let rowControlsListener = null;
|
||||
|
||||
const notify = () => rowControlsListener?.();
|
||||
@@ -68,6 +80,22 @@ export function createAirQualityLayer({ source, overlayHost } = {}) {
|
||||
show: false,
|
||||
});
|
||||
_viewer = viewer;
|
||||
// A double-click follows a station, framed to fit its disc, as the
|
||||
// default renderer followed its entity (a scene that takes no input
|
||||
// has none).
|
||||
_stockFollow =
|
||||
inputFor && findInput(viewer)
|
||||
? followOnDoubleClick({
|
||||
viewer,
|
||||
inputFor,
|
||||
name: 'air-quality',
|
||||
enabled: () => _enabled,
|
||||
targetFor: (hit) =>
|
||||
hit.set === _markers?.id
|
||||
? drawnItemTarget(hit.set, _drawn.get(hit.id))
|
||||
: null,
|
||||
})
|
||||
: null;
|
||||
_readings = [];
|
||||
_count = 0;
|
||||
_lastUpdate = null;
|
||||
@@ -88,6 +116,7 @@ export function createAirQualityLayer({ source, overlayHost } = {}) {
|
||||
_request?.abort();
|
||||
_request = null;
|
||||
_enabled = false;
|
||||
_stockFollow?.stop();
|
||||
if (_markers) _markers.show = false;
|
||||
overlayHost.clearSource(AIR_QUALITY_OVERLAY_SOURCE_ID);
|
||||
overlayHost.setVisible(AIR_QUALITY_OVERLAY_SOURCE_ID, false);
|
||||
@@ -170,6 +199,11 @@ export function createAirQualityLayer({ source, overlayHost } = {}) {
|
||||
);
|
||||
}
|
||||
_markers.set(markers);
|
||||
_drawn = new Map(markers.map((item) => [item.id, item]));
|
||||
// A station no longer reported takes its follow with it.
|
||||
_stockFollow?.retain((key) =>
|
||||
_drawn.has(key.slice(_markers.id.length + 1)),
|
||||
);
|
||||
if (_enabled) {
|
||||
overlayHost.setEntries(
|
||||
AIR_QUALITY_OVERLAY_SOURCE_ID,
|
||||
@@ -187,6 +221,9 @@ export function createAirQualityLayer({ source, overlayHost } = {}) {
|
||||
_request?.abort();
|
||||
_request = null;
|
||||
_enabled = false;
|
||||
_stockFollow?.destroy();
|
||||
_stockFollow = null;
|
||||
_drawn = new Map();
|
||||
overlayHost.clearSource(AIR_QUALITY_OVERLAY_SOURCE_ID);
|
||||
overlayHost.setVisible(AIR_QUALITY_OVERLAY_SOURCE_ID, false);
|
||||
_markers?.dispose();
|
||||
|
||||
@@ -322,3 +322,35 @@ test('a failed refresh over good readings reports degraded, not nominal', async
|
||||
'showing old data after a failure is degraded',
|
||||
);
|
||||
});
|
||||
|
||||
test('a double-click follows a station until it is no longer reported, as its entity was', async (t) => {
|
||||
const { bindRenderer } = await import('../../render/rendererOf.js');
|
||||
const { createStubRenderer } = await import('../../render/stub/index.js');
|
||||
const renderer = createStubRenderer();
|
||||
const viewer = { isDestroyed: () => false };
|
||||
const unbind = bindRenderer(viewer, renderer);
|
||||
let rows = [reading('a', 12)];
|
||||
const layer = createAirQualityLayer({
|
||||
source: { getSnapshot: async () => rows },
|
||||
overlayHost: { setEntries() {}, setVisible() {}, clearSource() {} },
|
||||
});
|
||||
t.after(() => {
|
||||
layer.destroy();
|
||||
unbind();
|
||||
renderer.destroy();
|
||||
});
|
||||
layer.init(viewer);
|
||||
layer.enable();
|
||||
await layer.update();
|
||||
const set = renderer.testing
|
||||
.sets()
|
||||
.find((id) => id.startsWith('air-quality'));
|
||||
renderer.testing.scriptPicks(() => [
|
||||
{ set, id: 'air-quality:eccc:a', surface: false },
|
||||
]);
|
||||
renderer.testing.pointer('dblclick', 10, 10);
|
||||
assert.ok(renderer.camera.followed, 'the station is followed');
|
||||
rows = [reading('b', 12)];
|
||||
await layer.update();
|
||||
assert.equal(renderer.camera.followed, null, 'gone: not followed');
|
||||
});
|
||||
Reference in new issue
Block a user