mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
fix(earthquakes): a double-click follows a disc again
The discs were entities, which the default renderer's double-click followed, framed to fit the disc. As draw-port items they took no part in it.
This commit is contained in:
1 parent
b9ccdff0a3
commit
50cd49cc31
2 files changed
+79
-2
No files matched your search
@@ -1,5 +1,7 @@
|
|||||||
import { fromDegrees } from '../../geo/ellipsoid.js';
|
import { fromDegrees } from '../../geo/ellipsoid.js';
|
||||||
import { drawOf } from '../../render/rendererOf.js';
|
import { followOnDoubleClick } from '../../data/stockFollow.js';
|
||||||
|
import { inputFor as defaultInputFor } from '../../input/dispatcher.js';
|
||||||
|
import { drawOf, findInput } from '../../render/rendererOf.js';
|
||||||
import {
|
import {
|
||||||
EARTHQUAKE_OVERLAY_SOURCE_ID,
|
EARTHQUAKE_OVERLAY_SOURCE_ID,
|
||||||
EARTHQUAKE_OVERLAY_COHORT_LIMIT,
|
EARTHQUAKE_OVERLAY_COHORT_LIMIT,
|
||||||
@@ -32,13 +34,20 @@ let instances = 0;
|
|||||||
* Given a Cesium viewer with no renderer bound, the
|
* Given a Cesium viewer with no renderer bound, the
|
||||||
* caller loads the package's `./render/cesium/unbound` export first.
|
* caller loads the package's `./render/cesium/unbound` export first.
|
||||||
*/
|
*/
|
||||||
export function createEarthquakesLayer({ source, overlayHost } = {}) {
|
export function createEarthquakesLayer({
|
||||||
|
source,
|
||||||
|
overlayHost,
|
||||||
|
inputFor = defaultInputFor,
|
||||||
|
} = {}) {
|
||||||
if (typeof source?.getSnapshot !== 'function')
|
if (typeof source?.getSnapshot !== 'function')
|
||||||
throw new TypeError('Earthquakes require a snapshot source');
|
throw new TypeError('Earthquakes require a snapshot source');
|
||||||
if (!overlayHost) throw new TypeError('Earthquakes require an overlay host');
|
if (!overlayHost) throw new TypeError('Earthquakes require an overlay host');
|
||||||
let _viewer = null;
|
let _viewer = null;
|
||||||
let _request = null;
|
let _request = null;
|
||||||
let _discs = null;
|
let _discs = null;
|
||||||
|
// Each drawn disc's centre and radius, for a double-click to follow.
|
||||||
|
let _discsById = new Map();
|
||||||
|
let _stockFollow = null;
|
||||||
// What the discs were drawn from, so analyst reads come from the app, not the drawing.
|
// What the discs were drawn from, so analyst reads come from the app, not the drawing.
|
||||||
let _events = [];
|
let _events = [];
|
||||||
let _count = 0;
|
let _count = 0;
|
||||||
@@ -60,6 +69,26 @@ export function createEarthquakesLayer({ source, overlayHost } = {}) {
|
|||||||
show: false,
|
show: false,
|
||||||
});
|
});
|
||||||
_viewer = viewer;
|
_viewer = viewer;
|
||||||
|
// A double-click follows a disc, framed to fit it, as the default
|
||||||
|
// renderer followed the discs' entities (a scene that takes no input
|
||||||
|
// has no double-click).
|
||||||
|
_stockFollow =
|
||||||
|
findInput(viewer) &&
|
||||||
|
followOnDoubleClick({
|
||||||
|
viewer,
|
||||||
|
inputFor,
|
||||||
|
name: 'earthquakes',
|
||||||
|
enabled: () => _enabled,
|
||||||
|
targetFor: (hit) => {
|
||||||
|
const disc = hit.set === _discs?.id && _discsById.get(hit.id);
|
||||||
|
if (!disc) return null;
|
||||||
|
return {
|
||||||
|
key: `${hit.set}:${hit.id}`,
|
||||||
|
position: () => ({ ...disc.center }),
|
||||||
|
sphere: { center: disc.center, radius: disc.radius },
|
||||||
|
};
|
||||||
|
},
|
||||||
|
});
|
||||||
_count = 0;
|
_count = 0;
|
||||||
_lastUpdate = null;
|
_lastUpdate = null;
|
||||||
_lastError = null;
|
_lastError = null;
|
||||||
@@ -80,6 +109,7 @@ export function createEarthquakesLayer({ source, overlayHost } = {}) {
|
|||||||
_request?.abort();
|
_request?.abort();
|
||||||
_request = null;
|
_request = null;
|
||||||
_enabled = false;
|
_enabled = false;
|
||||||
|
_stockFollow?.stop();
|
||||||
if (_discs) _discs.show = false;
|
if (_discs) _discs.show = false;
|
||||||
overlayHost.clearSource(EARTHQUAKE_OVERLAY_SOURCE_ID);
|
overlayHost.clearSource(EARTHQUAKE_OVERLAY_SOURCE_ID);
|
||||||
overlayHost.setVisible(EARTHQUAKE_OVERLAY_SOURCE_ID, false);
|
overlayHost.setVisible(EARTHQUAKE_OVERLAY_SOURCE_ID, false);
|
||||||
@@ -96,6 +126,7 @@ export function createEarthquakesLayer({ source, overlayHost } = {}) {
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
const nextDiscs = [];
|
const nextDiscs = [];
|
||||||
|
const nextById = new Map();
|
||||||
const nextEvents = [];
|
const nextEvents = [];
|
||||||
let count = 0;
|
let count = 0;
|
||||||
const overlayEntries = [];
|
const overlayEntries = [];
|
||||||
@@ -119,6 +150,10 @@ export function createEarthquakesLayer({ source, overlayHost } = {}) {
|
|||||||
|
|
||||||
const position = fromDegrees(lon, lat);
|
const position = fromDegrees(lon, lat);
|
||||||
nextEvents.push({ usgsId, mag, place, time, depthKm, lon, lat });
|
nextEvents.push({ usgsId, mag, place, time, depthKm, lon, lat });
|
||||||
|
nextById.set(`earthquake:${stableId}`, {
|
||||||
|
center: position,
|
||||||
|
radius: baseRadius,
|
||||||
|
});
|
||||||
// A filled disc on the ground, with static axes: re-tessellating
|
// A filled disc on the ground, with static axes: re-tessellating
|
||||||
// clamped ground geometry every frame is what once cost 30 fps.
|
// clamped ground geometry every frame is what once cost 30 fps.
|
||||||
// No outline: clamped to the ground, Cesium never drew one.
|
// No outline: clamped to the ground, Cesium never drew one.
|
||||||
@@ -145,6 +180,7 @@ export function createEarthquakesLayer({ source, overlayHost } = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_discs.set(nextDiscs);
|
_discs.set(nextDiscs);
|
||||||
|
_discsById = nextById;
|
||||||
_events = nextEvents;
|
_events = nextEvents;
|
||||||
if (_enabled) {
|
if (_enabled) {
|
||||||
overlayHost.setEntries(
|
overlayHost.setEntries(
|
||||||
@@ -181,8 +217,11 @@ export function createEarthquakesLayer({ source, overlayHost } = {}) {
|
|||||||
_enabled = false;
|
_enabled = false;
|
||||||
overlayHost.clearSource(EARTHQUAKE_OVERLAY_SOURCE_ID);
|
overlayHost.clearSource(EARTHQUAKE_OVERLAY_SOURCE_ID);
|
||||||
overlayHost.setVisible(EARTHQUAKE_OVERLAY_SOURCE_ID, false);
|
overlayHost.setVisible(EARTHQUAKE_OVERLAY_SOURCE_ID, false);
|
||||||
|
_stockFollow?.destroy();
|
||||||
|
_stockFollow = null;
|
||||||
_discs?.dispose();
|
_discs?.dispose();
|
||||||
_discs = null;
|
_discs = null;
|
||||||
|
_discsById = new Map();
|
||||||
_events = [];
|
_events = [];
|
||||||
_count = 0;
|
_count = 0;
|
||||||
_lastUpdate = null;
|
_lastUpdate = null;
|
||||||
|
|||||||
@@ -168,3 +168,41 @@ test('a viewer with nothing to draw with is refused at init, and init can be ret
|
|||||||
layer.destroy();
|
layer.destroy();
|
||||||
unbind();
|
unbind();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('a double-click follows a disc, framed to fit it, as its entity was', async (t) => {
|
||||||
|
const { bindRenderer } = await import('../../render/rendererOf.js');
|
||||||
|
const { createStubRenderer } = await import('../../render/stub/index.js');
|
||||||
|
const { resetPointerOwnership } = await import('../../input/dispatcher.js');
|
||||||
|
resetPointerOwnership?.();
|
||||||
|
const renderer = createStubRenderer();
|
||||||
|
const viewer = { isDestroyed: () => false };
|
||||||
|
const unbind = bindRenderer(viewer, renderer);
|
||||||
|
const layer = createEarthquakesLayer({
|
||||||
|
source: { getSnapshot: async () => [row] },
|
||||||
|
overlayHost: { setEntries() {}, setVisible() {}, clearSource() {} },
|
||||||
|
});
|
||||||
|
t.after(() => {
|
||||||
|
layer.destroy(viewer);
|
||||||
|
unbind();
|
||||||
|
renderer.destroy();
|
||||||
|
resetPointerOwnership?.();
|
||||||
|
});
|
||||||
|
layer.init(viewer);
|
||||||
|
layer.enable(viewer);
|
||||||
|
await layer.update(viewer);
|
||||||
|
const set = renderer.testing
|
||||||
|
.sets()
|
||||||
|
.find((id) => id.startsWith('earthquakes:'));
|
||||||
|
renderer.testing.scriptPicks(() => [
|
||||||
|
{ set, id: 'earthquake:event-a', surface: false },
|
||||||
|
]);
|
||||||
|
renderer.testing.pointer('dblclick', 10, 10);
|
||||||
|
const followed = renderer.camera.followed;
|
||||||
|
assert.ok(followed, 'the disc is followed');
|
||||||
|
assert.equal(followed.key, `${set}:earthquake:event-a`);
|
||||||
|
const p = followed.position(0);
|
||||||
|
const lon = (Math.atan2(p.y, p.x) * 180) / Math.PI;
|
||||||
|
assert.ok(Math.abs(lon - row.lon) < 1e-9, String(lon));
|
||||||
|
layer.disable(viewer);
|
||||||
|
assert.equal(renderer.camera.followed, null, 'hiding the layer stops it');
|
||||||
|
});
|
||||||
Reference in new issue
Block a user