mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
fix(input): no double-click follow or zoom on the map
The globe viewer's own double-click tracked a picked entity with a position or zoomed to one without. Layers moving onto the draw port had it re-created one by one (data/stockFollow.js); following is a click in GEV, so the viewer's handler is removed where the viewer is made and every re-creation goes: earthquakes, cyclones, air quality, news, perimeters, drone airspace, ghost maps, places, radio, cables, CCTV, ALPR, launches, bikeshare, Local ADS-B, installations, directions, trails, data packs, annotations, the library's view and local GeoJSON. The Cockpit's own double-click and the draw tool's finishing double-click stay.
This commit is contained in:
1 parent
bb2d22dbce
commit
b86014244d
69 files changed
+94
-2797
No files matched your search
@@ -2,6 +2,12 @@
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
- A double-click on the map no longer follows or zooms to what is under
|
||||
it. The globe's own double-click did that for some layers' markers and
|
||||
shapes (earthquakes, cyclones, air quality, news, cables, places and
|
||||
others); following something is a click, as for aircraft and ships. The
|
||||
Cockpit's double-click and a drawing's finishing double-click are
|
||||
unchanged (samehkhamis).
|
||||
- Aircraft no longer jump ahead or back, and their trails no longer kink,
|
||||
when the feed is late. The civil and military layers draw as far behind
|
||||
real time as their feed is late (the 90th percentile of recent report
|
||||
|
||||
@@ -3407,10 +3407,7 @@ which embeds the MAP_KEY.
|
||||
selected site's dot (a set of its own, so selecting one redraws no other),
|
||||
their ground outlines and the selected site's fill are renderer draw sets;
|
||||
reloads keep the drawn items of sites whose geometry is unchanged, so
|
||||
outlines and fills do not blink. A double-click on a dot follows the site
|
||||
through the camera port, centred on the surface under it (one on an outline
|
||||
or fill zooms to it), as the default renderer's double-click followed its
|
||||
entity; hiding the layer stops that follow. The layer no longer reaches
|
||||
outlines and fills do not blink. The layer no longer reaches
|
||||
Cesium; a caller handing it a Cesium viewer, with no
|
||||
renderer bound, loads the `./render/cesium/unbound` export once first.
|
||||
While Contacts has a subject, the layer loads a window around it
|
||||
@@ -7374,7 +7371,7 @@ request viewbox and continues searching without that geographic preference.
|
||||
- **Input handling.** Coordinates and GeoJSON geometry types are checked before anything is drawn. Only short plain names reach GeoJSON property bags; file IDs, custom CRS and styling properties are removed. KML feature/geometry IDs are removed while Style/StyleMap references remain. Local style references are trimmed, incomplete style pairs removed, hidden-folder flags normalized to the import's show control, and unsupported prototype-named elements removed. UTF-16 BOMs and common KML namespace export defects are handled. Empty drawable content is refused. A loader failure or timeout does not hold the next file indefinitely; teardown aborts pending waits.
|
||||
- **References and images.** File-authored remote links/icons/styles, network links, models and screen/photo overlays are removed. Packed KMZ and embedded PNG/JPEG/GIF/WebP/BMP images remain local; decoded dimensions are checked before image decoding against a total 16-megapixel and 8,192-pixel-side budget per file. Blocked IconStyle images fall back to local pins; authored empty icons remain empty. Colored overlays without an Icon survive; overlays with a removed external image are dropped. Metadata, labels and descriptions are removed; only a short plain name reaches a drawn item. The default pins are shared SVG images.
|
||||
- **Bounds.** File size ≤50 MiB; inflated KMZ ≤120 MiB; ≤20,000 entities (including multipart children and Folder containers); ≤250,000 positions; ≤2,000 normalized style definitions and distinct image links; ≤12 files per session. Exact repeated styles share definitions without changing inheritance or inline overrides. Files of 20–30 MB fit the byte budget, subject to geometry/image limits. Refusals name a reason and batches continue; with multiple failures the hint shows the first reason.
|
||||
- **Code layout.** `src/data/geoFileImport.js` reads, bounds and sanitizes the files. `src/data/geoImportFeatures.js` turns the sanitized KML or GeoJSON into plain features (pins, lines, walls, polygons and ground overlays) with the styles Cesium's KML and GeoJSON loaders gave them: icon, scale, colour, heading and hot spot; line and polygon colours and widths; extruded or clamped geometry. `src/data/geoImportPins.js` draws those features through the renderer's draw port (`drawOf`), settles ground pins through the height service, follows a double-clicked pin and frames the file for Fly-to. None of the three reaches Cesium, so the Cesium allow-list is empty. `src/data/geoImportShared.js` holds the error, limits, deadline and feature names they use.
|
||||
- **Code layout.** `src/data/geoFileImport.js` reads, bounds and sanitizes the files. `src/data/geoImportFeatures.js` turns the sanitized KML or GeoJSON into plain features (pins, lines, walls, polygons and ground overlays) with the styles Cesium's KML and GeoJSON loaders gave them: icon, scale, colour, heading and hot spot; line and polygon colours and widths; extruded or clamped geometry. `src/data/geoImportPins.js` draws those features through the renderer's draw port (`drawOf`), settles ground pins through the height service and frames the file for Fly-to. None of the three reaches Cesium, so the Cesium allow-list is empty. `src/data/geoImportShared.js` holds the error, limits, deadline and feature names they use.
|
||||
- **Lifecycle and keyboard.** `createApplicationTools` wires `initGeoFileImport` with viewer, navigation, ground services and map-source subscription. Destroy aborts pending work, unsubscribes, removes each file's draw sets, revokes blob URLs, removes document/canvas listeners and releases `window.__gevGeoImport`. List rebuilds retain keyboard focus; removing a row hands focus to the next row, else the previous row, else Import.
|
||||
- **Validation.** `node scripts/qa-geo-import.mjs` covers all four formats and real painted show/hide. Run `node scripts/qa-geo-import-regressions.mjs` against both dev and preview for XYZ/track heights, failure recovery, namespace/BOM support, portrait framing and panel drops. `node scripts/qa-geo-import-large.mjs [--file /absolute/path/sample.kml] [--expect-local-pins]` checks a 27.6 MB repeated-style file, that what the import draws matches Cesium's own `KmlDataSource` reading of the same file (positions, scale, heading, colours, widths, fills), large-file painted output and frame times. The QA scripts read what a file drew through `window.__gevGeoImport.drawn(id)`. It records the WebGL renderer; software-rendered runs do not establish GPU performance. Unit tests live beside the data/controller/framing modules.
|
||||
|
||||
|
||||
@@ -57,11 +57,7 @@ Cesium viewer with no renderer bound loads
|
||||
`gods-eye-view/render/cesium/unbound` once first; until then the layer reports
|
||||
an error naming it, as it does for a dataset it cannot load.
|
||||
A selected feature is the context record its draw item carries as `meta`; the
|
||||
layer no longer sets the viewer's `selectedEntity`. While the renderer's own
|
||||
double-click follow is on, a double-click follows a point or polygon through
|
||||
the camera port, looking at the centre of what it draws (stem included), framed
|
||||
as the default renderer framed an entity it began following, and zooms to a
|
||||
line, which has no stem to follow.
|
||||
layer no longer sets the viewer's `selectedEntity`.
|
||||
Features keep their own simplestyle `fill`, `fill-opacity`, `stroke`,
|
||||
`stroke-opacity`, `stroke-width`, `marker-color` and `marker-size`, given as
|
||||
hex, `rgb()` or `hsl()` colours or by the CSS colour names the default renderer
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
"modules": [
|
||||
"src/data/infrastructure.js",
|
||||
"src/data/localGeojsonCore.js",
|
||||
"src/data/stockFollow.js",
|
||||
"src/data/geojsonPins.js",
|
||||
"src/render/cesium/heights.js",
|
||||
"src/render/cesium/camera.js",
|
||||
@@ -2687,7 +2686,6 @@
|
||||
"src/layers/launches/ingestion.js",
|
||||
"src/layers/launches/launchPad.js",
|
||||
"src/layers/launches/lifecycle.js",
|
||||
"src/data/stockFollow.js",
|
||||
"src/layers/launches/model.js",
|
||||
"src/render/color.js",
|
||||
"src/geo/index.js",
|
||||
@@ -4114,7 +4112,6 @@
|
||||
"src/data/layerStateTokenReservations.json",
|
||||
"src/data/lifecycle.js",
|
||||
"src/data/localGeojsonCore.js",
|
||||
"src/data/stockFollow.js",
|
||||
"src/data/geojsonPins.js",
|
||||
"src/data/localGeojsonLod.js",
|
||||
"src/data/local_data/natural_earth/marine.json",
|
||||
@@ -5417,7 +5414,6 @@
|
||||
"src/data/layerState.js",
|
||||
"src/data/layerStateTokenReservations.json",
|
||||
"src/data/localGeojsonCore.js",
|
||||
"src/data/stockFollow.js",
|
||||
"src/data/geojsonPins.js",
|
||||
"src/data/localGeojsonLod.js",
|
||||
"src/data/local_data/natural_earth/marine.json",
|
||||
@@ -7425,7 +7421,6 @@
|
||||
"src/i18n/locales/zh-Hant.json",
|
||||
"src/data/geoImportImages.js",
|
||||
"src/data/geoImportPins.js",
|
||||
"src/data/stockFollow.js",
|
||||
"src/data/geojsonPins.js",
|
||||
"src/geo/sphere.js",
|
||||
"src/data/followed.js",
|
||||
|
||||
@@ -6,12 +6,9 @@ import {
|
||||
drawOf,
|
||||
findCamera,
|
||||
findFrame,
|
||||
findInput,
|
||||
frameOf,
|
||||
} from '../render/rendererOf.js';
|
||||
import { heightsOf } from '../queries/heights.js';
|
||||
import { drawnItemTarget, followOnDoubleClick } from '../data/stockFollow.js';
|
||||
import { inputFor } from '../input/dispatcher.js';
|
||||
|
||||
/**
|
||||
* World-space annotation renderer (Direction A).
|
||||
@@ -102,8 +99,6 @@ export function createWorldAnnotationRenderer(viewer) {
|
||||
const groundQueue = [];
|
||||
let offGroundFrame = null;
|
||||
let destroyed = false;
|
||||
/** The follow a double-click on a mark started (see the end). */
|
||||
let stockFollow = null;
|
||||
// Marks with a target ring, and the radius they are drawn at.
|
||||
const ringed = new Set();
|
||||
let offRingFrame = null;
|
||||
@@ -475,9 +470,6 @@ export function createWorldAnnotationRenderer(viewer) {
|
||||
}
|
||||
|
||||
function remove(anno) {
|
||||
// Its entities went, and with them a follow of one.
|
||||
const prefix = anno?._draw?.prefix;
|
||||
if (prefix) stockFollow?.retain((key) => !key.startsWith(`${prefix}:`));
|
||||
pendingGround.get(anno)?.finish('cancelled');
|
||||
hideOsmCredit(viewer, anno);
|
||||
osmAnnotations.delete(anno);
|
||||
@@ -520,8 +512,6 @@ export function createWorldAnnotationRenderer(viewer) {
|
||||
|
||||
function destroy() {
|
||||
destroyed = true;
|
||||
stockFollow?.destroy();
|
||||
stockFollow = null;
|
||||
for (const task of [...pendingGround.values()]) task.finish('cancelled');
|
||||
for (const anno of osmAnnotations) hideOsmCredit(viewer, anno);
|
||||
osmAnnotations.clear();
|
||||
@@ -535,41 +525,6 @@ export function createWorldAnnotationRenderer(viewer) {
|
||||
drawn.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* What a double-click on a hit follows or zooms to, as the default
|
||||
* renderer did for a mark's entities: a pin's ring or marker is followed,
|
||||
* an area, building or line zoomed to.
|
||||
*/
|
||||
function followTargetFor(hit) {
|
||||
if (hit.surface) return null;
|
||||
for (const anno of drawn) {
|
||||
const sets = anno._draw;
|
||||
const was = anno._drawn;
|
||||
if (!sets || !was || anno.hidden) continue;
|
||||
const kind = ['shapes', 'lines', 'points'].find(
|
||||
(name) => sets[name]?.id === hit.set,
|
||||
);
|
||||
if (!kind) continue;
|
||||
const item = was.items[kind]
|
||||
.map((make) => make(was.alpha))
|
||||
.find((candidate) => candidate.id === hit.id);
|
||||
return drawnItemTarget(hit.set, item);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// A double-click on a mark, as the default renderer's own followed its
|
||||
// entities (a scene that takes no input has none).
|
||||
stockFollow = findInput(viewer)
|
||||
? followOnDoubleClick({
|
||||
viewer,
|
||||
inputFor,
|
||||
name: 'annotations',
|
||||
enabled: () => !destroyed,
|
||||
targetFor: followTargetFor,
|
||||
})
|
||||
: null;
|
||||
|
||||
return { add, remove, sync, destroy };
|
||||
}
|
||||
|
||||
|
||||
@@ -446,33 +446,3 @@ test('a mark removed and added again draws afresh; two renderers on one viewer k
|
||||
assert.equal(route._draw, null, 'a destroyed renderer draws nothing more');
|
||||
assert.equal([...draw.sets.values()].filter((r) => !r.disposed).length, 0);
|
||||
});
|
||||
|
||||
test('a double-click follows a pin and zooms to an area, as their entities were; a removed pin ends it', async (t) => {
|
||||
const { createStubRenderer } = await import('../render/stub/index.js');
|
||||
const renderer = createStubRenderer();
|
||||
const v = { isDestroyed: () => false };
|
||||
const unbind = bindRenderer(v, renderer);
|
||||
const r = createWorldAnnotationRenderer(v);
|
||||
t.after(() => {
|
||||
r.destroy();
|
||||
unbind();
|
||||
renderer.destroy();
|
||||
});
|
||||
const [, area, pin] = marks();
|
||||
r.add(area);
|
||||
r.add(pin);
|
||||
const setOf = (anno, kind) => anno._draw[kind].id;
|
||||
let hit = null;
|
||||
renderer.testing.scriptPicks(() => (hit ? [hit] : []));
|
||||
hit = { set: setOf(pin, 'points'), id: 'marker', surface: false };
|
||||
renderer.testing.pointer('dblclick', 10, 10);
|
||||
assert.ok(renderer.camera.followed, 'the pin is followed');
|
||||
hit = { set: setOf(area, 'shapes'), id: 'fill:0', surface: false };
|
||||
renderer.testing.pointer('dblclick', 10, 10);
|
||||
assert.equal(renderer.camera.followed, null, 'the area is zoomed to');
|
||||
hit = { set: setOf(pin, 'shapes'), id: 'ring', surface: false };
|
||||
renderer.testing.pointer('dblclick', 10, 10);
|
||||
assert.ok(renderer.camera.followed, 'its ring follows it too');
|
||||
r.remove(pin);
|
||||
assert.equal(renderer.camera.followed, null, 'removed: no longer followed');
|
||||
});
|
||||
@@ -315,7 +315,7 @@ function cameraHarness(layer = alprCamerasLayer) {
|
||||
},
|
||||
});
|
||||
let box = { south: 30.26, west: -97.75, north: 30.28, east: -97.73 };
|
||||
let click, dblclick, picked;
|
||||
let click, picked;
|
||||
const credits = new Set();
|
||||
const viewer = {
|
||||
creditDisplay: {
|
||||
@@ -344,15 +344,6 @@ function cameraHarness(layer = alprCamerasLayer) {
|
||||
// port follows on a tracking widget of the fake's.
|
||||
trackedEntityChanged: new Cesium.Event(),
|
||||
entities: {},
|
||||
// The viewer's stock double-click (its follow), which the input port
|
||||
// takes and runs before layers' own.
|
||||
screenSpaceEventHandler: {
|
||||
getInputAction: (type) =>
|
||||
type === Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK
|
||||
? () => {}
|
||||
: undefined,
|
||||
removeInputAction() {},
|
||||
},
|
||||
};
|
||||
const ports = fakeScenePorts(viewer);
|
||||
bindFakeCesiumCamera(viewer, ports);
|
||||
@@ -370,11 +361,6 @@ function cameraHarness(layer = alprCamerasLayer) {
|
||||
modifier === undefined
|
||||
)
|
||||
click = fn;
|
||||
if (
|
||||
type === Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK &&
|
||||
modifier === undefined
|
||||
)
|
||||
dblclick = fn;
|
||||
return setInput.call(this, fn, type, modifier);
|
||||
};
|
||||
try {
|
||||
@@ -423,11 +409,6 @@ function cameraHarness(layer = alprCamerasLayer) {
|
||||
picked = item ? { id: { set: icons().id, id: item.id } } : undefined;
|
||||
click({ position: new Cesium.Cartesian2() });
|
||||
},
|
||||
dblclick(id) {
|
||||
const item = typeof id === 'string' ? icons()?.items.get(id) : null;
|
||||
picked = item ? { id: { set: icons().id, id: item.id } } : undefined;
|
||||
dblclick({ position: new Cesium.Cartesian2() });
|
||||
},
|
||||
restore() {
|
||||
layer.destroy(viewer);
|
||||
Date.now = originals.now;
|
||||
@@ -1566,22 +1547,3 @@ test('ALPR display tags collapse controls and cap final text without erasing Uni
|
||||
assert.equal(record.cameraType, null);
|
||||
assert.equal(record.zone, 'traffic zone');
|
||||
});
|
||||
|
||||
test('a double-click follows a camera with its card until it is no longer shown, as its entity was', async () => {
|
||||
const { followedOf } = await import('./followed.js');
|
||||
const h = cameraHarness();
|
||||
try {
|
||||
await alprCamerasLayer.update();
|
||||
h.dblclick('alpr:42');
|
||||
const followed = followedOf(h.viewer);
|
||||
assert.ok(followed, 'the camera is followed');
|
||||
assert.equal(followed.key, 'alpr:42');
|
||||
assert.ok(followed.entity, 'through its entity record, for its card');
|
||||
h.setFetch(async () => cameraResponse([cameraNode(43)]));
|
||||
h.expire();
|
||||
await alprCamerasLayer.update();
|
||||
assert.equal(followedOf(h.viewer), null, 'gone: no longer followed');
|
||||
} finally {
|
||||
h.restore();
|
||||
}
|
||||
});
|
||||
@@ -2,8 +2,6 @@ import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import * as Cesium from 'cesium';
|
||||
import { bindFakeDraw } from '../testSupport/fakeDrawPort.mjs';
|
||||
import { bindRenderer } from '../render/rendererOf.js';
|
||||
import { createStubRenderer } from '../render/stub/index.js';
|
||||
import {
|
||||
DEFAULT_DIRECTIONS_MODE,
|
||||
DIRECTIONS_MODES,
|
||||
@@ -1027,69 +1025,3 @@ test('a placed endpoint draws its letter through the overlay, not as entity text
|
||||
directionsLayer.destroy(viewer);
|
||||
assert.ok(cleared.includes(DIRECTIONS_MARKER_OVERLAY_SOURCE_ID));
|
||||
});
|
||||
|
||||
test('a double-click follows an A or B marker and zooms to the route, as their entities did', async (t) => {
|
||||
directionsLayer = createApplicationDirectionsLayer({
|
||||
source: {
|
||||
getRoute: async () => ({
|
||||
ok: true,
|
||||
distanceM: route.distanceM,
|
||||
durationS: route.durationS,
|
||||
geometry: route.geometry,
|
||||
steps: route.steps,
|
||||
}),
|
||||
},
|
||||
});
|
||||
directionsLayer._setOverlayHostForTest({
|
||||
setEntries() {},
|
||||
setVisible() {},
|
||||
clearSource() {},
|
||||
});
|
||||
resetPointerOwnership();
|
||||
const renderer = createStubRenderer();
|
||||
const viewer = { isDestroyed: () => false };
|
||||
const unbind = bindRenderer(viewer, renderer);
|
||||
t.after(() => {
|
||||
directionsLayer.destroy(viewer);
|
||||
directionsLayer._setOverlayHostForTest(null);
|
||||
unbind();
|
||||
renderer.destroy();
|
||||
resetPointerOwnership();
|
||||
});
|
||||
directionsLayer.init(viewer);
|
||||
directionsLayer.enable(viewer);
|
||||
directionsLayer.placeEndpoint('a', A);
|
||||
directionsLayer.placeEndpoint('b', B);
|
||||
const started = Date.now();
|
||||
while (
|
||||
directionsLayer.getStats().status !== 'ready' &&
|
||||
Date.now() - started < 5000
|
||||
)
|
||||
await new Promise((resolve) => setTimeout(resolve, 5));
|
||||
const setOf = (suffix) =>
|
||||
renderer.testing.sets().find((id) => id.endsWith(suffix));
|
||||
let hit = null;
|
||||
renderer.testing.scriptPicks(() => (hit ? [hit] : []));
|
||||
const markersId = setOf(':markers');
|
||||
const routeId = setOf(':route');
|
||||
assert.ok(markersId && routeId, 'the sets are drawn');
|
||||
|
||||
hit = { set: markersId, id: 'directions:marker:B', surface: false };
|
||||
renderer.testing.pointer('dblclick', 10, 10);
|
||||
const followed = renderer.camera.followed;
|
||||
assert.ok(followed, 'B is followed');
|
||||
assert.equal(followed.key, 'directions:marker:B');
|
||||
const p = followed.position(0);
|
||||
const at = Cesium.Cartographic.fromCartesian(
|
||||
new Cesium.Cartesian3(p.x, p.y, p.z),
|
||||
);
|
||||
assert.ok(Math.abs(Cesium.Math.toDegrees(at.latitude) - B.lat) < 1e-9);
|
||||
|
||||
hit = { set: routeId, id: 'directions:route', surface: false };
|
||||
renderer.testing.pointer('dblclick', 10, 10);
|
||||
assert.equal(renderer.camera.followed, null, 'the route is zoomed to');
|
||||
renderer.testing.tick();
|
||||
const pose = renderer.camera.pose();
|
||||
assert.ok(Math.abs(pose.lat - (A.lat + B.lat) / 2) < 0.2, String(pose.lat));
|
||||
assert.ok(Math.abs(pose.lon - (A.lon + B.lon) / 2) < 0.2, String(pose.lon));
|
||||
});
|
||||
@@ -1,20 +1,17 @@
|
||||
/**
|
||||
* The drawn part of the file import: what `geoImportFeatures.js` read from
|
||||
* a file, drawn through the draw port in three sets (its pins, its lines,
|
||||
* its shapes), its ground pins placed on the ground in batches, followed on
|
||||
* a double-click like every drawn item, and its footprint read back.
|
||||
* its shapes), its ground pins placed on the ground in batches, and its
|
||||
* footprint read back.
|
||||
*/
|
||||
import {
|
||||
GeoImportError,
|
||||
MAX_IMPORT_ENTITIES,
|
||||
boundedImport,
|
||||
} from './geoImportShared.js';
|
||||
import { followOnDoubleClick } from './stockFollow.js';
|
||||
import { msg } from '../i18n/marker.js';
|
||||
import { fromDegrees, toLonLatH } from '../geo/ellipsoid.js';
|
||||
import { sphereFromPoints } from '../geo/sphere.js';
|
||||
import { heightsOf } from '../queries/heights.js';
|
||||
import { inputFor as defaultInputFor } from '../input/dispatcher.js';
|
||||
import {
|
||||
drawOf,
|
||||
findCamera,
|
||||
@@ -73,13 +70,8 @@ function turnedCorners({ west, south, east: eastEdge, north }, rotation = 0) {
|
||||
* `mount()`; `refreshGround()` places the ground pins first.
|
||||
* @param {object} viewer
|
||||
* @param {object[]} features From `readKmlFeatures` or `readGeoJsonFeatures`.
|
||||
* @param {{inputFor?: Function}} [options]
|
||||
*/
|
||||
export function createImportedDrawing(
|
||||
viewer,
|
||||
features,
|
||||
{ inputFor = defaultInputFor } = {},
|
||||
) {
|
||||
export function createImportedDrawing(viewer, features) {
|
||||
const prefix = `geo-import:${++drawings}`;
|
||||
const ids = {
|
||||
icons: `${prefix}:pins`,
|
||||
@@ -98,11 +90,9 @@ export function createImportedDrawing(
|
||||
offset: pin.mode === 'relative' ? pin.height : 0,
|
||||
groundHeight: undefined,
|
||||
}));
|
||||
const byId = new Map();
|
||||
let sets = null;
|
||||
/** The items last handed to each set, for inspection. */
|
||||
let drawn = { icons: [], lines: [], shapes: [] };
|
||||
let follow = null;
|
||||
let show = true;
|
||||
let destroyed = false;
|
||||
/** The surface last asked whether it is the bare ellipsoid, and its answer. */
|
||||
@@ -241,11 +231,6 @@ export function createImportedDrawing(
|
||||
}
|
||||
}
|
||||
|
||||
/** The points a feature is framed by, ECEF. */
|
||||
function framePoints(feature) {
|
||||
return footprintOf(feature).map(ecef);
|
||||
}
|
||||
|
||||
/** A feature's footprint, `[lon, lat, height]`. */
|
||||
function footprintOf(feature) {
|
||||
switch (feature.kind) {
|
||||
@@ -283,17 +268,14 @@ export function createImportedDrawing(
|
||||
// A pin with no icon draws nothing, but frames its file.
|
||||
if (!feature.image) return;
|
||||
const item = pinItem(feature, index);
|
||||
byId.set(`${ids.icons}\u0000${item.id}`, feature);
|
||||
icons.push(item);
|
||||
} else if (feature.kind === 'line') {
|
||||
const item = lineItem(feature, `l${index}`);
|
||||
if (!item) return;
|
||||
byId.set(`${ids.lines}\u0000${item.id}`, feature);
|
||||
lines.push(item);
|
||||
} else {
|
||||
const item = shapeItem(feature, `s${index}`);
|
||||
if (!item) return;
|
||||
byId.set(`${ids.shapes}\u0000${item.id}`, feature);
|
||||
shapes.push(item);
|
||||
}
|
||||
});
|
||||
@@ -323,19 +305,6 @@ export function createImportedDrawing(
|
||||
sets = null;
|
||||
}
|
||||
|
||||
/** What a double-click on one of these items follows or zooms to. */
|
||||
function targetFor(hit) {
|
||||
const feature = byId.get(`${hit.set}\u0000${hit.id}`);
|
||||
if (!feature) return null;
|
||||
if (feature.kind === 'pin')
|
||||
return {
|
||||
key: `${hit.set}:${hit.id}`,
|
||||
position: () => fromDegrees(feature.lon, feature.lat, feature.height),
|
||||
};
|
||||
const points = framePoints(feature);
|
||||
return points.length ? { zoomTo: sphereFromPoints(points) } : null;
|
||||
}
|
||||
|
||||
/** Move the drawn pins to where they now stand. */
|
||||
function redrawPins() {
|
||||
if (!sets?.icons) return;
|
||||
@@ -470,18 +439,6 @@ export function createImportedDrawing(
|
||||
mount() {
|
||||
if (destroyed || sets) return;
|
||||
draw();
|
||||
try {
|
||||
follow = followOnDoubleClick({
|
||||
viewer,
|
||||
inputFor,
|
||||
name: 'geo-import',
|
||||
enabled: () => show && !destroyed,
|
||||
targetFor,
|
||||
});
|
||||
} catch {
|
||||
// A renderer that takes no input has no double-click to follow on.
|
||||
follow = null;
|
||||
}
|
||||
},
|
||||
/** Place the ground pins again, and move the drawn ones. */
|
||||
async refreshGround(signal) {
|
||||
@@ -507,12 +464,8 @@ export function createImportedDrawing(
|
||||
destroy() {
|
||||
if (destroyed) return;
|
||||
destroyed = true;
|
||||
// A pin it follows is no longer there to follow.
|
||||
follow?.destroy();
|
||||
follow = null;
|
||||
disposeSets();
|
||||
drawn = { icons: [], lines: [], shapes: [] };
|
||||
byId.clear();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -65,30 +65,16 @@ const FEATURES = [
|
||||
},
|
||||
];
|
||||
|
||||
/** A drawing of `features` on a renderer double, with double-clicks it is handed. */
|
||||
/** A drawing of `features` on a renderer double. */
|
||||
function drawn(features = FEATURES) {
|
||||
const viewer = {};
|
||||
const ground = bindFakeGroundRenderer(viewer);
|
||||
const clicks = [];
|
||||
const input = {
|
||||
onPointer(type, fn) {
|
||||
if (type === 'dblclick') clicks.push(fn);
|
||||
return () => clicks.splice(clicks.indexOf(fn), 1);
|
||||
},
|
||||
stockEnabled: () => true,
|
||||
};
|
||||
const drawing = createImportedDrawing(viewer, features, {
|
||||
inputFor: () => input,
|
||||
});
|
||||
const drawing = createImportedDrawing(viewer, features);
|
||||
drawing.mount();
|
||||
const items = (kind) => [
|
||||
...ground.draw.set(drawing.ids[kind]).items.values(),
|
||||
];
|
||||
const doubleClick = (hit) => {
|
||||
ground.setPick(() => hit);
|
||||
for (const fn of clicks) fn({ position: { x: 1, y: 1 } });
|
||||
};
|
||||
return { ground, drawing, items, doubleClick, clicks };
|
||||
return { ground, drawing, items };
|
||||
}
|
||||
|
||||
test('pins draw as icons with the look their file gave them', (t) => {
|
||||
@@ -141,36 +127,22 @@ test('paths, polygons, walls and overlays draw as lines and shapes', (t) => {
|
||||
assert.equal(overlay.height, 'clampGround');
|
||||
});
|
||||
|
||||
test('a double-click follows a pin and zooms to a path, until the file goes', (t) => {
|
||||
const { ground, drawing, doubleClick, clicks } = drawn();
|
||||
test('destroying a file takes its sets with it', (t) => {
|
||||
const { ground, drawing } = drawn();
|
||||
t.after(ground.unbind);
|
||||
doubleClick({ set: drawing.ids.icons, id: 'p0' });
|
||||
const followed = ground.follows.at(-1);
|
||||
assert.equal(followed.key, `${drawing.ids.icons}:p0`);
|
||||
const at = toLonLatH(followed.position());
|
||||
assert.ok(Math.abs(at.lon - 1) < 1e-9 && Math.abs(at.lat - 2) < 1e-9);
|
||||
doubleClick({ set: drawing.ids.lines, id: 'l2' });
|
||||
assert.ok(ground.flights.at(-1).sphere.radius > 0, 'zoomed to the path');
|
||||
assert.equal(ground.follows.at(-1), null, 'which ends the follow');
|
||||
doubleClick({ set: 'someone-else', id: 'p0' });
|
||||
assert.equal(ground.flights.length, 1, 'other sets are not followed');
|
||||
doubleClick({ set: drawing.ids.icons, id: 'p0' });
|
||||
drawing.destroy();
|
||||
assert.equal(ground.follows.at(-1), null, 'a removed pin is not followed');
|
||||
assert.equal(clicks.length, 0);
|
||||
assert.equal(ground.liveSets().length, 0);
|
||||
assert.deepEqual(drawing.items(), { icons: [], lines: [], shapes: [] });
|
||||
});
|
||||
|
||||
test('hiding a file hides its sets and takes no double-clicks', (t) => {
|
||||
const { ground, drawing, doubleClick } = drawn();
|
||||
test('hiding a file hides its sets', (t) => {
|
||||
const { ground, drawing } = drawn();
|
||||
t.after(ground.unbind);
|
||||
drawing.show = false;
|
||||
for (const id of Object.values(drawing.ids))
|
||||
assert.equal(ground.draw.set(id).show, false);
|
||||
doubleClick({ set: drawing.ids.icons, id: 'p0' });
|
||||
assert.equal(ground.follows.length, 0);
|
||||
drawing.show = true;
|
||||
|
||||
assert.equal(ground.draw.set(drawing.ids.icons).show, true);
|
||||
});
|
||||
|
||||
|
||||
@@ -200,7 +200,6 @@ test('consumer build includes only infrastructure code and resolves assets under
|
||||
'color.js',
|
||||
'dispatcher.js',
|
||||
'ellipsoid.js',
|
||||
'frames.js',
|
||||
'frustum.js',
|
||||
'geojsonPins.js',
|
||||
'heights.js',
|
||||
@@ -217,7 +216,6 @@ test('consumer build includes only infrastructure code and resolves assets under
|
||||
'scenePick.js',
|
||||
'sensorPick.js',
|
||||
'sphere.js',
|
||||
'stockFollow.js',
|
||||
'styleStages.js',
|
||||
'vector.js',
|
||||
]);
|
||||
|
||||
@@ -132,8 +132,9 @@ test('pointer input, camera holds and the stock clicks go through the one dispat
|
||||
[
|
||||
/(?:screenSpaceEventHandler|stockHandler)\??\.removeInputAction\(/,
|
||||
'removes stock clicks instead of suppressStockClicks()',
|
||||
// It runs the stock clicks itself.
|
||||
['src/render/cesium/input.js'],
|
||||
// It runs the stock clicks itself; the viewer's factory drops the
|
||||
// stock double-click before any input port exists.
|
||||
['src/render/cesium/input.js', 'src/render/cesium/applicationViewer.js'],
|
||||
],
|
||||
];
|
||||
const walk = (dir) =>
|
||||
|
||||
@@ -21,7 +21,6 @@ import {
|
||||
} from '../sources/infrastructureData.js';
|
||||
import { createInfrastructureOverlayEntry } from './infrastructureOverlayEntry.js';
|
||||
import { createGeojsonPins } from './geojsonPins.js';
|
||||
import { followViewFrom } from './stockFollow.js';
|
||||
import { inputFor as defaultInputFor } from '../input/dispatcher.js';
|
||||
import {
|
||||
selectInfraLod,
|
||||
@@ -567,9 +566,6 @@ export function createLocalGeoJsonLayer(
|
||||
let _drawn = null;
|
||||
let _enabled = false;
|
||||
let _clickSubscription = null;
|
||||
let _dblclickSubscription = null;
|
||||
/** The follow a double-click started, while the camera keeps it. */
|
||||
let _follow = null;
|
||||
let _count = 0;
|
||||
/** @type {number|null} Timestamp of the last successful dataset load. */
|
||||
let _lastUpdate = null;
|
||||
@@ -713,9 +709,6 @@ export function createLocalGeoJsonLayer(
|
||||
_lastLodBudgetLimit = 0;
|
||||
_lodComputed = false;
|
||||
_lastLodProbeMs = Number.NEGATIVE_INFINITY;
|
||||
// Its parts go, and the follow of one with them, as a removed entity
|
||||
// stopped being followed.
|
||||
stopFollow(viewer);
|
||||
releaseDrawn();
|
||||
_overlayPublisher.hide();
|
||||
clearSelectedEntityContextForLayer(id);
|
||||
@@ -936,78 +929,6 @@ export function createLocalGeoJsonLayer(
|
||||
if (pins.length) drawn.sets.pins.upsert(pins);
|
||||
}
|
||||
|
||||
/**
|
||||
* Follow the part under `position`: a part with a stem by the centre of
|
||||
* all it draws, stem and all, as the default renderer followed the
|
||||
* loader's entity by its bounds, framed as that renderer framed an entity
|
||||
* it started following; a line, which had no position to
|
||||
* follow, is flown into view instead.
|
||||
*/
|
||||
function followAt(viewer, position) {
|
||||
const hit = findQuery(viewer)?.pick(position.x, position.y);
|
||||
if (!hit || !hit.set?.startsWith(`${setPrefix}:`)) return;
|
||||
const part = _drawn?.parts.get(hit.id);
|
||||
if (!part) return;
|
||||
const camera = findCamera(viewer);
|
||||
if (!camera) return;
|
||||
const points = framedPoints(part);
|
||||
if (!points.length) return;
|
||||
const record = part.carrier.record;
|
||||
try {
|
||||
if (!record) {
|
||||
// As the default renderer zoomed to an entity with no position: at
|
||||
// once, north up, pitched down 45°, at the range that fits it in
|
||||
// view (the camera port's defaults).
|
||||
const sphere = sphereFromPoints(points);
|
||||
// Following nothing then, as that zoom stopped any follow first.
|
||||
if (camera.followed) camera.follow(null);
|
||||
camera.flyToBounds(sphere, { durationS: 0 });
|
||||
return;
|
||||
}
|
||||
// The camera looks at the bounds' centre, kept where the stem now
|
||||
// stands, as the default renderer kept its entity's bounds.
|
||||
const outline = framedPoints(part, false);
|
||||
const centre = () =>
|
||||
sphereFromPoints([...outline, record.base, record.tip]).center;
|
||||
const target = {
|
||||
key: `${id}:${record.id}`,
|
||||
position: centre,
|
||||
frame: 'enu',
|
||||
viewFrom: followViewFrom(sphereFromPoints(points), record.tip, camera),
|
||||
};
|
||||
camera.follow(target);
|
||||
_follow = target;
|
||||
} catch (error) {
|
||||
// A camera that cannot follow (a viewer without entity tracking)
|
||||
// leaves the view where it is, as that viewer's double-click did.
|
||||
console.warn(`${id}: cannot follow`, error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* What the default renderer framed for a part: all it drew of it (but
|
||||
* for its stem, without `withStem`).
|
||||
*/
|
||||
function framedPoints(part, withStem = true) {
|
||||
const record = part.carrier.record;
|
||||
const points = [];
|
||||
if (part.kind === 'polygon')
|
||||
for (const { lon, lat, height } of part.rings[0])
|
||||
points.push(fromDegrees(lon, lat, height ?? 0));
|
||||
else if (part.kind === 'line')
|
||||
for (const [lon, lat] of part.coordinates)
|
||||
points.push(fromDegrees(lon, lat, 0));
|
||||
if (record && withStem) points.push(copy(record.base), copy(record.tip));
|
||||
return points;
|
||||
}
|
||||
|
||||
/** Stop a follow this layer started, if the camera still keeps it. */
|
||||
function stopFollow(viewer) {
|
||||
const camera = findCamera(viewer);
|
||||
if (_follow && camera?.followed === _follow) camera.follow(null);
|
||||
_follow = null;
|
||||
}
|
||||
|
||||
/** Fly to where a clicked part stands, holding camera input meanwhile. */
|
||||
function flyToPart(viewer, input, part) {
|
||||
const target = part.carrier.record
|
||||
@@ -1202,19 +1123,6 @@ export function createLocalGeoJsonLayer(
|
||||
flyToPart(viewer, input, part);
|
||||
});
|
||||
}
|
||||
// 3. Follow a part on a double-click, as the default renderer's
|
||||
// own double-click followed the loader's entities.
|
||||
if (!_dblclickSubscription) {
|
||||
const input = inputFor(viewer);
|
||||
_dblclickSubscription =
|
||||
input.onPointer?.('dblclick', (event) => {
|
||||
if (!_enabled || !_drawn) return;
|
||||
// The renderer's own double-click follow, off while a
|
||||
// tool holds it or on a renderer without one.
|
||||
if (input.stockEnabled?.('dblclickFollow') !== true) return;
|
||||
followAt(viewer, event.position);
|
||||
}) ?? null;
|
||||
}
|
||||
})();
|
||||
try {
|
||||
await _loadPromise;
|
||||
@@ -1536,8 +1444,6 @@ export function createLocalGeoJsonLayer(
|
||||
record.context.label === selectedHere.label,
|
||||
))
|
||||
: null;
|
||||
// A follow of an old part ends with it, as a removed entity's did.
|
||||
stopFollow(viewer);
|
||||
_drawn = built;
|
||||
_stemRecords = built.records;
|
||||
_count = built.count;
|
||||
@@ -1576,8 +1482,6 @@ export function createLocalGeoJsonLayer(
|
||||
removeEntityContextsForLayer(id);
|
||||
_clickSubscription?.();
|
||||
_clickSubscription = null;
|
||||
_dblclickSubscription?.();
|
||||
_dblclickSubscription = null;
|
||||
_overlayPublisher.destroy();
|
||||
_cachedFeatures = null;
|
||||
pinMaker.clear();
|
||||
|
||||
@@ -8,9 +8,6 @@ import { localGeoJsonServices } from '../app/localGeojsonServices.js';
|
||||
import { getContextStore } from './contextStore.js';
|
||||
import { readEntityRecord } from './entityRecords.js';
|
||||
import { bindFakeGroundRenderer } from '../testSupport/fakeGroundRenderer.mjs';
|
||||
import { distance, normalize, sub } from '../geo/vector.js';
|
||||
import { eastNorthUp, framePoint, inverseFrameVector } from '../geo/frames.js';
|
||||
|
||||
const feature = (id, geometry, properties = { name: `Feature ${id}` }) => ({
|
||||
type: 'Feature',
|
||||
id,
|
||||
@@ -82,8 +79,6 @@ async function enabledLayer(t, features) {
|
||||
eye: { lon: 0.005, lat: 0.005, height: 50_000 },
|
||||
});
|
||||
let click = null;
|
||||
let dblclick = null;
|
||||
const stock = { dblclickFollow: true };
|
||||
const holds = [];
|
||||
const layer = createLocalGeoJsonLayer(
|
||||
{
|
||||
@@ -103,14 +98,6 @@ async function enabledLayer(t, features) {
|
||||
holds.push(reason);
|
||||
return () => holds.push(`release:${reason}`);
|
||||
},
|
||||
onPointer: (type, handler) => {
|
||||
assert.equal(type, 'dblclick');
|
||||
dblclick = handler;
|
||||
return () => {
|
||||
dblclick = null;
|
||||
};
|
||||
},
|
||||
stockEnabled: (name) => stock[name] === true,
|
||||
}),
|
||||
},
|
||||
{
|
||||
@@ -134,10 +121,7 @@ async function enabledLayer(t, features) {
|
||||
viewer,
|
||||
fake,
|
||||
holds,
|
||||
stock,
|
||||
click: (event) => click?.(event),
|
||||
dblclick: (event) => dblclick?.(event),
|
||||
subscribed: () => dblclick !== null,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -410,99 +394,3 @@ test('a marker-symbol is stamped on its pin: a character as text, a longer one a
|
||||
assert.match(pins.get('missing').image.svg, /fill="rgba\(255,0,0,1\)"/);
|
||||
assert.deepEqual(pins.get('missing').image, pins.get('plain').image);
|
||||
});
|
||||
|
||||
test('a double-click follows a part as the default renderer followed its entity, and zooms to a line', async (t) => {
|
||||
const env = await enabledLayer(t, [
|
||||
feature('pt', { type: 'Point', coordinates: [0.002, 0.003] }),
|
||||
feature('l', {
|
||||
type: 'LineString',
|
||||
coordinates: [
|
||||
[0, 0],
|
||||
[0.01, 0],
|
||||
],
|
||||
}),
|
||||
]);
|
||||
const { fake } = env;
|
||||
const setOf = (role) => fake.set(role).spec.id;
|
||||
const stem = fake.set('stems').items.get('pt');
|
||||
const [base, tip] = stem.positions;
|
||||
let picked = null;
|
||||
fake.setPick((x, y) => (x === 7 && y === 9 ? picked : null));
|
||||
|
||||
// Nothing of this layer's under it: nothing happens.
|
||||
env.dblclick({ position: { x: 7, y: 9 } });
|
||||
picked = { set: 'someone-else', id: 'pt' };
|
||||
env.dblclick({ position: { x: 7, y: 9 } });
|
||||
assert.equal(fake.follows.length, 0);
|
||||
|
||||
// Its pin, its stem or its dot: the camera follows the stem's centre,
|
||||
// where the default renderer kept the entity's bounds. A tall view, so
|
||||
// its width is what fits the stem in.
|
||||
fake.view.aspectRatio = 0.5;
|
||||
picked = { set: setOf('pins'), id: 'pt' };
|
||||
env.dblclick({ position: { x: 7, y: 9 } });
|
||||
const target = fake.follows.at(-1);
|
||||
assert.equal(target.key, 'local-dams:pt');
|
||||
assert.equal(target.frame, 'enu');
|
||||
const center = {
|
||||
x: (base.x + tip.x) / 2,
|
||||
y: (base.y + tip.y) / 2,
|
||||
z: (base.z + tip.z) / 2,
|
||||
};
|
||||
assert.ok(distance(target.position(0), center) < 1e-6);
|
||||
// Looking at it north up, pitched down 45 degrees (a little more for a
|
||||
// tip above the ellipsoid), at the range that fits the stem in view.
|
||||
const eye = framePoint(eastNorthUp(center), target.viewFrom);
|
||||
const radius = distance(base, tip) / 2;
|
||||
const fit = radius / (0.5 * Math.tan(Math.PI / 6));
|
||||
assert.ok(Math.abs(distance(eye, center) - fit) < 1e-6);
|
||||
const look = inverseFrameVector(
|
||||
eastNorthUp(center),
|
||||
normalize(sub(center, eye)),
|
||||
);
|
||||
const factor = 2 - 1 / Math.max(1, Math.hypot(tip.x, tip.y, tip.z) / 6378137);
|
||||
assert.ok(factor > 1 + 1e-5, 'the tip stands above the ellipsoid');
|
||||
assert.ok(Math.abs(look.x) < 1e-9, 'heading north');
|
||||
assert.ok(look.y > 0);
|
||||
assert.ok(
|
||||
Math.abs(Math.asin(-look.z) - (Math.PI / 4) * factor) < 1e-9,
|
||||
'pitched down 45 degrees, steeper above the ground',
|
||||
);
|
||||
fake.view.aspectRatio = 1;
|
||||
|
||||
// Off while the renderer's own double-click follow is held off.
|
||||
env.stock.dblclickFollow = false;
|
||||
picked = { set: setOf('stems'), id: 'pt' };
|
||||
env.dblclick({ position: { x: 7, y: 9 } });
|
||||
assert.equal(fake.follows.length, 1);
|
||||
env.stock.dblclickFollow = true;
|
||||
|
||||
// A line had no position to follow: it is zoomed to instead, at once,
|
||||
// with the camera's default framing (north, 45 degrees down, fitted).
|
||||
picked = { set: setOf('lines'), id: 'l' };
|
||||
env.dblclick({ position: { x: 7, y: 9 } });
|
||||
const zoom = fake.flights.at(-1);
|
||||
assert.ok(zoom.sphere.radius > 500);
|
||||
assert.deepEqual(zoom.options, { durationS: 0 });
|
||||
// Stopping the follow first, as that zoom did.
|
||||
assert.equal(fake.follows.length, 2);
|
||||
assert.equal(fake.follows.at(-1), null);
|
||||
|
||||
// Disabled, the layer leaves a follow another started in place of its
|
||||
// own, and stops its own.
|
||||
picked = { set: setOf('dots'), id: 'pt' };
|
||||
env.dblclick({ position: { x: 7, y: 9 } });
|
||||
assert.equal(fake.follows.at(-1).key, 'local-dams:pt');
|
||||
const theirs = { key: 'theirs' };
|
||||
fake.follows.push(theirs);
|
||||
env.layer.disable(env.viewer);
|
||||
assert.equal(fake.follows.at(-1), theirs);
|
||||
await env.layer.enable(env.viewer);
|
||||
env.dblclick({ position: { x: 7, y: 9 } });
|
||||
assert.equal(fake.follows.at(-1).key, 'local-dams:pt');
|
||||
env.layer.disable(env.viewer);
|
||||
assert.equal(fake.follows.at(-1), null);
|
||||
// Destroyed, it stops listening.
|
||||
env.layer.destroy(env.viewer);
|
||||
assert.equal(env.subscribed(), false);
|
||||
});
|
||||
@@ -1,184 +0,0 @@
|
||||
/**
|
||||
* @module data/stockFollow
|
||||
* @description A double-click on a layer's drawn item follows it, as the
|
||||
* default renderer's own double-click followed the entities layers drew
|
||||
* before they drew through the draw port: an item with a position is
|
||||
* followed, framed as that renderer framed an entity it started following;
|
||||
* one without (a line) is zoomed to at once instead. It runs only while the
|
||||
* renderer's own double-click follow is on (a tool can hold it off).
|
||||
*/
|
||||
import { followOffsetFitting } from '../geo/frames.js';
|
||||
import { findCamera, findQuery } from '../render/rendererOf.js';
|
||||
import { entityFollowTarget } from './followed.js';
|
||||
import { positionToEcef } from '../geo/ellipsoid.js';
|
||||
import { sphereFromPoints } from '../geo/sphere.js';
|
||||
|
||||
/** A line's or shape's positions as ECEF points. */
|
||||
function pointsOf(positions) {
|
||||
if (!positions) return [];
|
||||
if (ArrayBuffer.isView(positions)) {
|
||||
const out = [];
|
||||
for (let i = 0; i + 2 < positions.length; i += 3)
|
||||
out.push({ x: positions[i], y: positions[i + 1], z: positions[i + 2] });
|
||||
return out;
|
||||
}
|
||||
return Array.from(positions, positionToEcef);
|
||||
}
|
||||
|
||||
/**
|
||||
* What a double-click on a drawn item does, as the default renderer did
|
||||
* for the entity a layer drew it as before: a point, an icon or a disc
|
||||
* (an entity with a position) is followed, framed to fit the disc; a line
|
||||
* or another shape (an entity without one) is zoomed to. For a layer's
|
||||
* `targetFor`, given the hit's set id and the item drawn there.
|
||||
* @param {string} set The hit's set id.
|
||||
* @param {object|null|undefined} item The draw item (draw.d.ts) the hit names.
|
||||
*/
|
||||
export function drawnItemTarget(set, item) {
|
||||
if (!item) return null;
|
||||
const key = `${set}:${item.id}`;
|
||||
if (item.pos) {
|
||||
const at = positionToEcef(item.pos);
|
||||
return { key, position: () => ({ ...at }) };
|
||||
}
|
||||
const geometry = item.geometry;
|
||||
if (geometry?.kind === 'ellipse') {
|
||||
const at = positionToEcef(geometry.center);
|
||||
const radius = Math.max(geometry.semiMajor, geometry.semiMinor);
|
||||
return {
|
||||
key,
|
||||
position: () => ({ ...at }),
|
||||
sphere: { center: at, radius: Number.isFinite(radius) ? radius : 0 },
|
||||
};
|
||||
}
|
||||
let points = pointsOf(item.positions);
|
||||
if (geometry?.kind === 'polygon') points = pointsOf(geometry.rings?.[0]);
|
||||
else if (geometry?.kind === 'wall') points = pointsOf(geometry.positions);
|
||||
else if (geometry?.kind === 'rectangle') {
|
||||
const { west, south, east, north } = geometry.rect;
|
||||
points = pointsOf([
|
||||
{ lon: west, lat: south },
|
||||
{ lon: east, lat: south },
|
||||
{ lon: east, lat: north },
|
||||
{ lon: west, lat: north },
|
||||
]);
|
||||
}
|
||||
return points.length ? { zoomTo: sphereFromPoints(points) } : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Where the camera frames a part it starts following: `followOffsetFitting`
|
||||
* with the camera port's field of view and zoom limits.
|
||||
* @param {{center: {x: number, y: number, z: number}, radius: number}} sphere
|
||||
* @param {{x: number, y: number, z: number}} at
|
||||
* @param {object} camera The camera port.
|
||||
*/
|
||||
export function followViewFrom(sphere, at, camera) {
|
||||
const pose = camera.pose?.();
|
||||
const { minDistance, maxDistance } = camera.controls ?? {};
|
||||
return followOffsetFitting(sphere, at, {
|
||||
fovy: pose?.fovy,
|
||||
aspectRatio: pose?.aspectRatio,
|
||||
minDistance,
|
||||
maxDistance,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Follow (or zoom to) a layer's item on a double-click.
|
||||
* @param {object} options
|
||||
* @param {object} options.viewer
|
||||
* @param {(viewer: object) => object} options.inputFor The click dispatcher.
|
||||
* @param {string} options.name The layer, for warnings.
|
||||
* @param {() => boolean} options.enabled Whether the layer takes clicks now.
|
||||
* @param {(hit: import('../render/contract/query').Hit) =>
|
||||
* ({key: string, position: () => ({x: number, y: number, z: number}|null),
|
||||
* sphere?: {center: object, radius: number}, entity?: object}
|
||||
* | {zoomTo: {center: object, radius: number}}
|
||||
* | null)} options.targetFor What a hit on one of the layer's items is
|
||||
* followed by (`key`, its live `position`, the bounds it is framed by,
|
||||
* radius 0 by default, and the holder whose entity record shows it, as
|
||||
* `entityFollowTarget` reads one), or zoomed to (`zoomTo`); null for
|
||||
* anything else.
|
||||
* @returns {{readonly following: object|null, retain(drawn: (key: string) => boolean): void,
|
||||
* stop(): void, destroy(): void}}
|
||||
*/
|
||||
export function followOnDoubleClick({
|
||||
viewer,
|
||||
inputFor,
|
||||
name,
|
||||
enabled,
|
||||
targetFor,
|
||||
}) {
|
||||
const input = inputFor(viewer);
|
||||
/** The follow a double-click started, while the camera keeps it. */
|
||||
let follow = null;
|
||||
const off =
|
||||
input.onPointer?.('dblclick', (event) => {
|
||||
if (!enabled()) return;
|
||||
// The renderer's own double-click follow, off while a tool holds it
|
||||
// or on a renderer without one.
|
||||
if (input.stockEnabled?.('dblclickFollow') !== true) return;
|
||||
const hit = findQuery(viewer)?.pick(event.position.x, event.position.y);
|
||||
const found = hit && !hit.surface ? targetFor(hit) : null;
|
||||
if (!found) return;
|
||||
const camera = findCamera(viewer);
|
||||
if (!camera) return;
|
||||
try {
|
||||
if (found.zoomTo) {
|
||||
// As the default renderer zoomed to an entity with no position:
|
||||
// at once, north up, pitched down 45°, at the range that fits it
|
||||
// in view. Following nothing then, as that zoom stopped any
|
||||
// follow first.
|
||||
if (camera.followed) camera.follow(null);
|
||||
camera.flyToBounds(found.zoomTo, { durationS: 0 });
|
||||
return;
|
||||
}
|
||||
const at = found.position();
|
||||
if (!at) return;
|
||||
const fields = {
|
||||
key: found.key,
|
||||
position: found.position,
|
||||
frame: 'enu',
|
||||
viewFrom: followViewFrom(
|
||||
found.sphere ?? { center: at, radius: 0 },
|
||||
at,
|
||||
camera,
|
||||
),
|
||||
};
|
||||
const target = found.entity
|
||||
? entityFollowTarget(found.entity, fields)
|
||||
: fields;
|
||||
camera.follow(target);
|
||||
follow = target;
|
||||
} catch (error) {
|
||||
// A camera that cannot follow leaves the view where it is, as a
|
||||
// viewer without entity tracking did.
|
||||
console.warn(`${name}: cannot follow`, error);
|
||||
}
|
||||
}) ?? null;
|
||||
return {
|
||||
get following() {
|
||||
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() {
|
||||
const camera = findCamera(viewer);
|
||||
if (follow && camera?.followed === follow) camera.follow(null);
|
||||
follow = null;
|
||||
},
|
||||
destroy() {
|
||||
this.stop();
|
||||
off?.();
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -1,168 +0,0 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { followOnDoubleClick, followViewFrom } from './stockFollow.js';
|
||||
import { bindRenderer } from '../render/rendererOf.js';
|
||||
import { WGS84 } from '../geo/ellipsoid.js';
|
||||
|
||||
/** A viewer whose renderer answers picks with `hit` and records the camera. */
|
||||
function scene({ hit, stock = true, enabled = true }) {
|
||||
const viewer = {};
|
||||
const handlers = new Map();
|
||||
const calls = [];
|
||||
const camera = {
|
||||
followed: null,
|
||||
controls: { minDistance: 0, maxDistance: Infinity },
|
||||
pose: () => ({ fovy: Math.PI / 3, aspectRatio: 2 }),
|
||||
follow(target) {
|
||||
calls.push(['follow', target]);
|
||||
camera.followed = target;
|
||||
},
|
||||
flyToBounds(sphere, options) {
|
||||
calls.push(['flyToBounds', sphere, options]);
|
||||
},
|
||||
};
|
||||
const unbind = bindRenderer(viewer, {
|
||||
camera,
|
||||
query: { pick: () => hit },
|
||||
});
|
||||
const input = {
|
||||
onPointer(type, handler) {
|
||||
handlers.set(type, handler);
|
||||
return () => handlers.delete(type);
|
||||
},
|
||||
stockEnabled: (name) => name === 'dblclickFollow' && stock,
|
||||
};
|
||||
const at = { x: WGS84.radii.x, y: 0, z: 0 };
|
||||
const follow = followOnDoubleClick({
|
||||
viewer,
|
||||
inputFor: () => input,
|
||||
name: 'test-layer',
|
||||
enabled: () => enabled,
|
||||
targetFor: (picked) =>
|
||||
picked.id === 'point'
|
||||
? { key: 'layer:point', position: () => at }
|
||||
: picked.id === 'line'
|
||||
? { zoomTo: { center: at, radius: 50 } }
|
||||
: null,
|
||||
});
|
||||
const dblclick = () =>
|
||||
handlers.get('dblclick')?.({ position: { x: 1, y: 2 } });
|
||||
return { follow, camera, calls, dblclick, handlers, unbind };
|
||||
}
|
||||
|
||||
test('a double-click follows a point, framed as the default renderer framed an entity', () => {
|
||||
const s = scene({ hit: { set: 'layer', id: 'point', surface: false } });
|
||||
s.dblclick();
|
||||
const [[kind, target]] = s.calls;
|
||||
assert.equal(kind, 'follow');
|
||||
assert.equal(target.key, 'layer:point');
|
||||
assert.equal(target.frame, 'enu');
|
||||
// No size: the minimum fit range, 45 degrees down on the ground.
|
||||
const range = Math.hypot(
|
||||
target.viewFrom.x,
|
||||
target.viewFrom.y,
|
||||
target.viewFrom.z,
|
||||
);
|
||||
assert.ok(Math.abs(range - 100) < 1e-6);
|
||||
assert.ok(Math.abs(target.viewFrom.z + target.viewFrom.y) < 1e-6);
|
||||
assert.equal(s.follow.following, target);
|
||||
// Stopping ends only the follow it started.
|
||||
s.follow.stop();
|
||||
assert.equal(s.camera.followed, null);
|
||||
s.follow.destroy();
|
||||
assert.equal(s.handlers.size, 0);
|
||||
s.unbind();
|
||||
});
|
||||
|
||||
test('a double-click on a line zooms to it at once, following nothing', () => {
|
||||
const s = scene({ hit: { set: 'layer', id: 'line', surface: false } });
|
||||
s.camera.followed = { key: 'other' };
|
||||
s.dblclick();
|
||||
assert.deepEqual(
|
||||
s.calls.map(([kind]) => kind),
|
||||
['follow', 'flyToBounds'],
|
||||
);
|
||||
assert.equal(s.calls[0][1], null);
|
||||
assert.deepEqual(s.calls[1][2], { durationS: 0 });
|
||||
s.follow.destroy();
|
||||
s.unbind();
|
||||
});
|
||||
|
||||
test('no follow while the stock double-click is held off, the layer is off, or the pick is not its own', () => {
|
||||
for (const options of [
|
||||
{ hit: { id: 'point', surface: false }, stock: false },
|
||||
{ hit: { id: 'point', surface: false }, enabled: false },
|
||||
{ hit: { id: 'other', surface: false } },
|
||||
{ hit: { surface: true } },
|
||||
{ hit: null },
|
||||
]) {
|
||||
const s = scene(options);
|
||||
s.dblclick();
|
||||
assert.deepEqual(s.calls, []);
|
||||
s.follow.destroy();
|
||||
s.unbind();
|
||||
}
|
||||
});
|
||||
|
||||
test('the frame view fits a sphere and steepens far from the ground', () => {
|
||||
const camera = { pose: () => ({ fovy: Math.PI / 2, aspectRatio: 1 }) };
|
||||
const ground = { x: WGS84.radii.x, y: 0, z: 0 };
|
||||
const near = followViewFrom({ center: ground, radius: 1000 }, ground, camera);
|
||||
assert.ok(Math.abs(Math.hypot(near.x, near.y, near.z) - 1000) < 1e-6);
|
||||
const high = { x: WGS84.radii.x * 2, y: 0, z: 0 };
|
||||
const far = followViewFrom({ center: high, radius: 0 }, high, camera);
|
||||
// Looking down 45 degrees times 1.5 at twice the radius: the eye that
|
||||
// far above, south of the point.
|
||||
const elevation = Math.atan2(far.z, Math.hypot(far.x, far.y));
|
||||
assert.ok(Math.abs(elevation - (Math.PI / 4) * 1.5) < 1e-9);
|
||||
assert.ok(far.y < 0);
|
||||
});
|
||||
|
||||
test('a drawn item is followed as an entity with a position was, or zoomed to as one without', async () => {
|
||||
const { drawnItemTarget } = await import('./stockFollow.js');
|
||||
const near = (a, b) => Math.hypot(a.x - b.x, a.y - b.y, a.z - b.z) < 1e-6;
|
||||
const { fromDegrees } = await import('../geo/ellipsoid.js');
|
||||
const point = drawnItemTarget('s', { id: 'p', pos: { lon: 10, lat: 20 } });
|
||||
assert.equal(point.key, 's:p');
|
||||
assert.ok(near(point.position(), fromDegrees(10, 20, 0)));
|
||||
const disc = drawnItemTarget('s', {
|
||||
id: 'd',
|
||||
geometry: {
|
||||
kind: 'ellipse',
|
||||
center: { lon: 10, lat: 20 },
|
||||
semiMajor: 4000,
|
||||
semiMinor: 3000,
|
||||
},
|
||||
});
|
||||
assert.equal(disc.sphere.radius, 4000);
|
||||
assert.ok(near(disc.position(), fromDegrees(10, 20, 0)));
|
||||
const flat = new Float64Array([
|
||||
...Object.values(fromDegrees(0, 0, 0)),
|
||||
...Object.values(fromDegrees(2, 0, 0)),
|
||||
]);
|
||||
const line = drawnItemTarget('s', { id: 'l', positions: flat });
|
||||
assert.ok(line.zoomTo.radius > 100_000 && !line.position);
|
||||
const polygon = drawnItemTarget('s', {
|
||||
id: 'g',
|
||||
geometry: {
|
||||
kind: 'polygon',
|
||||
rings: [
|
||||
[
|
||||
{ lon: 0, lat: 0 },
|
||||
{ lon: 1, lat: 0 },
|
||||
{ lon: 1, lat: 1 },
|
||||
],
|
||||
],
|
||||
},
|
||||
});
|
||||
assert.ok(polygon.zoomTo.radius > 50_000);
|
||||
const rect = drawnItemTarget('s', {
|
||||
id: 'r',
|
||||
geometry: {
|
||||
kind: 'rectangle',
|
||||
rect: { west: 0, south: 0, east: 1, north: 1 },
|
||||
},
|
||||
});
|
||||
assert.ok(rect.zoomTo.radius > 50_000);
|
||||
assert.equal(drawnItemTarget('s', null), null);
|
||||
});
|
||||
@@ -564,8 +564,6 @@ function createCableHarness({
|
||||
// event-dirty behavior with no wall-clock coupling.
|
||||
let clockMs = 0;
|
||||
let clickHandler = null;
|
||||
let doubleHandler = null;
|
||||
let picked = null;
|
||||
const layer = createTeleGeographySubmarineCableLayer({
|
||||
overlayHost: {
|
||||
setVisible: (...args) => hostCalls.push(['visible', ...args]),
|
||||
@@ -579,14 +577,6 @@ function createCableHarness({
|
||||
if (clickHandler === fn) clickHandler = null;
|
||||
};
|
||||
},
|
||||
onPointer: (type, fn) => {
|
||||
if (type !== 'dblclick') return () => {};
|
||||
doubleHandler = fn;
|
||||
return () => {
|
||||
if (doubleHandler === fn) doubleHandler = null;
|
||||
};
|
||||
},
|
||||
stockEnabled: (name) => name === 'dblclickFollow',
|
||||
}),
|
||||
source,
|
||||
mapStackEventTarget,
|
||||
@@ -617,13 +607,8 @@ function createCableHarness({
|
||||
camera.port.cancelFlight = () => flights.push('cancel');
|
||||
camera.port.flyTo = (destination, options) =>
|
||||
flights.push({ destination, options });
|
||||
camera.port.followed = null;
|
||||
camera.port.follow = (target) => (camera.port.followed = target ?? null);
|
||||
const zooms = [];
|
||||
camera.port.flyToBounds = (sphere) => zooms.push(sphere);
|
||||
const { draw } = bindFakeDraw(viewer, {
|
||||
camera: camera.port,
|
||||
query: { pick: () => picked },
|
||||
frame: fakeSceneFrame(viewer),
|
||||
});
|
||||
layer.init(viewer);
|
||||
@@ -652,13 +637,6 @@ function createCableHarness({
|
||||
click(drawHit) {
|
||||
clickHandler?.({ drawHit, pick: null });
|
||||
},
|
||||
/** A double-click over a drawn item; what the camera then does. */
|
||||
dblclick(hit) {
|
||||
picked = hit;
|
||||
doubleHandler?.({ position: { x: 1, y: 1 } });
|
||||
},
|
||||
followed: () => camera.port.followed,
|
||||
zooms,
|
||||
async load() {
|
||||
layer.enable(viewer);
|
||||
source.releaseAll?.();
|
||||
@@ -1362,26 +1340,3 @@ test('every bundled cable segment is drawn with its source feature', async () =>
|
||||
assert.equal(env.set('references').items.size, features.length);
|
||||
env.layer.destroy();
|
||||
});
|
||||
|
||||
test('a double-click follows a landing point or reference and zooms to a cable, as their entities did', async () => {
|
||||
const env = await loadedHarness();
|
||||
const [lineId] = env.set('lines').items.keys();
|
||||
const [pinId] = env.set('pins').items.keys();
|
||||
const [cableRef] = env.set('references').items.keys();
|
||||
const surface = { surface: false };
|
||||
env.dblclick({ set: env.set('pins').spec.id, id: pinId, ...surface });
|
||||
assert.ok(env.followed(), 'a landing point is followed');
|
||||
env.dblclick({ set: env.set('stems').spec.id, id: cableRef, ...surface });
|
||||
assert.equal(
|
||||
env.followed().key,
|
||||
`${env.set('references').spec.id}:${cableRef}`,
|
||||
'a stem follows its reference, one entity before',
|
||||
);
|
||||
env.dblclick({ set: env.set('lines').spec.id, id: lineId, ...surface });
|
||||
assert.equal(env.followed(), null, 'a cable is zoomed to');
|
||||
assert.ok(env.zooms.at(-1)?.radius > 0);
|
||||
env.dblclick({ set: env.set('pins').spec.id, id: pinId, ...surface });
|
||||
env.layer.disable();
|
||||
assert.equal(env.followed(), null, 'hidden, its entities went: no follow');
|
||||
env.layer.destroy();
|
||||
});
|
||||
+10
-71
@@ -27,9 +27,8 @@
|
||||
* changing settle into static geometry.
|
||||
*/
|
||||
import { cssColor } from '../render/color.js';
|
||||
import { findDraw, findInput } from '../render/rendererOf.js';
|
||||
import { findDraw } from '../render/rendererOf.js';
|
||||
import { registerPickOwner } from './pickRegistry.js';
|
||||
import { drawnItemTarget, followOnDoubleClick } from './stockFollow.js';
|
||||
|
||||
// Trail lines are pickable (a click on one must not fall through to the
|
||||
// ground under it). A trail hugs its aircraft, so an unclaimed pick would
|
||||
@@ -44,54 +43,6 @@ registerPickOwner('trails', (pickedId) =>
|
||||
/** @type {number} Uniquifier for trail set and line ids. */
|
||||
let _trailSeq = 0;
|
||||
|
||||
/**
|
||||
* Per viewer, its trails' drawn lines by set id and the one double-click
|
||||
* handler they share: a double-click on a trail line zooms to it, as the
|
||||
* default renderer zoomed to the polyline entity a trail was drawn as.
|
||||
* @type {WeakMap<object, {lines: Map<string, (id: string) => object|null>,
|
||||
* follow: object|null}>}
|
||||
*/
|
||||
const doubleClicks = new WeakMap();
|
||||
|
||||
/**
|
||||
* Take part in `viewer`'s trail double-click with the set `setId`, whose
|
||||
* line by id `lineFor` gives. Returns how to leave it.
|
||||
*/
|
||||
function joinDoubleClick(viewer, setId, lineFor) {
|
||||
let shared = doubleClicks.get(viewer);
|
||||
if (!shared) {
|
||||
const lines = new Map();
|
||||
// A scene that takes no input (or a headless one, with no page to take
|
||||
// it from) has no double-click.
|
||||
let input = null;
|
||||
try {
|
||||
input = findInput(viewer);
|
||||
} catch {
|
||||
input = null;
|
||||
}
|
||||
shared = {
|
||||
lines,
|
||||
follow: input
|
||||
? followOnDoubleClick({
|
||||
viewer,
|
||||
inputFor: () => input,
|
||||
name: 'trails',
|
||||
enabled: () => true,
|
||||
targetFor: (hit) =>
|
||||
drawnItemTarget(hit.set, lines.get(hit.set)?.(hit.id)),
|
||||
})
|
||||
: null,
|
||||
};
|
||||
doubleClicks.set(viewer, shared);
|
||||
}
|
||||
shared.lines.set(setId, lineFor);
|
||||
return () => {
|
||||
if (!shared.lines.delete(setId) || shared.lines.size) return;
|
||||
shared.follow?.destroy();
|
||||
if (doubleClicks.get(viewer) === shared) doubleClicks.delete(viewer);
|
||||
};
|
||||
}
|
||||
|
||||
/** @constant {number} Alpha where the trail passes the depth test. */
|
||||
const TRAIL_ALPHA = 0.85;
|
||||
/** @constant {number} Alpha where the trail is behind/below scene geometry —
|
||||
@@ -182,21 +133,11 @@ export function createTrail(viewer, { color, width = 2.5 }) {
|
||||
* the position objects it was drawn from, which never change. */
|
||||
let chunks = [];
|
||||
let chunkSeq = 0;
|
||||
/** Leaves the viewer's trail double-click, once the set is drawn. */
|
||||
let leaveDoubleClick = null;
|
||||
|
||||
/** The line drawn under `id`, for a double-click to zoom to. */
|
||||
function lineFor(id) {
|
||||
const shown = drawn.get(id)?.item;
|
||||
if (shown) return shown.show === false ? null : shown;
|
||||
return chunks.find((chunk) => chunk.id === id)?.item ?? null;
|
||||
}
|
||||
|
||||
function ensureSet() {
|
||||
if (set || destroyed || !viewer || viewer.isDestroyed?.()) return set;
|
||||
set =
|
||||
findDraw(viewer)?.lines({ id: `trail:${seq}`, show: visible }) ?? null;
|
||||
if (set) leaveDoubleClick = joinDoubleClick(viewer, set.id, lineFor);
|
||||
return set;
|
||||
}
|
||||
|
||||
@@ -282,16 +223,16 @@ export function createTrail(viewer, { color, width = 2.5 }) {
|
||||
}
|
||||
}
|
||||
const positions = seg.slice(i, end + 1);
|
||||
const id = `${bodyId}:${++chunkSeq}`;
|
||||
const item = lineItem(
|
||||
id,
|
||||
positions.map(plain),
|
||||
TRAIL_ALPHA,
|
||||
TRAIL_OCCLUDED_ALPHA,
|
||||
);
|
||||
const chunk = { id, positions, item };
|
||||
const chunk = { id: `${bodyId}:${++chunkSeq}`, positions };
|
||||
next.push(chunk);
|
||||
added.push(item);
|
||||
added.push(
|
||||
lineItem(
|
||||
chunk.id,
|
||||
positions.map(plain),
|
||||
TRAIL_ALPHA,
|
||||
TRAIL_OCCLUDED_ALPHA,
|
||||
),
|
||||
);
|
||||
i = end;
|
||||
}
|
||||
});
|
||||
@@ -377,8 +318,6 @@ export function createTrail(viewer, { color, width = 2.5 }) {
|
||||
/** Remove the trail permanently (layer disable/teardown). */
|
||||
destroy() {
|
||||
destroyed = true;
|
||||
leaveDoubleClick?.();
|
||||
leaveDoubleClick = null;
|
||||
try {
|
||||
set?.dispose();
|
||||
} catch {
|
||||
|
||||
@@ -3,8 +3,6 @@ import assert from 'node:assert/strict';
|
||||
import { bindFakeDraw } from '../testSupport/fakeDrawPort.mjs';
|
||||
import { CHUNK_POINTS, createTrail } from './trailRenderer.js';
|
||||
import { findPickOwner } from './pickRegistry.js';
|
||||
import { bindFakeGroundRenderer } from '../testSupport/fakeGroundRenderer.mjs';
|
||||
import { fromDegrees } from '../geo/ellipsoid.js';
|
||||
|
||||
function viewerWithDraw(t) {
|
||||
const viewer = { isDestroyed: () => false };
|
||||
@@ -231,56 +229,3 @@ test('clearing a segmented trail lets every line go', (t) => {
|
||||
trail.setSegments([points(4)]);
|
||||
assert.equal(historyLines(set).length, 1, 'drawn again after a clear');
|
||||
});
|
||||
|
||||
test('a double-click on a trail line zooms to that line, as to the polyline entity it was', (t) => {
|
||||
const viewer = { isDestroyed: () => false };
|
||||
const fake = bindFakeGroundRenderer(viewer);
|
||||
t.after(fake.unbind);
|
||||
let dblclick = null;
|
||||
const stock = { dblclickFollow: true };
|
||||
fake.renderer.input = {
|
||||
onPointer(type, handler) {
|
||||
assert.equal(type, 'dblclick');
|
||||
dblclick = handler;
|
||||
return () => {
|
||||
dblclick = null;
|
||||
};
|
||||
},
|
||||
stockEnabled: (name) => stock[name] === true,
|
||||
};
|
||||
const trail = createTrail(viewer, { color: '#00d4ff' });
|
||||
const a = fromDegrees(0, 0, 1000);
|
||||
const b = fromDegrees(0.1, 0, 1000);
|
||||
trail.setPositions([a, b]);
|
||||
const set = fake.liveSets().find((s) => s.spec.id.startsWith('trail:'));
|
||||
const [line] = set.items.values();
|
||||
fake.setPick(() => ({ set: set.spec.id, id: line.id }));
|
||||
const at = { position: { x: 1, y: 2 } };
|
||||
|
||||
dblclick(at);
|
||||
assert.equal(fake.flights.length, 1, 'zoomed at once');
|
||||
const { sphere, options } = fake.flights[0];
|
||||
assert.equal(options.durationS, 0);
|
||||
const mid = { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2, z: (a.z + b.z) / 2 };
|
||||
assert.ok(
|
||||
Math.hypot(
|
||||
sphere.center.x - mid.x,
|
||||
sphere.center.y - mid.y,
|
||||
sphere.center.z - mid.z,
|
||||
) < 1,
|
||||
);
|
||||
assert.equal(fake.follows.length, 0, 'nothing followed');
|
||||
|
||||
// Held off (a tool holds the stock follow), a hidden trail line, or
|
||||
// another layer's hit: nothing.
|
||||
stock.dblclickFollow = false;
|
||||
dblclick(at);
|
||||
stock.dblclickFollow = true;
|
||||
fake.setPick(() => ({ set: 'other', id: line.id }));
|
||||
dblclick(at);
|
||||
assert.equal(fake.flights.length, 1);
|
||||
|
||||
// The last trail gone, the viewer's double-click is let go.
|
||||
trail.destroy();
|
||||
assert.equal(dblclick, null);
|
||||
});
|
||||
@@ -1,11 +1,6 @@
|
||||
import { fromDegrees } from '../../geo/ellipsoid.js';
|
||||
import { cssColor } from '../../render/color.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 { drawOf, findCamera } from '../../render/rendererOf.js';
|
||||
import { msg, t, tn } from '../../i18n/index.js';
|
||||
import { translateFeedError } from '../../ui/statusText.js';
|
||||
import {
|
||||
@@ -39,11 +34,7 @@ function withAlpha(css, alpha) {
|
||||
}
|
||||
|
||||
/** Own one air-quality display, its refresh lifecycle, and its readout card. */
|
||||
export function createAirQualityLayer({
|
||||
source,
|
||||
overlayHost,
|
||||
inputFor = defaultInputFor,
|
||||
} = {}) {
|
||||
export function createAirQualityLayer({ source, overlayHost } = {}) {
|
||||
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');
|
||||
@@ -55,9 +46,6 @@ export function createAirQualityLayer({
|
||||
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?.();
|
||||
@@ -80,22 +68,6 @@ export function createAirQualityLayer({
|
||||
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;
|
||||
@@ -116,7 +88,6 @@ export function createAirQualityLayer({
|
||||
_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);
|
||||
@@ -199,11 +170,6 @@ export function createAirQualityLayer({
|
||||
);
|
||||
}
|
||||
_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,
|
||||
@@ -221,9 +187,6 @@ export function createAirQualityLayer({
|
||||
_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,35 +322,3 @@ 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');
|
||||
});
|
||||
@@ -70,8 +70,6 @@ export function createAlprCamerasLayer({ source, services } = {}) {
|
||||
postRenderRemove: null,
|
||||
lastAnchorSampleAt: 0,
|
||||
clickSubscription: null,
|
||||
/** The follow a double-click on a camera started, while installed. */
|
||||
stockFollow: null,
|
||||
debounceTimer: null,
|
||||
/** Snapped box of the last successful query; a view still inside it reuses its records. */
|
||||
lastQueryBox: null,
|
||||
@@ -346,8 +344,6 @@ export function createAlprCamerasLayer({ source, services } = {}) {
|
||||
state.postRenderRemove = null;
|
||||
state.clickSubscription?.();
|
||||
state.clickSubscription = null;
|
||||
state.stockFollow?.destroy();
|
||||
state.stockFollow = null;
|
||||
clearRendered();
|
||||
state.markers.dispose();
|
||||
state.credit = null;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { isFollowing } from '../../data/followed.js';
|
||||
import { inputFor } from '../../input/dispatcher.js';
|
||||
import { followOnDoubleClick } from '../../data/stockFollow.js';
|
||||
import { distance, fromDegrees, toLonLatH } from '../../geo/index.js';
|
||||
import {
|
||||
LAYER_ID,
|
||||
@@ -323,7 +322,6 @@ export function createAlprPresentation({ state, services, source }) {
|
||||
visibleRecords = [];
|
||||
clampedMarkers.clear();
|
||||
markers.clear();
|
||||
state.stockFollow?.stop();
|
||||
removeEntityContextsForLayer(LAYER_ID);
|
||||
}
|
||||
|
||||
@@ -378,8 +376,6 @@ export function createAlprPresentation({ state, services, source }) {
|
||||
if (!visibleIds.has(carrier.id)) gone.push(carrier.id);
|
||||
if (gone.length) {
|
||||
markers.remove(gone);
|
||||
// A camera no longer shown takes its follow with it.
|
||||
state.stockFollow?.retain((key) => Boolean(markers.get(key)));
|
||||
for (const id of gone) clampedMarkers.delete(id);
|
||||
changed = true;
|
||||
}
|
||||
@@ -598,26 +594,6 @@ export function createAlprPresentation({ state, services, source }) {
|
||||
selectRecord(id);
|
||||
else if (state.selectedId) clearSelection();
|
||||
});
|
||||
// A double-click follows a camera, its card shown, as the default
|
||||
// renderer followed its entity.
|
||||
state.stockFollow = followOnDoubleClick({
|
||||
viewer,
|
||||
inputFor,
|
||||
name: LAYER_ID,
|
||||
enabled: () => state.enabled,
|
||||
targetFor: (hit) => {
|
||||
const carrier = hit.set === markers.icons?.id && markers.get(hit.id);
|
||||
if (!carrier) return null;
|
||||
return {
|
||||
key: carrier.id,
|
||||
position: () => {
|
||||
const at = alprIconPosition(carrier);
|
||||
return at ? { ...at } : null;
|
||||
},
|
||||
entity: carrier,
|
||||
};
|
||||
},
|
||||
});
|
||||
}
|
||||
return {
|
||||
initOverlay: () => overlay.init(),
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { t } from '../../i18n/index.js';
|
||||
import { inputFor } from '../../input/dispatcher.js';
|
||||
import { followOnDoubleClick } from '../../data/stockFollow.js';
|
||||
import {
|
||||
BIKESHARE_SELECTED_OVERLAY_SOURCE_ID,
|
||||
BIKESHARE_SELECTED_OVERLAY_SOURCE_OPTIONS,
|
||||
@@ -102,8 +101,6 @@ export function createSelection({
|
||||
if (record?.position)
|
||||
layerState._stationSet?.upsert([parts.rendering.stationItem(record)]);
|
||||
if (layerState._selectedSet?.size()) layerState._selectedSet.clear();
|
||||
// Removing the highlight entity ended the default renderer's follow of it.
|
||||
layerState._stockFollow?.stop();
|
||||
layerState._overlayHost.clearSource(BIKESHARE_SELECTED_OVERLAY_SOURCE_ID);
|
||||
}
|
||||
|
||||
@@ -145,7 +142,7 @@ export function createSelection({
|
||||
function _installClickHandler(viewer) {
|
||||
if (layerState._clickSubscription) return;
|
||||
|
||||
const clickOff = inputFor(viewer).onClick((event) => {
|
||||
layerState._clickSubscription = inputFor(viewer).onClick((event) => {
|
||||
const hit = event.drawHit;
|
||||
|
||||
if (hit) {
|
||||
@@ -165,26 +162,6 @@ export function createSelection({
|
||||
// Clicked anything else — deselect.
|
||||
if (layerState._selectedKey) _clearSelection();
|
||||
});
|
||||
// A double-click follows the selected station's highlight, as the
|
||||
// default renderer followed the point entity it was (the station dots
|
||||
// were point primitives, which it never followed).
|
||||
layerState._stockFollow = followOnDoubleClick({
|
||||
viewer,
|
||||
inputFor,
|
||||
name: 'bikeshare',
|
||||
enabled: () => layerState._enabled,
|
||||
targetFor: (hit) => {
|
||||
const key = layerState._selectedKey;
|
||||
const position = layerState._stationRenderMap.get(key)?.position;
|
||||
if (hit.set !== layerState._selectedSet?.id || !position) return null;
|
||||
return { key, position: () => ({ ...position }) };
|
||||
},
|
||||
});
|
||||
layerState._clickSubscription = () => {
|
||||
clickOff?.();
|
||||
layerState._stockFollow?.destroy();
|
||||
layerState._stockFollow = null;
|
||||
};
|
||||
|
||||
document.addEventListener('keydown', _onKeyDown);
|
||||
}
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { createSelection } from './selection.js';
|
||||
import { bindFakeGroundRenderer } from '../../testSupport/fakeGroundRenderer.mjs';
|
||||
import { fromDegrees } from '../../geo/ellipsoid.js';
|
||||
|
||||
test('a double-click follows the selected station, as its highlight entity was; deselecting ends it', (t) => {
|
||||
const viewer = {};
|
||||
const fake = bindFakeGroundRenderer(viewer);
|
||||
t.after(fake.unbind);
|
||||
const listeners = {};
|
||||
fake.renderer.input = {
|
||||
on(type, fn) {
|
||||
listeners[type] = fn;
|
||||
return () => delete listeners[type];
|
||||
},
|
||||
behaviours: { dblclickFollow: { enabled: true } },
|
||||
};
|
||||
const press = (type) =>
|
||||
listeners[type]({
|
||||
button: 0,
|
||||
modifiers: { shift: false, ctrl: false, alt: false, meta: false },
|
||||
position: { x: 5, y: 5 },
|
||||
});
|
||||
const position = fromDegrees(2, 41, 20);
|
||||
const state = {
|
||||
_enabled: true,
|
||||
_selectedKey: null,
|
||||
_stationRenderMap: new Map([['bcn:1', { position, stationId: '1' }]]),
|
||||
_stationSet: fake.renderer.draw.points({ id: 'bikeshare:stations' }),
|
||||
_selectedSet: fake.renderer.draw.points({ id: 'bikeshare:selected' }),
|
||||
_overlayHost: { setEntries() {}, clearSource() {} },
|
||||
_clickSubscription: null,
|
||||
};
|
||||
const selection = createSelection({
|
||||
state,
|
||||
services: {},
|
||||
parts: {
|
||||
rendering: { stationItem: (r) => ({ id: 'bcn:1', pos: r.position }) },
|
||||
},
|
||||
source: {},
|
||||
});
|
||||
const priorDocument = globalThis.document;
|
||||
globalThis.document = { addEventListener() {}, removeEventListener() {} };
|
||||
t.after(() => {
|
||||
if (priorDocument === undefined) delete globalThis.document;
|
||||
else globalThis.document = priorDocument;
|
||||
});
|
||||
selection._installClickHandler(viewer);
|
||||
|
||||
// A station dot itself (a point primitive before) is never followed.
|
||||
fake.setPick(() => ({ set: 'bikeshare:stations', id: 'bcn:1' }));
|
||||
press('dblclick');
|
||||
assert.equal(fake.follows.length, 0);
|
||||
|
||||
// Its first click selects it; the double-click lands on the highlight.
|
||||
press('click');
|
||||
assert.equal(state._selectedKey, 'bcn:1');
|
||||
fake.setPick(() => ({ set: 'bikeshare:selected', id: 'selected' }));
|
||||
press('dblclick');
|
||||
assert.equal(fake.follows.length, 1);
|
||||
assert.deepEqual(fake.renderer.camera.followed.position(), { ...position });
|
||||
|
||||
selection._clearSelection();
|
||||
assert.equal(fake.renderer.camera.followed, null, 'the highlight went');
|
||||
|
||||
// Disabled: a double-click on it follows nothing.
|
||||
state._clickSubscription();
|
||||
selection._selectStation('bcn:1');
|
||||
press('dblclick');
|
||||
assert.equal(fake.follows.length, 2, 'only the stop since');
|
||||
});
|
||||
@@ -17,8 +17,6 @@
|
||||
* Meshes and quads are capabilities: on a renderer without them there are
|
||||
* no viewshed volumes or monitor plane, and the lines still draw.
|
||||
*/
|
||||
import { positionToEcef } from '../../geo/ellipsoid.js';
|
||||
import { drawnItemTarget } from '../../data/stockFollow.js';
|
||||
import { drawOf } from '../../render/rendererOf.js';
|
||||
|
||||
/** Layer instances, for set ids unique to each. */
|
||||
@@ -93,9 +91,6 @@ export function createDrawSets({ state: layerState }) {
|
||||
plane: draw.quads?.({ id: `cctv:${n}:plane` }) ?? null,
|
||||
// What each line item was last written as, by id.
|
||||
lineKeys: new Map(),
|
||||
// Each line and plane item as last written, by id.
|
||||
lineItems: new Map(),
|
||||
planeItems: new Map(),
|
||||
};
|
||||
return current;
|
||||
}
|
||||
@@ -107,7 +102,6 @@ export function createDrawSets({ state: layerState }) {
|
||||
/** Let the sets go (the layer leaves its viewer, or moves to another). */
|
||||
function dispose() {
|
||||
if (!current) return;
|
||||
layerState._stockFollow?.stop();
|
||||
for (const set of [current.coverage, current.viewshed, current.plane])
|
||||
try {
|
||||
set?.dispose();
|
||||
@@ -145,7 +139,6 @@ export function createDrawSets({ state: layerState }) {
|
||||
const key = lineKey(item);
|
||||
if (s.lineKeys.get(item.id) === key) continue;
|
||||
s.lineKeys.set(item.id, key);
|
||||
s.lineItems.set(item.id, item);
|
||||
changed.push(item);
|
||||
}
|
||||
if (changed.length) s.coverage.upsert(changed);
|
||||
@@ -157,62 +150,17 @@ export function createDrawSets({ state: layerState }) {
|
||||
if (!s) return;
|
||||
s.coverage.clear();
|
||||
s.lineKeys.clear();
|
||||
s.lineItems.clear();
|
||||
}
|
||||
|
||||
/** Write the plane handle as it is now. */
|
||||
function writePlane(plane) {
|
||||
if (!plane?.id) return;
|
||||
const s = sets();
|
||||
if (!s?.plane) return;
|
||||
const item = quadItemOf(plane);
|
||||
s.planeItems.set(item.id, item);
|
||||
s.plane.upsert([item]);
|
||||
sets()?.plane?.upsert([quadItemOf(plane)]);
|
||||
}
|
||||
|
||||
/** Take a plane out. */
|
||||
function removePlane(plane) {
|
||||
const s = live();
|
||||
if (!plane?.id || !s?.plane) return;
|
||||
s.planeItems.delete(plane.id);
|
||||
s.plane.remove([plane.id]);
|
||||
// Removing the plane entity ended the default renderer's follow of it.
|
||||
layerState._stockFollow?.retain(
|
||||
(key) => key !== `${s.plane.id}:${plane.id}`,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* What a double-click on a hit follows or zooms to, as the default
|
||||
* renderer did for the entities these were: a coverage line (a polyline
|
||||
* entity) is zoomed to and the monitor plane (a plane entity with a
|
||||
* position) followed, framed to fit it. Null for anything else.
|
||||
* @param {{set: string, id: string}} hit
|
||||
*/
|
||||
function followTargetFor(hit) {
|
||||
const s = live();
|
||||
if (!s) return null;
|
||||
if (hit.set === s.coverage.id) {
|
||||
const item = s.lineItems.get(hit.id);
|
||||
return item && item.show !== false
|
||||
? drawnItemTarget(hit.set, item)
|
||||
: null;
|
||||
}
|
||||
if (!s.plane || hit.set !== s.plane.id) return null;
|
||||
const item = s.planeItems.get(hit.id);
|
||||
if (!item?.center) return null;
|
||||
const planes = s.planeItems;
|
||||
const at = positionToEcef(item.center);
|
||||
const [width, height] = item.size ?? [0, 0];
|
||||
return {
|
||||
key: `${hit.set}:${hit.id}`,
|
||||
// Where the plane is drawn now, as the entity's position was read.
|
||||
position: () => {
|
||||
const now = planes.get(hit.id)?.center;
|
||||
return now ? positionToEcef(now) : null;
|
||||
},
|
||||
sphere: { center: at, radius: Math.hypot(width, height) / 2 || 0 },
|
||||
};
|
||||
if (plane?.id) live()?.plane?.remove([plane.id]);
|
||||
}
|
||||
|
||||
/** Write a viewshed volume. */
|
||||
@@ -242,7 +190,6 @@ export function createDrawSets({ state: layerState }) {
|
||||
removePlane,
|
||||
writeVolume,
|
||||
removeVolume,
|
||||
followTargetFor,
|
||||
volumeWritesForTest,
|
||||
};
|
||||
}
|
||||
@@ -133,57 +133,3 @@ test('a renderer without meshes or quads still draws the lines', () => {
|
||||
unbind();
|
||||
}
|
||||
});
|
||||
|
||||
test('a double-click zooms to a coverage line and follows the plane, as their entities were', () => {
|
||||
const viewer = {};
|
||||
const { unbind } = bindFakeDraw(viewer);
|
||||
const retained = [];
|
||||
const state = {
|
||||
_viewer: viewer,
|
||||
_stockFollow: { retain: (drawn) => retained.push(drawn), stop() {} },
|
||||
};
|
||||
const drawSets = createDrawSets({ state });
|
||||
try {
|
||||
const a = line('cctv-cam-ray-tl');
|
||||
drawSets.writeLines([a]);
|
||||
const plane = {
|
||||
id: 'cctv-cam-plane',
|
||||
cameraId: 'cam',
|
||||
center: { x: 10, y: 0, z: 0 },
|
||||
orientation: { x: 0, y: 0, z: 0, w: 1 },
|
||||
size: [6, 8],
|
||||
show: true,
|
||||
};
|
||||
drawSets.writePlane(plane);
|
||||
const [coverage, planes] = drawSets.pickableSetIds();
|
||||
|
||||
const zoom = drawSets.followTargetFor({ set: coverage, id: a.id });
|
||||
assert.deepEqual(zoom.zoomTo.center, { x: 2.5, y: 3.5, z: 4.5 });
|
||||
|
||||
const follow = drawSets.followTargetFor({ set: planes, id: plane.id });
|
||||
assert.equal(follow.key, `${planes}:${plane.id}`);
|
||||
assert.deepEqual(follow.position(), { x: 10, y: 0, z: 0 });
|
||||
assert.equal(follow.sphere.radius, 5, 'framed to fit the plane');
|
||||
plane.center = { x: 20, y: 0, z: 0 };
|
||||
drawSets.writePlane(plane);
|
||||
assert.deepEqual(follow.position(), { x: 20, y: 0, z: 0 }, 'as drawn now');
|
||||
|
||||
assert.equal(drawSets.followTargetFor({ set: 'other', id: a.id }), null);
|
||||
a.show = false;
|
||||
drawSets.writeLines([a]);
|
||||
assert.equal(
|
||||
drawSets.followTargetFor({ set: coverage, id: a.id }),
|
||||
null,
|
||||
'a hidden line takes no part',
|
||||
);
|
||||
|
||||
// Taking the plane out ends a follow of it, and only of it.
|
||||
drawSets.removePlane(plane);
|
||||
assert.equal(retained.length, 1);
|
||||
assert.equal(retained[0](follow.key), false);
|
||||
assert.equal(retained[0]('other:key'), true);
|
||||
} finally {
|
||||
drawSets.dispose();
|
||||
unbind();
|
||||
}
|
||||
});
|
||||
@@ -5,7 +5,6 @@ import { viewshedColors, cameraHue } from '../../data/cctvViewshed.js';
|
||||
import { CCTV_OVERLAY_SOURCE_ID } from '../../data/cctvCards.js';
|
||||
import { GIZMO_ID_PREFIX } from '../../data/cctvGizmo.js';
|
||||
import { inputFor } from '../../input/dispatcher.js';
|
||||
import { followOnDoubleClick } from '../../data/stockFollow.js';
|
||||
import {
|
||||
GROUND_PRIOR_INIT_WAIT_MS,
|
||||
CALIBRATION_RANGE_FLOOR_M,
|
||||
@@ -439,21 +438,9 @@ export function createLifecycle({
|
||||
const unsubscribeHover = input.onPointer('move', (movement) =>
|
||||
parts.hover.handleHoverMove(movement?.endPosition),
|
||||
);
|
||||
// A double-click zooms to a coverage line and follows the monitor
|
||||
// plane, as the default renderer did for their entities (the camera
|
||||
// icons were billboards, which it never followed).
|
||||
layerState._stockFollow = followOnDoubleClick({
|
||||
viewer: layerState._viewer,
|
||||
inputFor: () => input,
|
||||
name: 'cctv',
|
||||
enabled: () => layerState._enabled,
|
||||
targetFor: (hit) => parts.drawSets.followTargetFor(hit),
|
||||
});
|
||||
layerState._clickSubscription = () => {
|
||||
unsubscribeClick();
|
||||
unsubscribeHover();
|
||||
layerState._stockFollow?.destroy();
|
||||
layerState._stockFollow = null;
|
||||
};
|
||||
|
||||
await parts.health.syncHealthState(true);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { hitTestWorldOverlay } from '../../overlays/worldOverlay.js';
|
||||
import { VESSEL_OVERLAY_SOURCE_ID } from '../../data/vesselLabels.js';
|
||||
import { inputFor } from '../../input/dispatcher.js';
|
||||
import { followOnDoubleClick } from '../../data/stockFollow.js';
|
||||
import {
|
||||
registerPickOwner,
|
||||
unregisterPickOwner,
|
||||
@@ -231,20 +230,7 @@ export function createCyclonesLayer({
|
||||
if (id) layer.setParams({ stormId: id });
|
||||
else if (!event.topHit) layer.setParams({ clear: true });
|
||||
});
|
||||
// A double-click follows a storm's point or zooms to its track or cone,
|
||||
// as the default renderer did for their entities.
|
||||
const follow = followOnDoubleClick({
|
||||
viewer,
|
||||
inputFor,
|
||||
name: 'weather-cyclones',
|
||||
enabled: () => enabled && !destroyed && selectionOwner === owner,
|
||||
targetFor: (hit) => rendering?.followTargetFor?.(hit) ?? null,
|
||||
});
|
||||
owner.follow = follow;
|
||||
owner.unsubscribe = () => {
|
||||
unsubscribe();
|
||||
follow.destroy();
|
||||
};
|
||||
owner.unsubscribe = unsubscribe;
|
||||
}
|
||||
function removeSelection() {
|
||||
const owner = selectionOwner;
|
||||
@@ -313,7 +299,6 @@ export function createCyclonesLayer({
|
||||
if (next.unavailable) {
|
||||
// An expired advisory must not remain presented as current hazard context.
|
||||
rendering.clear();
|
||||
selectionOwner?.follow?.stop();
|
||||
snapshot = next;
|
||||
selectedId = null;
|
||||
++navigationGeneration;
|
||||
@@ -333,8 +318,6 @@ export function createCyclonesLayer({
|
||||
return false;
|
||||
snapshot = next;
|
||||
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))
|
||||
select(
|
||||
selectionIntent === 'cleared'
|
||||
@@ -352,7 +335,6 @@ export function createCyclonesLayer({
|
||||
error = cause?.message || ADVISORIES_UNAVAILABLE;
|
||||
// Failed acquisition has no bounded last-good age guarantee at this layer.
|
||||
rendering?.clear();
|
||||
selectionOwner?.follow?.stop();
|
||||
snapshot = null;
|
||||
selectedId = null;
|
||||
++navigationGeneration;
|
||||
|
||||
@@ -63,10 +63,7 @@ export function createCycloneRendering({ viewer, overlayHost }) {
|
||||
let centers = new Map(),
|
||||
forecasts = [],
|
||||
spheres = new Map(),
|
||||
itemStorms = new Map(),
|
||||
// Per drawn item, where a double-click follows it (a point) or what it
|
||||
// zooms to (a track, cone or outline).
|
||||
itemPlaces = new Map();
|
||||
itemStorms = new Map();
|
||||
let counts = { storms: 0, tracks: 0, cones: 0, forecastPoints: 0 };
|
||||
let itemCount = 0;
|
||||
|
||||
@@ -102,8 +99,7 @@ export function createCycloneRendering({ viewer, overlayHost }) {
|
||||
if (destroyed) return false;
|
||||
const nextCenters = new Map(),
|
||||
nextSpheres = new Map(),
|
||||
nextItemStorms = new Map(),
|
||||
nextItemPlaces = new Map();
|
||||
nextItemStorms = new Map();
|
||||
const nextForecasts = [],
|
||||
nextLines = [],
|
||||
nextCones = [],
|
||||
@@ -126,7 +122,6 @@ export function createCycloneRendering({ viewer, overlayHost }) {
|
||||
const center = ecef(at);
|
||||
const extent = [center];
|
||||
own(`cyclone:${storm.id}:center`);
|
||||
nextItemPlaces.set(`cyclone:${storm.id}:center`, { at: center });
|
||||
nextCenters.set(storm.id, { id: storm.id, at });
|
||||
const label = {
|
||||
id: storm.id,
|
||||
@@ -147,9 +142,6 @@ export function createCycloneRendering({ viewer, overlayHost }) {
|
||||
// Lines take ECEF (draw.d.ts `LineItem`).
|
||||
const positions = line.map((c) => ecef(pair(c)));
|
||||
extent.push(...positions);
|
||||
nextItemPlaces.set(`cyclone:${storm.id}:track:${index}`, {
|
||||
extent: positions,
|
||||
});
|
||||
nextLines.push({
|
||||
id: own(`cyclone:${storm.id}:track:${index}`),
|
||||
positions,
|
||||
@@ -169,9 +161,6 @@ export function createCycloneRendering({ viewer, overlayHost }) {
|
||||
const all = rings.map((ring) => ring.map(pair));
|
||||
const ecefRings = all.map((ring) => ring.map(ecef));
|
||||
extent.push(...ecefRings[0]);
|
||||
nextItemPlaces.set(`cyclone:${storm.id}:cone:${index}`, {
|
||||
extent: ecefRings[0],
|
||||
});
|
||||
nextCones.push({
|
||||
id: own(`cyclone:${storm.id}:cone:${index}`),
|
||||
geometry: { kind: 'polygon', rings: all },
|
||||
@@ -179,10 +168,6 @@ export function createCycloneRendering({ viewer, overlayHost }) {
|
||||
height: 'clampGround',
|
||||
});
|
||||
ecefRings.forEach((ring, ringIndex) => {
|
||||
nextItemPlaces.set(
|
||||
`cyclone:${storm.id}:cone:${index}:outline:${ringIndex}`,
|
||||
{ extent: ring },
|
||||
);
|
||||
nextLines.push({
|
||||
id: own(
|
||||
`cyclone:${storm.id}:cone:${index}:outline:${ringIndex}`,
|
||||
@@ -203,9 +188,6 @@ export function createCycloneRendering({ viewer, overlayHost }) {
|
||||
const pos = lonLat(point.position);
|
||||
const p = ecef(pos);
|
||||
extent.push(p);
|
||||
nextItemPlaces.set(`cyclone:${storm.id}:forecast:${index}`, {
|
||||
at: p,
|
||||
});
|
||||
nextForecasts.push({
|
||||
id: own(`cyclone:${storm.id}:forecast:${index}`),
|
||||
pos,
|
||||
@@ -230,7 +212,6 @@ export function createCycloneRendering({ viewer, overlayHost }) {
|
||||
forecasts = nextForecasts;
|
||||
spheres = nextSpheres;
|
||||
itemStorms = nextItemStorms;
|
||||
itemPlaces = nextItemPlaces;
|
||||
counts = nextCounts;
|
||||
itemCount = nextItemStorms.size;
|
||||
committed = true;
|
||||
@@ -254,28 +235,6 @@ export function createCycloneRendering({ viewer, overlayHost }) {
|
||||
if (!setIds.has(hit.set)) return null;
|
||||
return itemStorms.get(hit.id) ?? null;
|
||||
},
|
||||
/**
|
||||
* What a double-click on a hit follows or zooms to (`followOnDoubleClick`
|
||||
* in `data/stockFollow.js`), as the default renderer did for the
|
||||
* advisory's entities: a center or forecast point is followed, a track,
|
||||
* cone or outline zoomed to.
|
||||
*/
|
||||
followTargetFor(hit) {
|
||||
if (!committed || !hit || hit.surface || !setIds.has(hit.set))
|
||||
return null;
|
||||
const place = itemPlaces.get(hit.id);
|
||||
if (!place) return null;
|
||||
if (place.extent) return { zoomTo: sphereFromPoints(place.extent) };
|
||||
const at = place.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) {
|
||||
return spheres.get(id) || null;
|
||||
},
|
||||
@@ -291,7 +250,6 @@ export function createCycloneRendering({ viewer, overlayHost }) {
|
||||
forecasts = [];
|
||||
spheres = new Map();
|
||||
itemStorms = new Map();
|
||||
itemPlaces = new Map();
|
||||
itemCount = 0;
|
||||
selected = null;
|
||||
counts = { storms: 0, tracks: 0, cones: 0, forecastPoints: 0 };
|
||||
|
||||
@@ -451,43 +451,3 @@ test('labels publish committed anchors to the shared overlay and follow selectio
|
||||
h.rendering.destroy();
|
||||
assert.equal(h.overlay.calls.at(-1), afterClear[1]);
|
||||
});
|
||||
|
||||
test('a double-click follows a storm’s points and zooms to its tracks and cones, as their entities did', async () => {
|
||||
const h = harness();
|
||||
await h.rendering.setSnapshot({ storms: [storm()] });
|
||||
for (const id of h.sets.points.items.keys()) {
|
||||
const target = h.rendering.followTargetFor(h.hit('points', id));
|
||||
assert.ok(target?.position, `${id} is followed`);
|
||||
assert.equal(target.key, `${h.sets.points.spec.id}:${id}`);
|
||||
}
|
||||
const center = h.rendering
|
||||
.followTargetFor(h.hit('points', 'cyclone:ep152026:center'))
|
||||
.position();
|
||||
const want = fromDegrees(179, 15, 0);
|
||||
assert.ok(
|
||||
Math.hypot(center.x - want.x, center.y - want.y, center.z - want.z) < 1e-6,
|
||||
);
|
||||
for (const kind of ['lines', 'cones'])
|
||||
for (const id of h.sets[kind].items.keys()) {
|
||||
const target = h.rendering.followTargetFor(h.hit(kind, id));
|
||||
assert.ok(target?.zoomTo?.radius > 0, `${id} is zoomed to`);
|
||||
}
|
||||
assert.equal(
|
||||
h.rendering.followTargetFor({
|
||||
set: 'other:points',
|
||||
id: 'cyclone:ep152026:center',
|
||||
surface: false,
|
||||
}),
|
||||
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();
|
||||
assert.equal(h.rendering.drawsFollowKey(key), false, 'cleared: not drawn');
|
||||
assert.equal(
|
||||
h.rendering.followTargetFor(h.hit('points', 'cyclone:ep152026:center')),
|
||||
null,
|
||||
);
|
||||
h.rendering.destroy();
|
||||
});
|
||||
@@ -18,8 +18,6 @@
|
||||
|
||||
import { roadLabel } from '../../data/routeSteps.js';
|
||||
import { fromDegrees, toLonLatH } from '../../geo/ellipsoid.js';
|
||||
import { sphereFromPoints } from '../../geo/sphere.js';
|
||||
import { followOnDoubleClick } from '../../data/stockFollow.js';
|
||||
import { hexColor } from '../../render/color.js';
|
||||
import { drawOf } from '../../render/rendererOf.js';
|
||||
import {
|
||||
@@ -1639,31 +1637,6 @@ export function createDirectionsLayer({ services, source }) {
|
||||
}
|
||||
}
|
||||
|
||||
/** What a double-click on a marker or the route follows or zooms to. */
|
||||
function followTargetFor(hit) {
|
||||
if (!_sets) return null;
|
||||
if (hit.set === _sets.markers.id) {
|
||||
const point =
|
||||
hit.id === 'directions:marker:A'
|
||||
? _a
|
||||
: hit.id === 'directions:marker:B'
|
||||
? _b
|
||||
: null;
|
||||
if (!point) return null;
|
||||
return {
|
||||
key: hit.id,
|
||||
position: () => fromDegrees(point.lon, point.lat, 0),
|
||||
};
|
||||
}
|
||||
if (hit.set === _sets.route.id && _route?.geometry?.length)
|
||||
return {
|
||||
zoomTo: sphereFromPoints(
|
||||
_route.geometry.map(([lon, lat]) => fromDegrees(lon, lat, 0)),
|
||||
),
|
||||
};
|
||||
return null;
|
||||
}
|
||||
|
||||
function _installClickHandler(viewer) {
|
||||
if (_clickSubscription) return;
|
||||
const input = inputFor(viewer);
|
||||
@@ -1697,25 +1670,9 @@ export function createDirectionsLayer({ services, source }) {
|
||||
}
|
||||
if (_selectedStep !== null) _clearStepSelection();
|
||||
});
|
||||
// A double-click follows an A or B marker and zooms to the route, as the
|
||||
// default renderer's double-click did with their entities.
|
||||
let follow = null;
|
||||
try {
|
||||
follow = followOnDoubleClick({
|
||||
viewer,
|
||||
inputFor: () => input,
|
||||
name: 'directions',
|
||||
enabled: () => _enabled,
|
||||
targetFor: followTargetFor,
|
||||
});
|
||||
} catch {
|
||||
// A renderer that takes no input has no double-click to follow on.
|
||||
follow = null;
|
||||
}
|
||||
_clickSubscription = () => {
|
||||
offPlace();
|
||||
offSelect();
|
||||
follow?.destroy();
|
||||
};
|
||||
if (typeof document !== 'undefined')
|
||||
document.addEventListener('keydown', _onKeyDown);
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
import { fromDegrees } from '../../geo/ellipsoid.js';
|
||||
import { drawOf, findInput } from '../../render/rendererOf.js';
|
||||
import {
|
||||
drawnItemTarget,
|
||||
followOnDoubleClick,
|
||||
} from '../../data/stockFollow.js';
|
||||
import { drawOf } from '../../render/rendererOf.js';
|
||||
import { cssColor } from '../../render/color.js';
|
||||
import { inputFor as defaultInputFor } from '../../input/dispatcher.js';
|
||||
import { msg, t } from '../../i18n/index.js';
|
||||
@@ -81,9 +77,6 @@ export function createDroneAirspaceLayer({
|
||||
let _lastError = null;
|
||||
let _stale = false;
|
||||
let _enabled = false;
|
||||
// Each drawn area by id, for a double-click to zoom to.
|
||||
let _areaById = new Map();
|
||||
let _stockFollow = null;
|
||||
let _clickSubscription = null;
|
||||
let _selectedId = null;
|
||||
let _selectedCardId = null;
|
||||
@@ -212,19 +205,6 @@ export function createDroneAirspaceLayer({
|
||||
if (_fills) _fills.show = _lines.show = true;
|
||||
overlayHost?.setVisible?.(DRONE_AIRSPACE_OVERLAY_SOURCE_ID, true);
|
||||
installClickHandler();
|
||||
// A double-click zooms to an area, as the default renderer zoomed to
|
||||
// its entity (a scene that takes no input has none).
|
||||
if (!_stockFollow && inputFor && findInput(_viewer))
|
||||
_stockFollow = followOnDoubleClick({
|
||||
viewer: _viewer,
|
||||
inputFor,
|
||||
name: layer.id,
|
||||
enabled: () => _enabled,
|
||||
targetFor: (hit) =>
|
||||
_setIds?.has(hit.set)
|
||||
? drawnItemTarget(hit.set, _areaById.get(hit.id))
|
||||
: null,
|
||||
});
|
||||
},
|
||||
|
||||
disable() {
|
||||
@@ -233,8 +213,6 @@ export function createDroneAirspaceLayer({
|
||||
_enabled = false;
|
||||
if (_fills) _fills.show = _lines.show = false;
|
||||
removeClickHandler();
|
||||
_stockFollow?.destroy();
|
||||
_stockFollow = null;
|
||||
clearSelection();
|
||||
},
|
||||
|
||||
@@ -309,7 +287,6 @@ export function createDroneAirspaceLayer({
|
||||
|
||||
_fills.set(nextFills);
|
||||
_lines.set(nextLines);
|
||||
_areaById = new Map(nextFills.map((item) => [item.id, item]));
|
||||
_snapshotSignature = signature;
|
||||
if (_selectedId) publishSelectedCard();
|
||||
_count = rows.length;
|
||||
@@ -337,8 +314,6 @@ export function createDroneAirspaceLayer({
|
||||
_request?.abort();
|
||||
_request = null;
|
||||
removeClickHandler();
|
||||
_stockFollow?.destroy();
|
||||
_stockFollow = null;
|
||||
clearSelection();
|
||||
_rowById.clear();
|
||||
_snapshotSignature = null;
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import { fromDegrees } from '../../geo/ellipsoid.js';
|
||||
import { followOnDoubleClick } from '../../data/stockFollow.js';
|
||||
import { inputFor as defaultInputFor } from '../../input/dispatcher.js';
|
||||
import { drawOf, findInput } from '../../render/rendererOf.js';
|
||||
import { drawOf } from '../../render/rendererOf.js';
|
||||
import {
|
||||
EARTHQUAKE_OVERLAY_SOURCE_ID,
|
||||
EARTHQUAKE_OVERLAY_COHORT_LIMIT,
|
||||
@@ -34,20 +32,13 @@ let instances = 0;
|
||||
* Given a Cesium viewer with no renderer bound, the
|
||||
* caller loads the package's `./render/cesium/unbound` export first.
|
||||
*/
|
||||
export function createEarthquakesLayer({
|
||||
source,
|
||||
overlayHost,
|
||||
inputFor = defaultInputFor,
|
||||
} = {}) {
|
||||
export function createEarthquakesLayer({ source, overlayHost } = {}) {
|
||||
if (typeof source?.getSnapshot !== 'function')
|
||||
throw new TypeError('Earthquakes require a snapshot source');
|
||||
if (!overlayHost) throw new TypeError('Earthquakes require an overlay host');
|
||||
let _viewer = null;
|
||||
let _request = 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.
|
||||
let _events = [];
|
||||
let _count = 0;
|
||||
@@ -69,26 +60,6 @@ export function createEarthquakesLayer({
|
||||
show: false,
|
||||
});
|
||||
_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;
|
||||
_lastUpdate = null;
|
||||
_lastError = null;
|
||||
@@ -109,7 +80,6 @@ export function createEarthquakesLayer({
|
||||
_request?.abort();
|
||||
_request = null;
|
||||
_enabled = false;
|
||||
_stockFollow?.stop();
|
||||
if (_discs) _discs.show = false;
|
||||
overlayHost.clearSource(EARTHQUAKE_OVERLAY_SOURCE_ID);
|
||||
overlayHost.setVisible(EARTHQUAKE_OVERLAY_SOURCE_ID, false);
|
||||
@@ -126,7 +96,6 @@ export function createEarthquakesLayer({
|
||||
return false;
|
||||
|
||||
const nextDiscs = [];
|
||||
const nextById = new Map();
|
||||
const nextEvents = [];
|
||||
let count = 0;
|
||||
const overlayEntries = [];
|
||||
@@ -150,10 +119,6 @@ export function createEarthquakesLayer({
|
||||
|
||||
const position = fromDegrees(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
|
||||
// clamped ground geometry every frame is what once cost 30 fps.
|
||||
// No outline: clamped to the ground, Cesium never drew one.
|
||||
@@ -180,11 +145,6 @@ export function createEarthquakesLayer({
|
||||
}
|
||||
|
||||
_discs.set(nextDiscs);
|
||||
_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;
|
||||
if (_enabled) {
|
||||
overlayHost.setEntries(
|
||||
@@ -221,11 +181,8 @@ export function createEarthquakesLayer({
|
||||
_enabled = false;
|
||||
overlayHost.clearSource(EARTHQUAKE_OVERLAY_SOURCE_ID);
|
||||
overlayHost.setVisible(EARTHQUAKE_OVERLAY_SOURCE_ID, false);
|
||||
_stockFollow?.destroy();
|
||||
_stockFollow = null;
|
||||
_discs?.dispose();
|
||||
_discs = null;
|
||||
_discsById = new Map();
|
||||
_events = [];
|
||||
_count = 0;
|
||||
_lastUpdate = null;
|
||||
|
||||
@@ -168,55 +168,3 @@ test('a viewer with nothing to draw with is refused at init, and init can be ret
|
||||
layer.destroy();
|
||||
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 () => rows },
|
||||
overlayHost: { setEntries() {}, setVisible() {}, clearSource() {} },
|
||||
});
|
||||
let rows = [row];
|
||||
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));
|
||||
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);
|
||||
assert.equal(renderer.camera.followed, null, 'hiding the layer stops it');
|
||||
});
|
||||
@@ -16,11 +16,7 @@ import {
|
||||
import { createHorizonCull } from '../streetLevel/view.js';
|
||||
import { fromDegrees } from '../../geo/ellipsoid.js';
|
||||
import { hexColor } from '../../render/color.js';
|
||||
import { drawOf, findFrame, findInput } from '../../render/rendererOf.js';
|
||||
import {
|
||||
drawnItemTarget,
|
||||
followOnDoubleClick,
|
||||
} from '../../data/stockFollow.js';
|
||||
import { drawOf, findFrame } from '../../render/rendererOf.js';
|
||||
import { readGhostMapsKml } from './kml.js';
|
||||
import {
|
||||
fieldLabel,
|
||||
@@ -201,8 +197,6 @@ export function createGhostMapsLayer({
|
||||
let _stream = 'closed';
|
||||
let _queue = Promise.resolve();
|
||||
let _clickSubscription = null;
|
||||
/** The follow a double-click on a placemark started, while installed. */
|
||||
let _stockFollow = null;
|
||||
let _rowListener = null;
|
||||
let _selectedKey = null;
|
||||
let _selectedCardId = null;
|
||||
@@ -271,10 +265,7 @@ export function createGhostMapsLayer({
|
||||
for (const [index, feature] of item.features) {
|
||||
if (!isGhostMapsEventExpired(feature.dateMs, at, _ageDays)) continue;
|
||||
for (const [kind, ids] of Object.entries(feature.itemIds))
|
||||
if (ids.length) {
|
||||
dropFollowOf(item.sets?.[kind], ids);
|
||||
item.sets?.[kind]?.remove(ids);
|
||||
}
|
||||
if (ids.length) item.sets?.[kind]?.remove(ids);
|
||||
item.features.delete(index);
|
||||
if (_selectedKey === `${productId}:${index}`) clearSelection();
|
||||
changed = true;
|
||||
@@ -287,22 +278,9 @@ export function createGhostMapsLayer({
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* End a double-click's follow of an item that goes (any of `ids`, or the
|
||||
* whole set), as removing its entity ended the default renderer's.
|
||||
*/
|
||||
function dropFollowOf(set, ids = null) {
|
||||
const key = _stockFollow?.following?.key;
|
||||
if (!set || !key?.startsWith(`${set.id}:`)) return;
|
||||
if (!ids || ids.includes(key.slice(set.id.length + 1))) _stockFollow.stop();
|
||||
}
|
||||
|
||||
function disposeSets(sets) {
|
||||
if (!sets) return;
|
||||
for (const set of Object.values(sets)) {
|
||||
dropFollowOf(set);
|
||||
set.dispose();
|
||||
}
|
||||
for (const set of Object.values(sets)) set.dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -329,13 +307,6 @@ export function createGhostMapsLayer({
|
||||
}
|
||||
for (const pin of next.pins) pin.set = sets.icons;
|
||||
next.sets = sets;
|
||||
// Each set's items by id, for a double-click to follow or zoom to.
|
||||
next.drawn = new Map(
|
||||
Object.entries(sets).map(([kind, set]) => [
|
||||
set.id,
|
||||
new Map(next.items[kind].map((item) => [item.id, item])),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
/** The placemark a hit on one of this layer's items is, or null. */
|
||||
@@ -765,32 +736,7 @@ export function createGhostMapsLayer({
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* A double-click follows a pin and zooms to a line or an area, as the
|
||||
* default renderer did for their entities (a scene that takes no input
|
||||
* has none).
|
||||
*/
|
||||
function installFollow() {
|
||||
if (_stockFollow || !_viewer || !inputFor || !findInput(_viewer)) return;
|
||||
_stockFollow = followOnDoubleClick({
|
||||
viewer: _viewer,
|
||||
inputFor,
|
||||
name: GHOSTMAPS_LAYER_ID,
|
||||
enabled: () => _enabled,
|
||||
targetFor: (hit) => {
|
||||
const key = hitKey(hit);
|
||||
const loaded = key && _loaded.get(key.split(':')[0]);
|
||||
return drawnItemTarget(
|
||||
hit.set,
|
||||
loaded?.drawn?.get(hit.set)?.get(hit.id),
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function removeClickHandler() {
|
||||
_stockFollow?.destroy();
|
||||
_stockFollow = null;
|
||||
_clickSubscription?.();
|
||||
_clickSubscription = null;
|
||||
picking?.unregisterPickOwner?.(GHOSTMAPS_LAYER_ID);
|
||||
@@ -824,7 +770,6 @@ export function createGhostMapsLayer({
|
||||
for (const item of _loaded.values())
|
||||
for (const set of Object.values(item.sets ?? {})) set.show = true;
|
||||
installClickHandler();
|
||||
installFollow();
|
||||
if (!_unsubscribe && typeof source.subscribe === 'function')
|
||||
_unsubscribe = source.subscribe(
|
||||
(catalog) => {
|
||||
|
||||
@@ -2,7 +2,6 @@ import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { createGhostMapsLayer } from './index.js';
|
||||
import { bindFakeDraw } from '../../testSupport/fakeDrawPort.mjs';
|
||||
import { fakeCameraPort } from '../../testSupport/fakeCameraPort.mjs';
|
||||
import { GHOSTMAPS_PRODUCTS, GHOSTMAPS_LATEST_DROP } from './catalog.js';
|
||||
|
||||
function element(localName, children = [], value = '', attributes = {}) {
|
||||
@@ -122,26 +121,13 @@ function fixture(
|
||||
const viewer = {};
|
||||
// An input port and a query port: a click picks what `click(id)` names.
|
||||
const listeners = new Set();
|
||||
const doubleListeners = new Set();
|
||||
let picked = null;
|
||||
const camera = fakeCameraPort();
|
||||
// What the camera follows, as the port's `follow` sets it.
|
||||
camera.port.followed = null;
|
||||
camera.port.follow = (target) => (camera.port.followed = target ?? null);
|
||||
const { draw, unbind } = bindFakeDraw(viewer, {
|
||||
camera: camera.port,
|
||||
input: {
|
||||
behaviours: { dblclickFollow: { enabled: true } },
|
||||
on(type, cb) {
|
||||
const into =
|
||||
type === 'click'
|
||||
? listeners
|
||||
: type === 'dblclick'
|
||||
? doubleListeners
|
||||
: null;
|
||||
if (!into) return () => {};
|
||||
into.add(cb);
|
||||
return () => into.delete(cb);
|
||||
if (type !== 'click') return () => {};
|
||||
listeners.add(cb);
|
||||
return () => listeners.delete(cb);
|
||||
},
|
||||
},
|
||||
query: { pick: () => picked },
|
||||
@@ -165,17 +151,6 @@ function fixture(
|
||||
modifiers: { shift: false, ctrl: false, alt: false },
|
||||
});
|
||||
};
|
||||
const dblclick = (id) => {
|
||||
const set = items().get(id);
|
||||
picked = set ? { set, id, surface: false } : null;
|
||||
for (const cb of [...doubleListeners])
|
||||
cb({
|
||||
type: 'dblclick',
|
||||
position: { x: 0, y: 0 },
|
||||
button: 0,
|
||||
modifiers: { shift: false, ctrl: false, alt: false },
|
||||
});
|
||||
};
|
||||
// The editions drawn: each draws in sets of its own.
|
||||
const mounted = {
|
||||
get size() {
|
||||
@@ -216,8 +191,6 @@ function fixture(
|
||||
items,
|
||||
liveSets,
|
||||
click,
|
||||
dblclick,
|
||||
camera: camera.port,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -669,13 +642,3 @@ test('narrowing to a window the loaded data covers clears a failed wider reload'
|
||||
assert.equal(layer.getStats().error, null);
|
||||
assert.equal(layer.getStats().count, 1);
|
||||
});
|
||||
|
||||
test('a double-click follows a pin until its edition goes, as its entity was', async (t) => {
|
||||
const { layer, viewer, dblclick, camera } = fixture(t);
|
||||
await layer.update(viewer);
|
||||
dblclick('ghostmaps:cip:0:0');
|
||||
assert.ok(camera.followed, 'the pin is followed');
|
||||
assert.match(camera.followed.key, /:icons:ghostmaps:cip:0:0$/);
|
||||
layer.disable();
|
||||
assert.equal(camera.followed, null, 'its edition gone, so is the follow');
|
||||
});
|
||||
@@ -1,18 +1,9 @@
|
||||
import { installationClassLabel, installationTitle } from './classLabel.js';
|
||||
import { t } from '../../i18n/index.js';
|
||||
import { LAYER_ID, MAX_RENDERED, COLOR_BY_CLASS } from './policy.js';
|
||||
import { entityRecord, readEntityRecord } from '../../data/entityRecords.js';
|
||||
import { entityFollowTarget } from '../../data/followed.js';
|
||||
import { entityRecord } from '../../data/entityRecords.js';
|
||||
import { fromDegrees } from '../../geo/ellipsoid.js';
|
||||
import { followOffsetFitting } from '../../geo/frames.js';
|
||||
import { sphereFromPoints } from '../../geo/sphere.js';
|
||||
import { heightsOf } from '../../queries/heights.js';
|
||||
import {
|
||||
drawOf,
|
||||
findCamera,
|
||||
findGlobe,
|
||||
findQuery,
|
||||
} from '../../render/rendererOf.js';
|
||||
import { drawOf, findGlobe } from '../../render/rendererOf.js';
|
||||
|
||||
let instances = 0;
|
||||
|
||||
@@ -55,10 +46,7 @@ export function createRendering({
|
||||
return [r, g, b, alpha ?? a];
|
||||
}
|
||||
|
||||
/**
|
||||
* Make the layer's draw sets, hidden until the layer is enabled, and
|
||||
* follow a site on a double-click.
|
||||
*/
|
||||
/** Make the layer's draw sets, hidden until the layer is enabled. */
|
||||
function attach(viewer) {
|
||||
const draw = drawOf(viewer);
|
||||
selectedDotKey = null;
|
||||
@@ -72,7 +60,6 @@ export function createRendering({
|
||||
}
|
||||
|
||||
function detach() {
|
||||
stopFollow();
|
||||
if (layerState.sets)
|
||||
for (const set of Object.values(layerState.sets)) set.dispose();
|
||||
layerState.sets = null;
|
||||
@@ -82,7 +69,6 @@ export function createRendering({
|
||||
function setShown(shown) {
|
||||
if (!layerState.sets) return;
|
||||
for (const set of Object.values(layerState.sets)) set.show = shown;
|
||||
if (!shown) stopFollow();
|
||||
}
|
||||
|
||||
/** Whether `setId` is one of this layer's sets. */
|
||||
@@ -156,7 +142,6 @@ export function createRendering({
|
||||
|
||||
function clearRendered() {
|
||||
clearSelectionFill();
|
||||
stopFollow();
|
||||
if (layerState.sets) {
|
||||
layerState.sets.dots.clear();
|
||||
layerState.sets.selected.clear();
|
||||
@@ -252,13 +237,12 @@ export function createRendering({
|
||||
else sets.selected.clear();
|
||||
}
|
||||
|
||||
/** Stop drawing a record's dot and outlines, and following it. */
|
||||
/** Stop drawing a record's dot and outlines. */
|
||||
function removeRecordItems(id, dotIds, outlineIds) {
|
||||
const rendered = layerState.renderedKeys.get(id);
|
||||
if (!rendered) return;
|
||||
dotIds.push(id);
|
||||
outlineIds.push(...rendered.outlineIds);
|
||||
if (follow?.recordId === id) stopFollow();
|
||||
layerState.renderedKeys.delete(id);
|
||||
}
|
||||
|
||||
@@ -444,98 +428,6 @@ export function createRendering({
|
||||
syncSelectionFill();
|
||||
}
|
||||
|
||||
/** The follow a double-click started, while the camera keeps it. */
|
||||
let follow = null;
|
||||
|
||||
/**
|
||||
* Follow the site whose dot is under `position`, as the default renderer
|
||||
* followed the site's entity on a double-click: by the site's display
|
||||
* position, framed as that renderer framed an entity it started
|
||||
* following. A double-click on an outline or the selected fill, which had
|
||||
* no position to follow, zooms to it at once instead.
|
||||
* @param {{x: number, y: number}} position Canvas pixels.
|
||||
*/
|
||||
function followAt(position) {
|
||||
const viewer = layerState.viewer;
|
||||
if (!layerState.enabled || !layerState.sets) return;
|
||||
const query = findQuery(viewer);
|
||||
const hit = query?.pick(position.x, position.y);
|
||||
if (!hit || !ownsSet(hit.set)) return;
|
||||
const camera = findCamera(viewer);
|
||||
if (!camera) return;
|
||||
const recordId = hit.meta?.installationId;
|
||||
const record = layerState.recordById.get(recordId);
|
||||
if (!record) return;
|
||||
try {
|
||||
if (
|
||||
hit.set !== layerState.sets.dots.id &&
|
||||
hit.set !== layerState.sets.selected.id
|
||||
) {
|
||||
const points = partPoints(record, hit.id);
|
||||
if (!points.length) return;
|
||||
// Following nothing then, as that zoom stopped any follow first.
|
||||
if (camera.followed) camera.follow(null);
|
||||
camera.flyToBounds(sphereFromPoints(points), { durationS: 0 });
|
||||
return;
|
||||
}
|
||||
const rendered = layerState.renderedKeys.get(recordId);
|
||||
if (!rendered) return;
|
||||
const { carrier } = rendered;
|
||||
const shown = readEntityRecord(carrier)?.displayPosition?.();
|
||||
if (!shown) return;
|
||||
// Centred where the dot is drawn, on the surface under it when its
|
||||
// height is loaded (the cached floor may not be yet), and held there
|
||||
// as the stock follow held the dot's bounding sphere.
|
||||
const surface = heightsOf(viewer).now({
|
||||
lon: record.longitude,
|
||||
lat: record.latitude,
|
||||
});
|
||||
const at = Number.isFinite(surface)
|
||||
? fromDegrees(record.longitude, record.latitude, surface)
|
||||
: shown;
|
||||
const pose = camera.pose?.();
|
||||
const target = entityFollowTarget(carrier, {
|
||||
key: `installations:${record.id}`,
|
||||
position: () => at,
|
||||
frame: 'enu',
|
||||
viewFrom: followOffsetFitting({ center: at, radius: 0 }, at, {
|
||||
fovy: pose?.fovy,
|
||||
aspectRatio: pose?.aspectRatio,
|
||||
minDistance: camera.controls?.minDistance,
|
||||
maxDistance: camera.controls?.maxDistance,
|
||||
}),
|
||||
});
|
||||
camera.follow(target);
|
||||
follow = { target, recordId };
|
||||
} catch (error) {
|
||||
// A camera that cannot follow leaves the view where it is, as a
|
||||
// viewer without entity tracking did on a double-click.
|
||||
console.warn(`${LAYER_ID}: cannot follow`, error);
|
||||
}
|
||||
}
|
||||
|
||||
/** The ground points of a record's outline or fill item `itemId`. */
|
||||
function partPoints(record, itemId) {
|
||||
const outline = /:outline:(\d+)$/.exec(itemId);
|
||||
if (outline) {
|
||||
const line = outlinesOf(record)[Number(outline[1])] || [];
|
||||
return line.map(([lon, lat]) => fromDegrees(lon, lat));
|
||||
}
|
||||
const fill = /:selected-fill:(\d+)$/.exec(itemId);
|
||||
if (fill) {
|
||||
const rings = footprintsOf(record)[Number(fill[1])] || [];
|
||||
return rings.flat().map(([lon, lat]) => fromDegrees(lon, lat));
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
/** Stop a follow this layer started, if the camera still keeps it. */
|
||||
function stopFollow() {
|
||||
const camera = follow && findCamera(layerState.viewer);
|
||||
if (follow && camera?.followed === follow.target) camera.follow(null);
|
||||
follow = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Second paint for floors that missed the bounded pre-render deadline.
|
||||
*
|
||||
@@ -579,8 +471,6 @@ export function createRendering({
|
||||
detach,
|
||||
setShown,
|
||||
ownsSet,
|
||||
followAt,
|
||||
stopFollow,
|
||||
installationSurfaceHeightM,
|
||||
clearSelectionFill,
|
||||
syncSelectionFill,
|
||||
|
||||
@@ -10,7 +10,6 @@ export function createSelection({
|
||||
const { clearSelectedEntityContextForLayer } = services.context;
|
||||
|
||||
let removeContextListeners = null;
|
||||
let removeDoubleClick = null;
|
||||
|
||||
function syncContextSelection(event) {
|
||||
if (!layerState.enabled) return;
|
||||
@@ -72,15 +71,6 @@ export function createSelection({
|
||||
parts.rendering.renderRecords();
|
||||
}
|
||||
});
|
||||
// Follow a site on a double-click, as the renderer's own double-click
|
||||
// followed the site's entity.
|
||||
removeDoubleClick =
|
||||
input.onPointer?.('dblclick', (event) => {
|
||||
// The renderer's own double-click follow, off while a tool holds it
|
||||
// or on a renderer without one.
|
||||
if (input.stockEnabled?.('dblclickFollow') !== true) return;
|
||||
parts.rendering.followAt(event.position);
|
||||
}) ?? null;
|
||||
}
|
||||
return {
|
||||
selectRecord,
|
||||
@@ -88,8 +78,6 @@ export function createSelection({
|
||||
destroy() {
|
||||
removeContextListeners?.();
|
||||
removeContextListeners = null;
|
||||
removeDoubleClick?.();
|
||||
removeDoubleClick = null;
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -7,7 +7,6 @@ import { createRendering } from './rendering.js';
|
||||
import { createNamedMarkers, namedPointId } from './namedMarkers.js';
|
||||
import { bindFakeCesiumScene } from '../../testSupport/fakeCesiumScene.mjs';
|
||||
import { fakeInput } from '../../input/testDoubles.mjs';
|
||||
import { inputFor } from '../../input/dispatcher.js';
|
||||
|
||||
function harness(t) {
|
||||
const previousWindow = globalThis.window;
|
||||
@@ -40,16 +39,6 @@ function harness(t) {
|
||||
renderedKeys: new Map(),
|
||||
viewer: {
|
||||
camera: { positionWC: Cesium.Cartesian3.fromDegrees(0, 0, 1e6) },
|
||||
// The viewer's stock double-click follow, which the site follow
|
||||
// stands in for.
|
||||
screenSpaceEventHandler: {
|
||||
getInputAction: (type) =>
|
||||
type === Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK
|
||||
? () => {}
|
||||
: undefined,
|
||||
setInputAction() {},
|
||||
removeInputAction() {},
|
||||
},
|
||||
scene: {
|
||||
globe: { show: false },
|
||||
canvas: Object.assign(new EventTarget(), {
|
||||
@@ -62,7 +51,7 @@ function harness(t) {
|
||||
},
|
||||
};
|
||||
let picked;
|
||||
const { draw, camera, query } = bindFakeCesiumScene(state.viewer);
|
||||
const { draw } = bindFakeCesiumScene(state.viewer);
|
||||
const input = fakeInput(state.viewer);
|
||||
t.mock.method(
|
||||
Cesium.SceneTransforms,
|
||||
@@ -124,8 +113,6 @@ function harness(t) {
|
||||
selection,
|
||||
assertSelected,
|
||||
draw,
|
||||
camera,
|
||||
query,
|
||||
input,
|
||||
parts,
|
||||
/** Click on what `pick` names, as the scene would pick it. */
|
||||
@@ -246,94 +233,3 @@ test('a click on a site dot or its outline selects the site; another set does no
|
||||
h.click({ id: { set: 'other:1', id: outline.id, meta: outline.meta } });
|
||||
assert.equal(selectedNow(), false);
|
||||
});
|
||||
|
||||
test('a double-click follows a site dot where it is drawn and zooms to its outline', (t) => {
|
||||
const h = harness(t);
|
||||
h.state.records[0].namedArea = false;
|
||||
h.state.records[0].outlineLines = [
|
||||
[
|
||||
[0, 0],
|
||||
[0.01, 0],
|
||||
],
|
||||
];
|
||||
h.parts.rendering.renderRecords({ claimSelection: true });
|
||||
h.state.enabled = true;
|
||||
const follows = [];
|
||||
const flights = [];
|
||||
let followed = null;
|
||||
Object.assign(h.camera, {
|
||||
follow(target) {
|
||||
follows.push(target);
|
||||
followed = target;
|
||||
},
|
||||
flyToBounds(sphere, options) {
|
||||
flights.push({ sphere, options });
|
||||
},
|
||||
controls: { minDistance: 1, maxDistance: 1e9 },
|
||||
});
|
||||
Object.defineProperty(h.camera, 'followed', { get: () => followed });
|
||||
let hit = null;
|
||||
h.query.pick = () => hit;
|
||||
const dots = h.state.sets.dots;
|
||||
const dot = h.draw.set(dots.id).items.get('base');
|
||||
h.input.dblclick({ x: 640, y: 400 });
|
||||
assert.equal(follows.length, 0, 'nothing of the layer under it');
|
||||
hit = { set: dots.id, id: 'base', meta: dot.meta, surface: false };
|
||||
h.input.dblclick({ x: 640, y: 400 });
|
||||
const target = follows.at(-1);
|
||||
assert.equal(target.key, 'installations:base');
|
||||
assert.equal(target.frame, 'enu');
|
||||
// The tracked card reads the site through the target's entity.
|
||||
assert.equal(target.entity, dot.meta);
|
||||
assert.equal(target.labelModel.title, 'Base');
|
||||
const at = target.position(0);
|
||||
assert.ok(Math.abs(at.x - 6378137) < 1e-6 && Math.abs(at.y) < 1e-6);
|
||||
// 100 m from it, north up, pitched down 45 degrees.
|
||||
const range = Math.hypot(
|
||||
target.viewFrom.x,
|
||||
target.viewFrom.y,
|
||||
target.viewFrom.z,
|
||||
);
|
||||
assert.ok(Math.abs(range - 100) < 1e-6);
|
||||
assert.ok(Math.abs(target.viewFrom.x) < 1e-9);
|
||||
assert.ok(Math.abs(target.viewFrom.y + target.viewFrom.z) < 1e-6);
|
||||
// On the surface under the dot once its height is loaded, before the
|
||||
// cached floor has it, and held there.
|
||||
h.query.sampleHeightNow = () => 2400;
|
||||
h.input.dblclick({ x: 640, y: 400 });
|
||||
const raised = follows.at(-1).position(0);
|
||||
assert.ok(Math.abs(raised.x - 6380537) < 1e-6);
|
||||
h.query.sampleHeightNow = () => null;
|
||||
h.input.dblclick({ x: 640, y: 400 });
|
||||
assert.ok(Math.abs(follows.at(-1).position(0).x - 6378137) < 1e-6);
|
||||
const outlines = h.state.sets.outlines;
|
||||
hit = {
|
||||
set: outlines.id,
|
||||
id: 'base:outline:0',
|
||||
meta: { installationId: 'base' },
|
||||
surface: false,
|
||||
};
|
||||
h.input.dblclick({ x: 640, y: 400 });
|
||||
assert.equal(followed, null, 'a zoom stops the follow');
|
||||
assert.equal(flights.length, 1);
|
||||
assert.equal(flights[0].options.durationS, 0);
|
||||
// The follow stops when the layer hides.
|
||||
hit = { set: dots.id, id: 'base', meta: dot.meta, surface: false };
|
||||
h.input.dblclick({ x: 640, y: 400 });
|
||||
assert.equal(followed?.key, 'installations:base');
|
||||
h.parts.rendering.setShown(false);
|
||||
assert.equal(followed, null);
|
||||
// Another layer's item under the cursor neither follows nor zooms.
|
||||
h.parts.rendering.setShown(true);
|
||||
const before = follows.length;
|
||||
hit = { set: 'another:1', id: 'base', meta: dot.meta, surface: false };
|
||||
h.input.dblclick({ x: 640, y: 400 });
|
||||
assert.equal(follows.length, before);
|
||||
assert.equal(flights.length, 1);
|
||||
// With the stock double-click follow turned off, nothing follows.
|
||||
hit = { set: dots.id, id: 'base', meta: dot.meta, surface: false };
|
||||
const release = inputFor(h.state.viewer).suppressStockClicks();
|
||||
h.input.dblclick({ x: 640, y: 400 });
|
||||
assert.equal(follows.length, before);
|
||||
release();
|
||||
});
|
||||
@@ -180,7 +180,6 @@ async function fixture(t) {
|
||||
addLaunchEntity: noop,
|
||||
flushLaunchEntities: noop,
|
||||
clearLaunchEntities: noop,
|
||||
followTargetFor: () => null,
|
||||
launchIdFromPicks: () => null,
|
||||
launchMarkerAt: () => null,
|
||||
missionHitsAt: () => [],
|
||||
|
||||
@@ -137,7 +137,6 @@ async function fixture({ legacySource = false } = {}) {
|
||||
},
|
||||
launchIdFromPicks: () => null,
|
||||
missionHitsAt: () => [],
|
||||
followTargetFor: () => null,
|
||||
launchMarkerAt: () => false,
|
||||
addLaunchEntity(record) {
|
||||
state._missionSets.items.push(record.id);
|
||||
@@ -327,11 +326,8 @@ test('destroy followed by actual init starts a clean instance with owned handler
|
||||
assert.equal(typeof f.state._inputSubscription, 'function');
|
||||
await f.destroy();
|
||||
assert.equal(f.state._inputSubscription, null);
|
||||
assert.equal(
|
||||
input.subscriberCount(),
|
||||
before - 3,
|
||||
'click, hover and double-click follow',
|
||||
);
|
||||
assert.equal(input.subscriberCount(), before - 2, 'click and hover');
|
||||
|
||||
assert.equal(f.attachedSets(), 0);
|
||||
assert.equal(f.viewer.scene.preRender.numberOfListeners, 0);
|
||||
} finally {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { isPointerFree } from '../../data/inputOwnership.js';
|
||||
import { inputFor } from '../../input/dispatcher.js';
|
||||
import { canvasOf, findCamera, findFrame } from '../../render/rendererOf.js';
|
||||
import { followOnDoubleClick } from '../../data/stockFollow.js';
|
||||
import { worldClock } from '../../time/worldClock.js';
|
||||
|
||||
const HOVER_PICK_INTERVAL_MS = 120;
|
||||
@@ -204,20 +203,9 @@ export function createLifecycle({
|
||||
launchAt: parts.rendering.launchMarkerAt,
|
||||
});
|
||||
const unsubscribeHover = input.onPointer('move', hover.move);
|
||||
// A double-click follows a mission point, as the default renderer
|
||||
// followed the missions' entities.
|
||||
layerState._stockFollow = followOnDoubleClick({
|
||||
viewer,
|
||||
inputFor: () => input,
|
||||
name: 'rocket-launches',
|
||||
enabled: () => layerState._enabled && parts.rendering.missionsShown(),
|
||||
targetFor: parts.rendering.followTargetFor,
|
||||
});
|
||||
layerState._inputSubscription = () => {
|
||||
unsubscribeClick();
|
||||
unsubscribeHover();
|
||||
layerState._stockFollow?.destroy();
|
||||
layerState._stockFollow = null;
|
||||
};
|
||||
// Apply horizon visibility before the renderer draws and picks.
|
||||
// A postRender write is one frame late and can remain visibly stale when
|
||||
@@ -307,7 +295,6 @@ export function createLifecycle({
|
||||
layerState._cameraReleased = true;
|
||||
parts.selection.stopMissionZoomAnchor();
|
||||
parts.rendering.showMissions(false);
|
||||
layerState._stockFollow?.stop();
|
||||
parts.orbitRendering.syncMissionOrbitPrimitiveVisibility();
|
||||
const canvas = canvasOf(layerState._viewer);
|
||||
if (canvas) canvas.style.cursor = '';
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { fromDegrees, fromDegreesInto } from '../../geo/ellipsoid.js';
|
||||
import { horizonFrom } from '../../geo/horizon.js';
|
||||
import { sphereFromPoints } from '../../geo/sphere.js';
|
||||
import { clamp } from '../../geo/vector.js';
|
||||
import { hexColor } from '../../render/color.js';
|
||||
import { drawOf, findCamera, findQuery } from '../../render/rendererOf.js';
|
||||
@@ -42,18 +41,7 @@ export function createRendering({
|
||||
let setIds = null;
|
||||
/** Frames the mission sets have been walked in, the live cache's key. */
|
||||
let frameNumber = 0;
|
||||
// The follow reads its target before preRender (once a tick, and again
|
||||
// in preUpdate while it first frames), so a follow read opens the live
|
||||
// sample the next preRender keeps: the camera and the marker stand at
|
||||
// the same instant, and every read until then shares it.
|
||||
let followSampled = false;
|
||||
|
||||
/** Open the live sample a follow read and the next preRender share. */
|
||||
function openFollowSample() {
|
||||
if (followSampled) return;
|
||||
followSampled = true;
|
||||
frameNumber += 1;
|
||||
}
|
||||
/**
|
||||
* Every drawn mission item by set and id, with what decides whether it
|
||||
* shows: `isolated` (the mission's selection), and for points and icons
|
||||
@@ -173,9 +161,6 @@ export function createRendering({
|
||||
|
||||
/** Remove every mission item, ahead of a rebuild. */
|
||||
function clearLaunchEntities() {
|
||||
// A followed item goes with them, as a removed entity stopped being
|
||||
// followed.
|
||||
layerState._stockFollow?.stop();
|
||||
const sets = layerState._missionSets;
|
||||
records.clear();
|
||||
pending.clear();
|
||||
@@ -194,28 +179,6 @@ export function createRendering({
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* What a double-click on a mission item follows: a point by where it is
|
||||
* drawn (the payload as it moves), a line zoomed to by its bounds.
|
||||
*/
|
||||
function followTargetFor(hit) {
|
||||
if (!missionHit(hit)) return null;
|
||||
const name = Object.keys(setIds).find((key) => setIds[key] === hit.set);
|
||||
const record = records.get(recordKey(name, hit.id));
|
||||
if (!record) return null;
|
||||
if (!record.position)
|
||||
return { zoomTo: sphereFromPoints(record.item.positions) };
|
||||
const at = record.position;
|
||||
return {
|
||||
key: `${setIds.sites}:${hit.id}`,
|
||||
position: () => {
|
||||
if (typeof at === 'function') openFollowSample();
|
||||
const p = typeof at === 'function' ? at() : at;
|
||||
return p ? copy(p) : null;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/** The launch of the first mission item among a click's drilled hits. */
|
||||
function launchIdFromPicks(hits) {
|
||||
for (const hit of hits) {
|
||||
@@ -287,8 +250,7 @@ export function createRendering({
|
||||
}
|
||||
|
||||
function updateMissionFrame() {
|
||||
if (followSampled) followSampled = false;
|
||||
else frameNumber += 1;
|
||||
frameNumber += 1;
|
||||
if (!layerState._enabled || !layerState._viewer || !missionsShown()) {
|
||||
parts.overlays.hideReplayVehicleOverlay();
|
||||
return;
|
||||
@@ -841,7 +803,6 @@ export function createRendering({
|
||||
showMissions,
|
||||
clearLaunchEntities,
|
||||
launchIdFromPicks,
|
||||
followTargetFor,
|
||||
missionHitsAt,
|
||||
launchMarkerAt,
|
||||
selectLaunchEntity,
|
||||
|
||||
@@ -35,9 +35,6 @@ export function createState({ services }) {
|
||||
|
||||
state._inputSubscription = null;
|
||||
|
||||
// The double-click follow of mission points, while initialised.
|
||||
state._stockFollow = null;
|
||||
|
||||
state._viewer = null;
|
||||
|
||||
state._declutterHandler = null;
|
||||
|
||||
@@ -13,7 +13,6 @@ import {
|
||||
findQuery,
|
||||
} from '../../render/rendererOf.js';
|
||||
import { inputFor } from '../../input/dispatcher.js';
|
||||
import { followOnDoubleClick } from '../../data/stockFollow.js';
|
||||
import { pickRenderAltitudeM } from '../../data/renderAltitude.js';
|
||||
import { routePlausible } from '../../data/routePlausible.js';
|
||||
import {
|
||||
@@ -151,8 +150,6 @@ export function createLocalAdsbLayer({
|
||||
let tickTimer = null;
|
||||
let syncTimer = null;
|
||||
let clickSubscription = null;
|
||||
/** The follow a double-click on a marker started, while installed. */
|
||||
let stockFollow = null;
|
||||
let removePreRender = null;
|
||||
let renderHeld = false;
|
||||
let selectedId = null;
|
||||
@@ -571,9 +568,6 @@ export function createLocalAdsbLayer({
|
||||
if (ringsGone.length) sets.rings.remove(ringsGone);
|
||||
// Expired aircraft take their 3D models (and pending loads) with them.
|
||||
if (removed) models?.retain(markers);
|
||||
// An aircraft that went took the follow a double-click gave it.
|
||||
const followed = stockFollow?.following;
|
||||
if (followed && !markers.has(followed.key)) stockFollow.stop();
|
||||
if (selectedId && !live.has(selectedId))
|
||||
clearSelection({ evicted: enabled });
|
||||
removeEntityContextsForLayer(LAYER_ID, { retainIds: live });
|
||||
@@ -688,26 +682,6 @@ export function createLocalAdsbLayer({
|
||||
|
||||
function installInteraction() {
|
||||
if (clickSubscription || !viewer) return;
|
||||
// A double-click follows a local aircraft, its card shown, as the
|
||||
// default renderer followed its entity.
|
||||
stockFollow = followOnDoubleClick({
|
||||
viewer,
|
||||
inputFor,
|
||||
name: LAYER_ID,
|
||||
enabled: () => enabled,
|
||||
targetFor: (hit) => {
|
||||
const marker =
|
||||
!hit.surface &&
|
||||
(hit.set === sets?.markers.id || hit.set === sets?.rings.id) &&
|
||||
markers.get(hit.id);
|
||||
if (!marker?.carrier) return null;
|
||||
return {
|
||||
key: marker.id,
|
||||
position: () => (marker.position ? { ...marker.position } : null),
|
||||
entity: marker.carrier,
|
||||
};
|
||||
},
|
||||
});
|
||||
clickSubscription = inputFor(viewer).onClick((event) => {
|
||||
if (!enabled) return;
|
||||
const target = clickTarget(event);
|
||||
@@ -728,8 +702,6 @@ export function createLocalAdsbLayer({
|
||||
}
|
||||
|
||||
function releaseInteraction() {
|
||||
stockFollow?.destroy();
|
||||
stockFollow = null;
|
||||
clickSubscription?.();
|
||||
clickSubscription = null;
|
||||
}
|
||||
|
||||
@@ -1309,42 +1309,6 @@ test('a type change takes its belly offset with the new model, however soon it i
|
||||
models.destroy();
|
||||
});
|
||||
|
||||
test('a double-click follows a local aircraft with its card, until it goes, as its entity was', async (t) => {
|
||||
const { bindRenderer } = await import('../../render/rendererOf.js');
|
||||
const { createStubRenderer } = await import('../../render/stub/index.js');
|
||||
const { followedOf } = await import('../../data/followed.js');
|
||||
const renderer = createStubRenderer();
|
||||
const viewer = { isDestroyed: () => false };
|
||||
const unbind = bindRenderer(viewer, renderer);
|
||||
const receiver = fakeReceiver({ mode: 'adsb', connected: true });
|
||||
const clock = { now: 100_000 };
|
||||
const { layer } = await enabledLayer(receiver, clock, null, {
|
||||
viewer: { viewer, draw: renderer.draw },
|
||||
});
|
||||
t.after(() => {
|
||||
layer.destroy();
|
||||
unbind();
|
||||
renderer.destroy();
|
||||
});
|
||||
receiver.set({ aircraft: [record()] });
|
||||
await layer.update();
|
||||
const set = renderer.testing.sets().find((id) => id.endsWith(':markers'));
|
||||
renderer.testing.scriptPicks(() => [
|
||||
{ set, id: 'local-adsb:abc123', surface: false },
|
||||
]);
|
||||
renderer.testing.pointer('dblclick', 10, 10);
|
||||
const followed = followedOf(viewer);
|
||||
assert.ok(followed, 'the aircraft is followed');
|
||||
assert.equal(followed.key, 'local-adsb:abc123');
|
||||
assert.ok(followed.entity, 'its entity record shows the tracked card');
|
||||
assert.equal(typeof followed.displayPosition, 'function');
|
||||
assert.ok(followed.labelModel?.title, 'with its card');
|
||||
receiver.set({ aircraft: [] });
|
||||
clock.now += 10 * 60_000;
|
||||
await layer.update();
|
||||
assert.equal(followedOf(viewer), null, 'gone, it is no longer followed');
|
||||
});
|
||||
|
||||
test('a click on a UAT ring selects its aircraft, as the ring was a point on its entity', async (t) => {
|
||||
const receiver = fakeReceiver({ mode: 'adsb', connected: true });
|
||||
const feeds = fakeFeeds();
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
import { isPointerFree } from '../../data/inputOwnership.js';
|
||||
import { inputFor as defaultInputFor } from '../../input/dispatcher.js';
|
||||
import {
|
||||
drawnItemTarget,
|
||||
followOnDoubleClick,
|
||||
} from '../../data/stockFollow.js';
|
||||
import { fromDegrees } from '../../geo/ellipsoid.js';
|
||||
import { cssColor } from '../../render/color.js';
|
||||
import {
|
||||
@@ -222,15 +218,10 @@ export function createNewsLayer({
|
||||
if (drawPictureCards !== null && typeof drawPictureCards !== 'function')
|
||||
throw new TypeError('News picture cards must be a function');
|
||||
|
||||
const outlineItems = new Map();
|
||||
let viewer = null,
|
||||
// The layer's draw sets (`sets.icons` and the rest), made on init.
|
||||
sets = null,
|
||||
clickOff = null,
|
||||
// The follow a double-click started, and what each set draws now (the
|
||||
// markers by set, the outlines by id), for it to follow or zoom to.
|
||||
stockFollow = null,
|
||||
drawnMarkers = new Map(),
|
||||
listener = null,
|
||||
runNavigation = null,
|
||||
request = null,
|
||||
@@ -890,19 +881,6 @@ export function createNewsLayer({
|
||||
horizon.update(cullTargets, { quiet: true });
|
||||
for (const kind of ['halos', 'points', 'icons', 'boxes'])
|
||||
sets[kind].set(list[kind]);
|
||||
// Every marker was drawn anew as an entity: that ended a follow of one.
|
||||
stockFollow?.retain(
|
||||
(key) =>
|
||||
!['halos', 'points', 'icons', 'boxes'].some((kind) =>
|
||||
key.startsWith(`${sets[kind].id}:`),
|
||||
),
|
||||
);
|
||||
drawnMarkers = new Map(
|
||||
['halos', 'points', 'icons', 'boxes'].map((kind) => [
|
||||
sets[kind].id,
|
||||
new Map(list[kind].map((item) => [item.id, item])),
|
||||
]),
|
||||
);
|
||||
updatePulse();
|
||||
if (drawPictureCards)
|
||||
// At every height: zoomed out, a hotspot's reports give way to its
|
||||
@@ -1048,8 +1026,6 @@ export function createNewsLayer({
|
||||
for (const [index, area] of disputed.entries())
|
||||
for (const [k, points] of area.rings.entries())
|
||||
line(`${pickId}~disputed${index}.${k}`, closed(points), 2, dotted);
|
||||
for (const item of [...parts.fills, ...parts.borders])
|
||||
outlineItems.set(item.id, item);
|
||||
if (parts.fills.length) sets.outlineFills.upsert(parts.fills);
|
||||
if (parts.borders.length) sets.outlineLines.upsert(parts.borders);
|
||||
outlineDisputed.set(key, disputed);
|
||||
@@ -1434,37 +1410,11 @@ export function createNewsLayer({
|
||||
if (id && isOwnedByOtherLayer(NEWS_LAYER_ID, id)) return;
|
||||
if (selectedId && !picked?.id) layer.setParams({ clear: true });
|
||||
});
|
||||
// A double-click follows a marker and zooms to an outline, as the
|
||||
// default renderer did for their entities.
|
||||
stockFollow = followOnDoubleClick({
|
||||
viewer,
|
||||
inputFor,
|
||||
name: NEWS_LAYER_ID,
|
||||
enabled: () => enabled && !destroyed,
|
||||
targetFor: followTargetFor,
|
||||
});
|
||||
}
|
||||
|
||||
function removeSelection() {
|
||||
clickOff?.();
|
||||
clickOff = null;
|
||||
stockFollow?.destroy();
|
||||
stockFollow = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* What a double-click on a hit follows or zooms to, as the default
|
||||
* renderer did for the entity it was: a marker is followed, an outline or
|
||||
* hotspot box zoomed to; an item not shown takes no part.
|
||||
*/
|
||||
function followTargetFor(hit) {
|
||||
if (!sets || hit.surface) return null;
|
||||
const item =
|
||||
drawnMarkers.get(hit.set)?.get(hit.id) ??
|
||||
(hit.set === sets.outlineFills.id || hit.set === sets.outlineLines.id
|
||||
? outlineItems.get(hit.id)
|
||||
: null);
|
||||
return item && item.show !== false ? drawnItemTarget(hit.set, item) : null;
|
||||
}
|
||||
|
||||
function feedView() {
|
||||
@@ -1810,7 +1760,6 @@ export function createNewsLayer({
|
||||
if (sets) for (const set of Object.values(sets)) set.dispose();
|
||||
sets = null;
|
||||
outlineParts.clear();
|
||||
outlineItems.clear();
|
||||
outlineDisputed.clear();
|
||||
viewer = null;
|
||||
listener = null;
|
||||
|
||||
@@ -103,10 +103,6 @@ function fixture(
|
||||
});
|
||||
cameraPort.port.flyTo = (destination, options = {}) =>
|
||||
flights.push({ destination, ...options });
|
||||
// What the camera follows, and where a double-click zooms.
|
||||
cameraPort.port.followed = null;
|
||||
cameraPort.port.follow = (target) =>
|
||||
(cameraPort.port.followed = target ?? null);
|
||||
const camera = {
|
||||
setHeight: (next) =>
|
||||
cameraPort.setPose({
|
||||
@@ -116,10 +112,8 @@ function fixture(
|
||||
moveEnd: () => cameraPort.emit('moveEnd'),
|
||||
};
|
||||
const viewer = {};
|
||||
let picked = null;
|
||||
const { draw, unbind } = bindFakeDraw(viewer, {
|
||||
camera: cameraPort.port,
|
||||
query: { pick: () => picked },
|
||||
frame: { requestRender() {}, on: () => () => {} },
|
||||
...(quality ? { quality } : {}),
|
||||
});
|
||||
@@ -133,23 +127,11 @@ function fixture(
|
||||
];
|
||||
// The scene's click dispatcher: `click(hit)` clicks over a drawn item.
|
||||
const clickHandlers = new Set();
|
||||
const doubleHandlers = new Set();
|
||||
const input = {
|
||||
onClick(fn) {
|
||||
clickHandlers.add(fn);
|
||||
return () => clickHandlers.delete(fn);
|
||||
},
|
||||
onPointer(type, fn) {
|
||||
if (type !== 'dblclick') return () => {};
|
||||
doubleHandlers.add(fn);
|
||||
return () => doubleHandlers.delete(fn);
|
||||
},
|
||||
stockEnabled: (name) => name === 'dblclickFollow',
|
||||
};
|
||||
// `dblclick(hit)` double-clicks over a drawn item.
|
||||
const dblclick = (hit) => {
|
||||
picked = hit;
|
||||
for (const fn of [...doubleHandlers]) fn({ position: { x: 10, y: 10 } });
|
||||
};
|
||||
const click = (topHit) => {
|
||||
for (const fn of [...clickHandlers])
|
||||
@@ -190,13 +172,6 @@ function fixture(
|
||||
items,
|
||||
click,
|
||||
clickHandlers,
|
||||
dblclick,
|
||||
cameraPort: cameraPort.port,
|
||||
/** The id of the layer's live draw set named `part`. */
|
||||
setId: (part) =>
|
||||
[...draw.sets.values()].find(
|
||||
(set) => !set.disposed && set.spec.id.endsWith(`:${part}`),
|
||||
)?.spec.id,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1326,51 +1301,3 @@ test('zoomed out, a hotspot is one beacon; off, nothing draws; destroyed, the se
|
||||
layer.destroy();
|
||||
assert.deepEqual(items('points'), []);
|
||||
});
|
||||
|
||||
test('a double-click follows a marker until the markers are drawn anew, and zooms to a hotspot outline', async (t) => {
|
||||
const { layer, items, dblclick, cameraPort, setId } = fixture(t, {
|
||||
height: 500_000,
|
||||
source: {
|
||||
getOutline: async () => ({
|
||||
polygons: [
|
||||
{
|
||||
outer: [
|
||||
[30, 45],
|
||||
[40, 45],
|
||||
[40, 52],
|
||||
[30, 52],
|
||||
],
|
||||
holes: [],
|
||||
},
|
||||
],
|
||||
borders: [],
|
||||
disputed: [],
|
||||
}),
|
||||
},
|
||||
});
|
||||
const zooms = [];
|
||||
cameraPort.flyToBounds = (sphere) => zooms.push(sphere);
|
||||
layer.enable();
|
||||
await layer.update();
|
||||
await flush();
|
||||
const marker = [...items('points'), ...items('icons')].find((item) =>
|
||||
String(item.id).startsWith('news:report:major~'),
|
||||
);
|
||||
const set = setId(items('points').includes(marker) ? 'points' : 'icons');
|
||||
dblclick({ set, id: marker.id, surface: false });
|
||||
assert.ok(cameraPort.followed, 'the marker is followed');
|
||||
assert.deepEqual(cameraPort.followed.position(), marker.pos);
|
||||
// A render draws every marker anew, as the entities were.
|
||||
await layer.update();
|
||||
await flush();
|
||||
assert.equal(cameraPort.followed, null, 'drawn anew: no longer followed');
|
||||
// Each line a hotspot box or outline draws is zoomed to.
|
||||
const line = [...items('boxes'), ...items('outline-lines')].find(
|
||||
(item) => item.show !== false,
|
||||
);
|
||||
const part = items('boxes').includes(line) ? 'boxes' : 'outline-lines';
|
||||
assert.ok(line, 'a box or outline is drawn');
|
||||
dblclick({ set: setId(part), id: line.id, surface: false });
|
||||
assert.ok(zooms.at(-1)?.radius > 0, 'it is zoomed to');
|
||||
assert.equal(cameraPort.followed, null);
|
||||
});
|
||||
@@ -1,7 +1,5 @@
|
||||
import { fromDegrees } from '../../geo/ellipsoid.js';
|
||||
import { drawOf, findInput } from '../../render/rendererOf.js';
|
||||
import { followOnDoubleClick } from '../../data/stockFollow.js';
|
||||
import { inputFor as defaultInputFor } from '../../input/dispatcher.js';
|
||||
import { drawOf } from '../../render/rendererOf.js';
|
||||
import { msg } from '../../i18n/marker.js';
|
||||
import { OSM_PLACES_LAYER_ID } from './model.js';
|
||||
import { createNominatimStatus } from '../../sources/nominatimStatus.js';
|
||||
@@ -30,7 +28,6 @@ export function createOsmPlacesLayer({
|
||||
overlayHost,
|
||||
// The same once-per-page capability probe as Nominatim's, on Overpass.
|
||||
overpassConfigured = createNominatimStatus({ url: '/api/overpass/status' }),
|
||||
inputFor = defaultInputFor,
|
||||
} = {}) {
|
||||
if (!overlayHost) throw new TypeError('OSM Places requires an overlay host');
|
||||
let viewer = null;
|
||||
@@ -42,17 +39,12 @@ export function createOsmPlacesLayer({
|
||||
let lastUpdate = null;
|
||||
/** true / false from the server's probe, null while unknown. */
|
||||
let configured = null;
|
||||
/** Each drawn place's position, for a double-click to follow. */
|
||||
let placeAt = new Map();
|
||||
let stockFollow = null;
|
||||
|
||||
function render() {
|
||||
if (!points) return;
|
||||
const items = [];
|
||||
const nextAt = new Map();
|
||||
const overlay = [];
|
||||
for (const record of records) {
|
||||
nextAt.set(`osm-place:${record.id}`, fromDegrees(record.lon, record.lat));
|
||||
items.push({
|
||||
id: `osm-place:${record.id}`,
|
||||
pos: { lon: record.lon, lat: record.lat },
|
||||
@@ -85,7 +77,6 @@ export function createOsmPlacesLayer({
|
||||
});
|
||||
}
|
||||
points.set(items);
|
||||
placeAt = nextAt;
|
||||
if (enabled)
|
||||
overlayHost.setEntries(OVERLAY_SOURCE_ID, overlay, {
|
||||
cohortLimit: LABEL_LIMIT,
|
||||
@@ -125,23 +116,6 @@ export function createOsmPlacesLayer({
|
||||
show: false,
|
||||
});
|
||||
overlayHost.setVisible(OVERLAY_SOURCE_ID, false);
|
||||
// A double-click follows a place, as the default renderer followed
|
||||
// the places' entities (a scene that takes no input has none).
|
||||
stockFollow?.destroy();
|
||||
stockFollow =
|
||||
findInput(viewer) &&
|
||||
followOnDoubleClick({
|
||||
viewer,
|
||||
inputFor,
|
||||
name: OSM_PLACES_LAYER_ID,
|
||||
enabled: () => enabled,
|
||||
targetFor: (hit) => {
|
||||
const at = hit.set === points?.id && placeAt.get(hit.id);
|
||||
return at
|
||||
? { key: `${hit.set}:${hit.id}`, position: () => ({ ...at }) }
|
||||
: null;
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
enable() {
|
||||
@@ -154,7 +128,6 @@ export function createOsmPlacesLayer({
|
||||
|
||||
disable() {
|
||||
enabled = false;
|
||||
stockFollow?.stop();
|
||||
if (points) points.show = false;
|
||||
overlayHost.clearSource(OVERLAY_SOURCE_ID);
|
||||
overlayHost.setVisible(OVERLAY_SOURCE_ID, false);
|
||||
@@ -170,11 +143,8 @@ export function createOsmPlacesLayer({
|
||||
enabled = false;
|
||||
overlayHost.clearSource(OVERLAY_SOURCE_ID);
|
||||
overlayHost.setVisible(OVERLAY_SOURCE_ID, false);
|
||||
stockFollow?.destroy();
|
||||
stockFollow = null;
|
||||
points?.dispose();
|
||||
points = null;
|
||||
placeAt = new Map();
|
||||
viewer = null;
|
||||
records = [];
|
||||
meta = null;
|
||||
@@ -190,8 +160,6 @@ export function createOsmPlacesLayer({
|
||||
records = Array.isArray(next) ? next.slice() : [];
|
||||
meta = nextMeta ? { ...nextMeta } : null;
|
||||
lastUpdate = Date.now();
|
||||
// New results replace every place: one followed is gone with them.
|
||||
stockFollow?.stop();
|
||||
render();
|
||||
},
|
||||
|
||||
|
||||
@@ -150,39 +150,3 @@ test('places are depth-tested past close range, so they never show through the g
|
||||
`depth test off only within ${distance} m`,
|
||||
);
|
||||
});
|
||||
|
||||
test('a double-click follows a place until new results replace it, 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);
|
||||
const layer = createOsmPlacesLayer({
|
||||
overlayHost: fakeOverlayHost(),
|
||||
overpassConfigured: async () => true,
|
||||
});
|
||||
t.after(() => {
|
||||
layer.destroy();
|
||||
unbind();
|
||||
renderer.destroy();
|
||||
});
|
||||
layer.init(viewer);
|
||||
layer.enable();
|
||||
layer.setResults(RECORDS, { kind: 'hospital', label: 'h', area: 'K' });
|
||||
const set = renderer.testing.sets().find((id) => id.endsWith(':points'));
|
||||
renderer.testing.scriptPicks(() => [
|
||||
{ set, id: 'osm-place:node/1', surface: false },
|
||||
]);
|
||||
renderer.testing.pointer('dblclick', 10, 10);
|
||||
const followed = renderer.camera.followed;
|
||||
assert.ok(followed, 'the place is followed');
|
||||
const p = followed.position(0);
|
||||
const lat = (Math.asin(p.z / Math.hypot(p.x, p.y, p.z)) * 180) / Math.PI;
|
||||
assert.ok(Math.abs(lat - 27.7) < 0.2, String(lat));
|
||||
layer.setResults(RECORDS.slice(1), {
|
||||
kind: 'hospital',
|
||||
label: 'h',
|
||||
area: 'K',
|
||||
});
|
||||
assert.equal(renderer.camera.followed, null, 'new results end it');
|
||||
});
|
||||
@@ -1,9 +1,5 @@
|
||||
import { fromDegrees } from '../../geo/ellipsoid.js';
|
||||
import { drawOf, findInput } from '../../render/rendererOf.js';
|
||||
import {
|
||||
drawnItemTarget,
|
||||
followOnDoubleClick,
|
||||
} from '../../data/stockFollow.js';
|
||||
import { drawOf } from '../../render/rendererOf.js';
|
||||
import { hexColor } from '../../render/color.js';
|
||||
import {
|
||||
PERIMETER_OVERLAY_SOURCE_ID,
|
||||
@@ -85,9 +81,6 @@ export function createFirePerimetersLayer({
|
||||
let _stale = false;
|
||||
let _lastError = null;
|
||||
let _enabled = false;
|
||||
// Each drawn area by id, for a double-click to zoom to.
|
||||
let _areaById = new Map();
|
||||
let _stockFollow = null;
|
||||
let _clickSubscription = null;
|
||||
let _selectedId = null;
|
||||
let _selectedLink = null;
|
||||
@@ -309,19 +302,6 @@ export function createFirePerimetersLayer({
|
||||
if (_fills) _fills.show = _lines.show = true;
|
||||
overlayHost?.setVisible?.(PERIMETER_OVERLAY_SOURCE_ID, true);
|
||||
installClickHandler();
|
||||
// A double-click zooms to an area, as the default renderer zoomed to
|
||||
// its entity (a scene that takes no input has none).
|
||||
if (!_stockFollow && inputFor && findInput(_viewer))
|
||||
_stockFollow = followOnDoubleClick({
|
||||
viewer: _viewer,
|
||||
inputFor,
|
||||
name: layer.id,
|
||||
enabled: () => _enabled,
|
||||
targetFor: (hit) =>
|
||||
_setIds?.has(hit.set)
|
||||
? drawnItemTarget(hit.set, _areaById.get(hit.id))
|
||||
: null,
|
||||
});
|
||||
},
|
||||
|
||||
disable() {
|
||||
@@ -330,8 +310,6 @@ export function createFirePerimetersLayer({
|
||||
_enabled = false;
|
||||
if (_fills) _fills.show = _lines.show = false;
|
||||
removeClickHandler();
|
||||
_stockFollow?.destroy();
|
||||
_stockFollow = null;
|
||||
clearSelection();
|
||||
},
|
||||
|
||||
@@ -407,7 +385,6 @@ export function createFirePerimetersLayer({
|
||||
|
||||
_fills.set(nextFills);
|
||||
_lines.set(nextLines);
|
||||
_areaById = new Map(nextFills.map((item) => [item.id, item]));
|
||||
_snapshotSignature = signature;
|
||||
// Refresh (or drop) the selected incident's card against the new feed.
|
||||
if (_selectedId) publishSelectedCard();
|
||||
@@ -435,8 +412,6 @@ export function createFirePerimetersLayer({
|
||||
_request?.abort();
|
||||
_request = null;
|
||||
removeClickHandler();
|
||||
_stockFollow?.destroy();
|
||||
_stockFollow = null;
|
||||
clearSelection();
|
||||
_rowById.clear();
|
||||
_snapshotSignature = null;
|
||||
|
||||
@@ -642,38 +642,3 @@ test('a failed refresh after a stale snapshot reads as the failure, not stale',
|
||||
assert.equal(h.layer.getStats().stale, false);
|
||||
assert.equal(h.layer.getStats().error, 'WFIGS HTTP 502');
|
||||
});
|
||||
|
||||
test('a double-click zooms to a perimeter, as the default renderer zoomed to its entity', 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);
|
||||
const layer = createFirePerimetersLayer({
|
||||
source: { getSnapshot: async () => [row] },
|
||||
});
|
||||
t.after(() => {
|
||||
layer.destroy();
|
||||
unbind();
|
||||
renderer.destroy();
|
||||
});
|
||||
layer.init(viewer);
|
||||
layer.enable();
|
||||
await layer.update();
|
||||
for (const suffix of [':fills', ':lines']) {
|
||||
const set = renderer.testing.sets().find((id) => id.endsWith(suffix));
|
||||
renderer.testing.scriptPicks(() => [
|
||||
{ set, id: `fire-perimeter:${row.stableId}:0`, surface: false },
|
||||
]);
|
||||
renderer.camera.setView({
|
||||
destination: { lon: 0, lat: 0, height: 20_000_000 },
|
||||
});
|
||||
renderer.testing.tick();
|
||||
assert.ok(renderer.camera.pose().height > 1_000_000, 'starts far out');
|
||||
renderer.testing.pointer('dblclick', 10, 10);
|
||||
renderer.testing.tick();
|
||||
const pose = renderer.camera.pose();
|
||||
assert.equal(renderer.camera.followed, null, 'zoomed to, not followed');
|
||||
assert.ok(pose.height < 1_000_000, `${suffix}: ${pose.height}`);
|
||||
}
|
||||
});
|
||||
@@ -1,5 +1,4 @@
|
||||
import { inputFor } from '../../input/dispatcher.js';
|
||||
import { followOnDoubleClick } from '../../data/stockFollow.js';
|
||||
import {
|
||||
RADIO_PREFIX,
|
||||
RADIO_PICK_WINDOW_PX,
|
||||
@@ -99,15 +98,6 @@ export function createInteraction({
|
||||
);
|
||||
}
|
||||
});
|
||||
// A double-click follows a station, as the default renderer followed
|
||||
// its entity.
|
||||
layerState._stockFollow = followOnDoubleClick({
|
||||
viewer,
|
||||
inputFor,
|
||||
name: 'radio',
|
||||
enabled: () => radioPresentationAllowed(),
|
||||
targetFor: (hit) => parts.rendering.followTargetFor(hit),
|
||||
});
|
||||
// Polling remains bounded during flights, but a stationary camera no longer
|
||||
// rewrites every station's visibility four times per second while voice and
|
||||
// audio processing share the main thread.
|
||||
@@ -121,8 +111,6 @@ export function createInteraction({
|
||||
unregisterPickOwner('radio');
|
||||
layerState._clickSubscription?.();
|
||||
layerState._clickSubscription = null;
|
||||
layerState._stockFollow?.destroy();
|
||||
layerState._stockFollow = null;
|
||||
if (layerState._horizonTimer) clearInterval(layerState._horizonTimer);
|
||||
layerState._horizonTimer = null;
|
||||
}
|
||||
|
||||
@@ -529,10 +529,6 @@ export function createRendering({
|
||||
layerState._selectedId = null;
|
||||
}
|
||||
|
||||
// Every station was drawn anew as an entity: that ended a follow of one.
|
||||
layerState._stockFollow?.retain(
|
||||
(key) => !key.startsWith(`${sets?.stations.id}:`),
|
||||
);
|
||||
layerState._renderById.clear();
|
||||
drawnShow.clear();
|
||||
clusteredIds = new Set();
|
||||
@@ -575,7 +571,6 @@ export function createRendering({
|
||||
|
||||
/** Stop clustering and let the stations' draw sets go. */
|
||||
function removeDataSource() {
|
||||
layerState._stockFollow?.stop();
|
||||
offCameraChanged?.();
|
||||
offCameraChanged = null;
|
||||
if (sets) for (const set of Object.values(sets)) set.dispose();
|
||||
@@ -603,10 +598,6 @@ export function createRendering({
|
||||
/** Take the selected station's dot and bracket down, if it has them. */
|
||||
function removeSelectionEntity() {
|
||||
if (!selection) return;
|
||||
// The selection's dot was an entity: taking it down ended its follow.
|
||||
layerState._stockFollow?.retain(
|
||||
(key) => !key.startsWith(`${sets?.selectedDot.id}:`),
|
||||
);
|
||||
selection = null;
|
||||
sets?.selectedDot.clear();
|
||||
sets?.selectedBracket.clear();
|
||||
@@ -622,32 +613,8 @@ export function createRendering({
|
||||
governorRequestRender('radio-recluster');
|
||||
}
|
||||
|
||||
/**
|
||||
* What a double-click on a hit follows (`followOnDoubleClick`), as the
|
||||
* default renderer followed a station's entity or the selected one's: a
|
||||
* cluster, never an entity, is followed by nothing.
|
||||
*/
|
||||
function followTargetFor(hit) {
|
||||
if (!sets || hit.surface) return null;
|
||||
let at = null;
|
||||
let set = hit.set;
|
||||
if (set === sets.stations.id && hit.id.startsWith(RADIO_PREFIX))
|
||||
at = layerState._renderById.get(
|
||||
hit.id.slice(RADIO_PREFIX.length),
|
||||
)?.position;
|
||||
else if (
|
||||
(set === sets.selectedDot.id || set === sets.selectedBracket.id) &&
|
||||
selection?.dot.id === hit.id
|
||||
) {
|
||||
at = selection.position;
|
||||
set = sets.selectedDot.id;
|
||||
}
|
||||
return at ? { key: `${set}:${hit.id}`, position: () => ({ ...at }) } : null;
|
||||
}
|
||||
|
||||
return {
|
||||
radioStationIdFromPick,
|
||||
followTargetFor,
|
||||
installDataSource,
|
||||
removeDataSource,
|
||||
setStationsShown,
|
||||
|
||||
@@ -139,26 +139,3 @@ test('a filter that hides stations clusters them again at once', async () => {
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
test('a double-click follows a station, as its entity was', async () => {
|
||||
const { createStubRenderer } = await import('../../render/stub/index.js');
|
||||
const renderer = createStubRenderer();
|
||||
const stations = [station(1, -97.0, 30.0), station(2, -90, 35)];
|
||||
try {
|
||||
await withRadioLayer({ stations, renderer }, async () => {
|
||||
const set = renderer.testing
|
||||
.sets()
|
||||
.find((id) => id.endsWith(':stations'));
|
||||
renderer.testing.scriptPicks(() => [
|
||||
{ set, id: `radio:${stations[1].id}`, surface: false },
|
||||
]);
|
||||
renderer.testing.pointer('dblclick', 10, 10);
|
||||
const followed = renderer.camera.followed;
|
||||
assert.ok(followed, 'the station is followed');
|
||||
const { lon, lat } = toLonLatH(followed.position(0), WGS84);
|
||||
assert.ok(Math.abs(lon + 90) < 1e-6 && Math.abs(lat - 35) < 1e-6);
|
||||
});
|
||||
} finally {
|
||||
renderer.destroy();
|
||||
}
|
||||
});
|
||||
@@ -119,8 +119,6 @@ export function createState({ services }) {
|
||||
layerState._playFallbackAttemptId = null;
|
||||
|
||||
layerState._clickSubscription = null;
|
||||
/** The follow a double-click on a station started, while installed. */
|
||||
layerState._stockFollow = null;
|
||||
|
||||
layerState._horizonTimer = null;
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { toRadians } from '../../geo/vector.js';
|
||||
import { cameraOf } from '../../render/rendererOf.js';
|
||||
import { followOnDoubleClick } from '../../data/stockFollow.js';
|
||||
|
||||
export function createInteraction({ state, parts, inputFor }) {
|
||||
function beginInteraction(viewer) {
|
||||
@@ -11,15 +10,6 @@ export function createInteraction({ state, parts, inputFor }) {
|
||||
if (!record?.reference) return;
|
||||
flyToReference(viewer, record.reference);
|
||||
});
|
||||
// A double-click follows a landing point or reference and zooms to a
|
||||
// cable, as the default renderer did for their entities.
|
||||
state._stockFollow = followOnDoubleClick({
|
||||
viewer,
|
||||
inputFor,
|
||||
name: 'submarine-cables',
|
||||
enabled: () => state._enabled,
|
||||
targetFor: (hit) => parts.rendering.followTargetFor(hit),
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -109,8 +109,6 @@ export function createLifecycle({ state, parts, source, mapStackEventTarget }) {
|
||||
state._overlayPublisher.hide();
|
||||
state._clickSubscription?.();
|
||||
state._clickSubscription = null;
|
||||
state._stockFollow?.destroy();
|
||||
state._stockFollow = null;
|
||||
if (state._preRenderRemover) {
|
||||
state._preRenderRemover();
|
||||
state._preRenderRemover = null;
|
||||
|
||||
@@ -4,7 +4,6 @@ import { densifyRhumb } from '../../geo/rhumb.js';
|
||||
import { distance, toRadians } from '../../geo/vector.js';
|
||||
import { cssColor } from '../../render/color.js';
|
||||
import { cameraOf, canvasOf, drawOf } from '../../render/rendererOf.js';
|
||||
import { drawnItemTarget } from '../../data/stockFollow.js';
|
||||
import {
|
||||
clampLabel,
|
||||
createCableOverlayEntry,
|
||||
@@ -181,9 +180,6 @@ export function createRendering({ state }) {
|
||||
state._publishScratch.length = 0;
|
||||
state._loaded = false;
|
||||
state._referenceSweepGate.reset();
|
||||
// The sources' entities went with them, and so did a follow of one.
|
||||
state._stockFollow?.stop();
|
||||
state._drawnItems = new Map();
|
||||
if (!state._sets) return;
|
||||
if (clearSets) for (const set of Object.values(state._sets)) set.clear();
|
||||
for (const picks of state._picks.values()) picks.clear();
|
||||
@@ -399,18 +395,6 @@ export function createRendering({ state }) {
|
||||
map.clear();
|
||||
for (const [id, info] of picks) map.set(id, info);
|
||||
}
|
||||
// Drawn anew, as new sources' entities were: a follow of one ends.
|
||||
state._stockFollow?.stop();
|
||||
state._drawnItems = new Map([
|
||||
[sets.lines.id, new Map(out.lines.map((item) => [item.id, item]))],
|
||||
[sets.fills.id, new Map(out.fills.map((item) => [item.id, item]))],
|
||||
[sets.pins.id, new Map(out.pins.map((item) => [item.id, item]))],
|
||||
// A reference's stem and point were one entity, placed at the tip.
|
||||
...[sets.stems.id, sets.references.id].map((id) => [
|
||||
id,
|
||||
new Map(out.references.map((record) => [record.id, record.point])),
|
||||
]),
|
||||
]);
|
||||
sets.lines.set(out.lines);
|
||||
sets.fills.set(out.fills);
|
||||
sets.pins.set(out.pins);
|
||||
@@ -418,21 +402,6 @@ export function createRendering({ state }) {
|
||||
sets.references.set(out.references.map((record) => record.point));
|
||||
}
|
||||
|
||||
/**
|
||||
* What a double-click on a hit follows or zooms to, as the default
|
||||
* renderer did for the entity it was: a landing point or a reference is
|
||||
* followed, a cable or area zoomed to.
|
||||
*/
|
||||
function followTargetFor(hit) {
|
||||
if (!hit || hit.surface || !state._setIds.has(hit.set)) return null;
|
||||
const item = state._drawnItems?.get(hit.set)?.get(hit.id);
|
||||
if (!item) return null;
|
||||
// A reference's stem and point follow as one.
|
||||
const set =
|
||||
hit.set === state._sets?.stems.id ? state._sets.references.id : hit.set;
|
||||
return drawnItemTarget(set, item);
|
||||
}
|
||||
|
||||
/** What a pick on one of the layer's sets names, or null. */
|
||||
function pickInfo(hit) {
|
||||
if (!hit || !state._setIds.has(hit.set)) return null;
|
||||
@@ -533,7 +502,6 @@ export function createRendering({ state }) {
|
||||
applyCableClassification,
|
||||
drawFeatures,
|
||||
pickInfo,
|
||||
followTargetFor,
|
||||
updateReferenceVisibility,
|
||||
};
|
||||
}
|
||||
@@ -62,9 +62,6 @@ export function createState({ sweepClock, overlayHost }) {
|
||||
state._referenceRecords = [];
|
||||
|
||||
state._clickSubscription = null;
|
||||
/** The follow a double-click started, and each set's drawn items by id. */
|
||||
state._stockFollow = null;
|
||||
state._drawnItems = new Map();
|
||||
|
||||
state._preRenderRemover = null;
|
||||
|
||||
|
||||
+12
-81
@@ -18,10 +18,8 @@ import {
|
||||
drawOf,
|
||||
findCamera,
|
||||
findGlobe,
|
||||
findInput,
|
||||
findQuery,
|
||||
} from '../render/rendererOf.js';
|
||||
import { drawnItemTarget, followOnDoubleClick } from '../data/stockFollow.js';
|
||||
import { cssColor } from '../render/color.js';
|
||||
import { markBaseTileset } from '../render/baseTilesets.js';
|
||||
import { fromDegrees, toLonLatH } from '../geo/ellipsoid.js';
|
||||
@@ -90,28 +88,6 @@ function libraryRowControls(getExtent, onZoom, onRemove, legend = []) {
|
||||
* given; otherwise the manifest's static `display.legend` (a tile layer's
|
||||
* colour scale). Labels travel with the colours, so colour is never alone.
|
||||
*/
|
||||
/**
|
||||
* A double-click on one of a library layer's drawn items follows it (a
|
||||
* point) or zooms to it (a line or area), as the default renderer did for
|
||||
* the entities they were; null on a scene that takes no input.
|
||||
* @param {object} viewer
|
||||
* @param {string} name The layer, for warnings.
|
||||
* @param {() => boolean} enabled
|
||||
* @param {(hit: {set: string, id: string}) => object|null|undefined} itemFor
|
||||
* The item a hit names, if it is the layer's.
|
||||
*/
|
||||
function libraryDoubleClick(viewer, name, enabled, itemFor) {
|
||||
const input = viewer ? findInput(viewer) : null;
|
||||
if (!input) return null;
|
||||
return followOnDoubleClick({
|
||||
viewer,
|
||||
inputFor: () => input,
|
||||
name,
|
||||
enabled,
|
||||
targetFor: (hit) => drawnItemTarget(hit.set, itemFor(hit)),
|
||||
});
|
||||
}
|
||||
|
||||
export function colorByLegend(display, counts = null) {
|
||||
const colorBy = display?.colorBy;
|
||||
if (!colorBy)
|
||||
@@ -495,13 +471,9 @@ export function createLibraryTileLayer(
|
||||
let outlineCount = 0;
|
||||
let outlineEpoch = 0;
|
||||
let outlineBuilds = 0;
|
||||
/** The outline's rings by item id, for a double-click to zoom to. */
|
||||
let outlineItems = new Map();
|
||||
let outlineZoom = null;
|
||||
|
||||
function removeOutline() {
|
||||
outlineEpoch += 1;
|
||||
outlineItems = new Map();
|
||||
try {
|
||||
outline?.dispose();
|
||||
} catch {
|
||||
@@ -526,27 +498,27 @@ export function createLibraryTileLayer(
|
||||
);
|
||||
if (epoch !== outlineEpoch || !enabled || !rings.length) return;
|
||||
const color = cssColor(OUTLINE_COLOR);
|
||||
// Pickable, as the polyline entities were: a double-click on a
|
||||
// border zooms to it.
|
||||
const set = drawOf(viewer).lines({
|
||||
id: `${id}:outline:${++outlineBuilds}`,
|
||||
pickable: false,
|
||||
});
|
||||
const items = rings.map((ring, index) => ({
|
||||
id: String(index),
|
||||
positions: ring.map(([lon, lat]) => fromDegrees(lon, lat, 0)),
|
||||
widthPx: OUTLINE_WIDTH_PX,
|
||||
mode: 'draped',
|
||||
clampTo: 'both',
|
||||
style: { kind: 'solid', color },
|
||||
}));
|
||||
try {
|
||||
set.set(items);
|
||||
set.set(
|
||||
rings.map((ring, index) => ({
|
||||
id: String(index),
|
||||
positions: ring.map(([lon, lat]) => fromDegrees(lon, lat, 0)),
|
||||
widthPx: OUTLINE_WIDTH_PX,
|
||||
mode: 'draped',
|
||||
clampTo: 'both',
|
||||
style: { kind: 'solid', color },
|
||||
pickable: false,
|
||||
})),
|
||||
);
|
||||
} catch (error) {
|
||||
set.dispose();
|
||||
throw error;
|
||||
}
|
||||
outline = set;
|
||||
outlineItems = new Map(items.map((item) => [item.id, item]));
|
||||
outlineCount = rings.length;
|
||||
if (outlineMode !== 'bbox')
|
||||
registerDynamicCredit(viewer, NATURAL_EARTH_CREDIT);
|
||||
@@ -640,13 +612,6 @@ export function createLibraryTileLayer(
|
||||
const off = mapStackController?.subscribe?.(followMap);
|
||||
unsubscribeMap = typeof off === 'function' ? off : null;
|
||||
void drawOutline();
|
||||
if (outlineMode && !outlineZoom)
|
||||
outlineZoom = libraryDoubleClick(
|
||||
viewer,
|
||||
id,
|
||||
() => enabled,
|
||||
(hit) => (hit.set === outline?.id ? outlineItems.get(hit.id) : null),
|
||||
);
|
||||
requestRender(`library-tiles:${entry.id}`);
|
||||
},
|
||||
async disable() {
|
||||
@@ -655,8 +620,6 @@ export function createLibraryTileLayer(
|
||||
unsubscribeMap = null;
|
||||
detach();
|
||||
removeOutline();
|
||||
outlineZoom?.destroy();
|
||||
outlineZoom = null;
|
||||
requestRender(`library-tiles:${entry.id}`);
|
||||
},
|
||||
async destroy() {
|
||||
@@ -665,8 +628,6 @@ export function createLibraryTileLayer(
|
||||
unsubscribeMap = null;
|
||||
detach();
|
||||
removeOutline();
|
||||
outlineZoom?.destroy();
|
||||
outlineZoom = null;
|
||||
viewer = null;
|
||||
},
|
||||
getStats() {
|
||||
@@ -753,9 +714,6 @@ export function createLibraryViewLayer(
|
||||
let enabled = false;
|
||||
/** The sets drawing the current view's features, or null. */
|
||||
let drawn = null;
|
||||
/** Each build's items by set id, then item id, for a double-click. */
|
||||
const itemsOf = new WeakMap();
|
||||
let stockFollow = null;
|
||||
let builds = 0;
|
||||
let controller = null;
|
||||
let timer = null;
|
||||
@@ -786,8 +744,6 @@ export function createLibraryViewLayer(
|
||||
}
|
||||
|
||||
function clear() {
|
||||
// Removing the entities ended the default renderer's follow of one.
|
||||
stockFollow?.stop();
|
||||
disposeSets(drawn);
|
||||
drawn = null;
|
||||
loadedKey = null;
|
||||
@@ -859,19 +815,6 @@ export function createLibraryViewLayer(
|
||||
sets.fills.set(fills);
|
||||
sets.lines.set(lines);
|
||||
sets.dots.set(dots);
|
||||
itemsOf.set(
|
||||
sets,
|
||||
new Map(
|
||||
[
|
||||
[sets.fills.id, fills],
|
||||
[sets.lines.id, lines],
|
||||
[sets.dots.id, dots],
|
||||
].map(([setId, list]) => [
|
||||
setId,
|
||||
new Map(list.map((item) => [item.id, item])),
|
||||
]),
|
||||
),
|
||||
);
|
||||
} catch (caught) {
|
||||
disposeSets(sets);
|
||||
throw caught;
|
||||
@@ -964,8 +907,6 @@ export function createLibraryViewLayer(
|
||||
const previous = drawn;
|
||||
drawn = sets;
|
||||
for (const set of Object.values(sets)) set.show = true;
|
||||
// Replacing the entities ended the default renderer's follow of one.
|
||||
if (previous) stockFollow?.stop();
|
||||
disposeSets(previous);
|
||||
count = result.features.length;
|
||||
truncated = result.truncated;
|
||||
@@ -1017,28 +958,18 @@ export function createLibraryViewLayer(
|
||||
registerDynamicCredit(viewer, libraryCredit(entry));
|
||||
removeMoveEnd?.();
|
||||
removeMoveEnd = findCamera(viewer)?.on('moveEnd', schedule) ?? null;
|
||||
stockFollow ??= libraryDoubleClick(
|
||||
viewer,
|
||||
id,
|
||||
() => enabled,
|
||||
(hit) => (drawn ? itemsOf.get(drawn)?.get(hit.set)?.get(hit.id) : null),
|
||||
);
|
||||
await refresh();
|
||||
},
|
||||
async disable() {
|
||||
enabled = false;
|
||||
stop();
|
||||
clear();
|
||||
stockFollow?.destroy();
|
||||
stockFollow = null;
|
||||
render();
|
||||
},
|
||||
async destroy() {
|
||||
enabled = false;
|
||||
stop();
|
||||
clear();
|
||||
stockFollow?.destroy();
|
||||
stockFollow = null;
|
||||
viewer = null;
|
||||
},
|
||||
getStats() {
|
||||
|
||||
@@ -158,8 +158,6 @@ test('a bbox outline draws on the ground with the drape, and goes with it', asyn
|
||||
const [ring] = [...set.items.values()];
|
||||
assert.equal(ring.mode, 'draped');
|
||||
assert.equal(ring.positions.length, 5);
|
||||
assert.notEqual(set.spec.pickable, false, 'picked, as its entity was');
|
||||
assert.notEqual(ring.pickable, false);
|
||||
assert.equal(layer.getDiagnostics().outlineRings, 1);
|
||||
await layer.disable();
|
||||
assert.equal(set.disposed, true);
|
||||
|
||||
@@ -324,92 +324,3 @@ test('features draw as the GeoJSON loader drew them: rhumb edges and their own s
|
||||
assert.ok(line.positions.length > 40);
|
||||
await layer.destroy(viewer);
|
||||
});
|
||||
|
||||
test('a double-click follows a dot and zooms to an area, as their entities were; a new view ends the follow', async (t) => {
|
||||
const point = {
|
||||
type: 'Feature',
|
||||
geometry: { type: 'Point', coordinates: [-77.0295, 38.8905] },
|
||||
properties: { OCC_CLS: 'Government' },
|
||||
};
|
||||
const layer = createLibraryViewLayer(entry, {
|
||||
source: {
|
||||
loadDataset: async () => ({
|
||||
features: [polygon, point],
|
||||
truncated: false,
|
||||
}),
|
||||
},
|
||||
debounceMs: 0,
|
||||
});
|
||||
const viewer = { canvas: { clientWidth: 800, clientHeight: 600 } };
|
||||
const camera = fakeCameraPort();
|
||||
const follows = [];
|
||||
const flights = [];
|
||||
// A getter, defined so: Object.assign would copy its value once.
|
||||
Object.defineProperty(camera.port, 'followed', {
|
||||
get: () => follows.at(-1) ?? null,
|
||||
});
|
||||
Object.assign(camera.port, {
|
||||
follow: (target) => follows.push(target),
|
||||
flyToBounds: (sphere, options) => flights.push({ sphere, options }),
|
||||
controls: { minDistance: 1, maxDistance: Infinity },
|
||||
});
|
||||
let lon = -77.03;
|
||||
const centre = () => fromDegrees(lon, 38.89, 0);
|
||||
camera.setPose({
|
||||
lon,
|
||||
lat: 38.89,
|
||||
height: 2000,
|
||||
position: fromDegrees(lon, 38.89, 2000),
|
||||
});
|
||||
let pickAt = () => null;
|
||||
let dblclick = null;
|
||||
const { draw, unbind } = bindFakeDraw(viewer, {
|
||||
camera: camera.port,
|
||||
query: { pickEllipsoid: centre, pick: (x, y) => pickAt(x, y) },
|
||||
input: {
|
||||
onPointer: (type, fn) => {
|
||||
assert.equal(type, 'dblclick');
|
||||
dblclick = fn;
|
||||
return () => (dblclick = null);
|
||||
},
|
||||
stockEnabled: (name) => name === 'dblclickFollow',
|
||||
},
|
||||
});
|
||||
t.after(unbind);
|
||||
await layer.init(viewer);
|
||||
await layer.enable(viewer);
|
||||
const live = (role) =>
|
||||
[...draw.sets.values()].find(
|
||||
(s) => !s.disposed && s.spec.id.endsWith(role),
|
||||
);
|
||||
const at = { position: { x: 1, y: 1 } };
|
||||
|
||||
const fills = live(':fills');
|
||||
pickAt = () => ({ set: fills.spec.id, id: [...fills.items.keys()][0] });
|
||||
dblclick(at);
|
||||
assert.equal(flights.length, 1, 'an area is zoomed to');
|
||||
|
||||
const dots = live(':dots');
|
||||
pickAt = () => ({ set: dots.spec.id, id: [...dots.items.keys()][0] });
|
||||
dblclick(at);
|
||||
assert.equal(follows.length, 1, 'a dot is followed');
|
||||
assert.ok(camera.port.followed);
|
||||
const expected = fromDegrees(-77.0295, 38.8905, 0);
|
||||
const got = follows[0].position();
|
||||
assert.ok(
|
||||
Math.hypot(got.x - expected.x, got.y - expected.y, got.z - expected.z) <
|
||||
1e-6,
|
||||
);
|
||||
|
||||
// The camera settles elsewhere: the view is drawn anew, which ended a
|
||||
// follow of an entity it replaced.
|
||||
lon = -77.2;
|
||||
camera.setPose({ lon, position: fromDegrees(lon, 38.89, 2000) });
|
||||
camera.emit('moveEnd');
|
||||
await new Promise((resolve) => setTimeout(resolve, 5));
|
||||
assert.equal(camera.port.followed, null);
|
||||
|
||||
await layer.disable(viewer);
|
||||
assert.equal(dblclick, null, 'let go when disabled');
|
||||
await layer.destroy(viewer);
|
||||
});
|
||||
@@ -84,6 +84,11 @@ export function createApplicationViewer({ container, creditContainer }) {
|
||||
);
|
||||
try {
|
||||
viewer.targetFrameRate = 60;
|
||||
// No double-click follow or zoom: the Viewer's own (it tracked or
|
||||
// zoomed to the entity picked) is off. Following is a layer's click.
|
||||
viewer.screenSpaceEventHandler.removeInputAction(
|
||||
Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK,
|
||||
);
|
||||
// A phone pinch spans fewer screen pixels than desktop zoom gestures.
|
||||
// Keep Cesium's distance-aware zoom and collision limits, with less travel
|
||||
// required on touch-first screens. Mouse/trackpad sensitivity stays native.
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
import { packItemId, renderPackGeometry } from './geometry.js';
|
||||
import { fromDegrees } from '../../geo/ellipsoid.js';
|
||||
import { drawOf, findFrame, findInput } from '../../render/rendererOf.js';
|
||||
import {
|
||||
drawnItemTarget,
|
||||
followOnDoubleClick,
|
||||
} from '../../data/stockFollow.js';
|
||||
import { drawOf, findFrame } from '../../render/rendererOf.js';
|
||||
import { useDataPacksStore } from '../../ui/stores/dataPacks.js';
|
||||
import { applicationPinia } from '../../ui/vueRuntime.js';
|
||||
|
||||
@@ -70,40 +66,6 @@ export function createPackPresentations(
|
||||
cards = cards.filter((card) => card.key !== key);
|
||||
present();
|
||||
}
|
||||
// Each drawn point set's items by id: a double-click follows a pack's
|
||||
// point, as the default renderer followed the point entity it was (its
|
||||
// lines, polygons and images were primitives, which it never followed).
|
||||
const pointSets = new Map();
|
||||
let stockFollow = null;
|
||||
function followPoints(setId, items) {
|
||||
pointSets.set(setId, new Map(items.map((item) => [item.id, item])));
|
||||
if (stockFollow) return;
|
||||
// A scene that takes no input (or a headless one, with no page to take
|
||||
// it from) has no double-click.
|
||||
let input = null;
|
||||
try {
|
||||
input = findInput(viewer);
|
||||
} catch {
|
||||
input = null;
|
||||
}
|
||||
if (!input) return;
|
||||
stockFollow = followOnDoubleClick({
|
||||
viewer,
|
||||
inputFor: () => input,
|
||||
name: 'data-packs',
|
||||
enabled: () => true,
|
||||
targetFor: (hit) =>
|
||||
drawnItemTarget(hit.set, pointSets.get(hit.set)?.get(hit.id)),
|
||||
});
|
||||
}
|
||||
function unfollowPoints(setId) {
|
||||
if (!pointSets.delete(setId)) return;
|
||||
// Removing a followed entity ended the follow.
|
||||
stockFollow?.retain((key) => !key.startsWith(`${setId}:`));
|
||||
if (pointSets.size) return;
|
||||
stockFollow?.destroy();
|
||||
stockFollow = null;
|
||||
}
|
||||
function resource(pack) {
|
||||
const sets = [],
|
||||
urls = [],
|
||||
@@ -127,7 +89,6 @@ export function createPackPresentations(
|
||||
const set = drawOf(viewer)[kind]({ id: `data-pack:${++drawSets}` });
|
||||
sets.push(set);
|
||||
set.set(items);
|
||||
if (kind === 'points') followPoints(set.id, items);
|
||||
requestRender();
|
||||
return set.id;
|
||||
},
|
||||
@@ -165,10 +126,7 @@ export function createPackPresentations(
|
||||
for (const key of featureKeys.splice(0)) targets.delete(key);
|
||||
// The view stops a removed card's player as it goes.
|
||||
if (card) removeCard(card);
|
||||
for (const set of sets.splice(0)) {
|
||||
unfollowPoints(set.id);
|
||||
set.dispose();
|
||||
}
|
||||
for (const set of sets.splice(0)) set.dispose();
|
||||
if (labelSource) {
|
||||
labels.length = 0;
|
||||
overlayHost.clearSource(labelSource);
|
||||
|
||||
@@ -3,8 +3,6 @@ import assert from 'node:assert/strict';
|
||||
import { createPackPresentations } from './presentation.js';
|
||||
import { packItemId } from './geometry.js';
|
||||
import { bindFakeDraw } from '../../testSupport/fakeDrawPort.mjs';
|
||||
import { bindFakeGroundRenderer } from '../../testSupport/fakeGroundRenderer.mjs';
|
||||
import { fromDegrees } from '../../geo/ellipsoid.js';
|
||||
|
||||
test('abort releases an in-flight image URL before the decoder settles or the viewer is destroyed', async () => {
|
||||
let settle;
|
||||
@@ -304,80 +302,3 @@ test('an image pack draws its decoded pixels as a rectangle at its height', asyn
|
||||
else globalThis.document = priorDocument;
|
||||
}
|
||||
});
|
||||
|
||||
test('a double-click follows a pack point, as the point entity it was, and never a line or area', async (t) => {
|
||||
const viewer = { container: {} };
|
||||
const fake = bindFakeGroundRenderer(viewer);
|
||||
t.after(fake.unbind);
|
||||
let dblclick = null;
|
||||
fake.renderer.input = {
|
||||
onPointer(type, handler) {
|
||||
assert.equal(type, 'dblclick');
|
||||
dblclick = handler;
|
||||
return () => {
|
||||
dblclick = null;
|
||||
};
|
||||
},
|
||||
stockEnabled: (name) => name === 'dblclickFollow',
|
||||
};
|
||||
const ring = [
|
||||
[2, 1],
|
||||
[2.1, 1],
|
||||
[2.1, 1.1],
|
||||
[2, 1],
|
||||
];
|
||||
const bytes = new TextEncoder().encode(
|
||||
JSON.stringify({
|
||||
type: 'FeatureCollection',
|
||||
features: [
|
||||
{
|
||||
type: 'Feature',
|
||||
id: 'point',
|
||||
geometry: { type: 'Point', coordinates: [2, 1, 10] },
|
||||
},
|
||||
{
|
||||
type: 'Feature',
|
||||
id: 'area',
|
||||
geometry: { type: 'Polygon', coordinates: [ring] },
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
const handle = await createPackPresentations(viewer, new Map(), {
|
||||
store: { publish() {} },
|
||||
}).geojson({
|
||||
pack: { id: 'data', attribution: { text: 'Example', license: 'CC0' } },
|
||||
asset: { bytes, mimeType: 'application/geo+json' },
|
||||
signal: new AbortController().signal,
|
||||
});
|
||||
const points = fake.liveSets().find((record) => record.kind === 'points');
|
||||
const shapes = fake.liveSets().find((record) => record.kind === 'shapes');
|
||||
const at = { position: { x: 1, y: 2 } };
|
||||
|
||||
fake.setPick(() => ({ set: shapes.spec.id, id: packItemId('data', 'area') }));
|
||||
dblclick(at);
|
||||
assert.equal(
|
||||
fake.follows.length + fake.flights.length,
|
||||
0,
|
||||
'an area: nothing',
|
||||
);
|
||||
|
||||
fake.setPick(() => ({
|
||||
set: points.spec.id,
|
||||
id: packItemId('data', 'point'),
|
||||
}));
|
||||
dblclick(at);
|
||||
assert.equal(fake.follows.length, 1);
|
||||
const followed = fake.follows[0];
|
||||
const expected = fromDegrees(2, 1, 10);
|
||||
const got = followed.position();
|
||||
assert.ok(
|
||||
Math.hypot(got.x - expected.x, got.y - expected.y, got.z - expected.z) <
|
||||
1e-6,
|
||||
);
|
||||
|
||||
// Removing the pack ends the follow and lets the double-click go.
|
||||
handle.dispose();
|
||||
assert.equal(fake.renderer.camera.followed, null);
|
||||
assert.equal(dblclick, null);
|
||||
});
|
||||
@@ -13,11 +13,7 @@ import {
|
||||
import { bindRenderer } from '../render/rendererOf.js';
|
||||
import { entityFollowTarget } from '../data/followed.js';
|
||||
import { createCesiumInput } from '../render/cesium/input.js';
|
||||
import {
|
||||
routeSceneDoubleClick,
|
||||
onSceneDoubleClick,
|
||||
onScenePointerDown,
|
||||
} from './cockpitInput.js';
|
||||
import { routeSceneDoubleClick, onSceneDoubleClick } from './cockpitInput.js';
|
||||
import { inputFor } from '../input/dispatcher.js';
|
||||
|
||||
function harness(t, { stock = null } = {}) {
|
||||
@@ -28,9 +24,8 @@ function harness(t, { stock = null } = {}) {
|
||||
},
|
||||
clock: { currentTime: 0 },
|
||||
};
|
||||
// The followed aircraft is drawn at (100, 100), unless a test moves it.
|
||||
let drawnAt = { x: 100, y: 100 };
|
||||
const project = () => drawnAt;
|
||||
// The followed aircraft is drawn at (100, 100).
|
||||
const project = () => ({ x: 100, y: 100 });
|
||||
// With `stock`, the renderer's own input port takes the viewer's stock
|
||||
// double-click follow and runs it as the app's does; else the fake input.
|
||||
// The camera port follows the aircraft, as the flights layer's follow does.
|
||||
@@ -78,14 +73,7 @@ function harness(t, { stock = null } = {}) {
|
||||
stop();
|
||||
input.destroy();
|
||||
});
|
||||
return {
|
||||
input,
|
||||
controller,
|
||||
stop,
|
||||
moveTo: (at) => {
|
||||
drawnAt = at;
|
||||
},
|
||||
};
|
||||
return { input, controller, stop };
|
||||
}
|
||||
|
||||
/** The Cesium renderer's input port over a fake handler, with `follow` as
|
||||
@@ -261,34 +249,3 @@ test('an active Cockpit leaves presses alone, and stopping lets a hold go', (t)
|
||||
stop();
|
||||
assert.equal(controller.holds, 0);
|
||||
});
|
||||
|
||||
test('a ship moved by the first click still enters, with the stock follow held where it was', async (t) => {
|
||||
const follows = [];
|
||||
const { input, controller, moveTo } = harness(t, {
|
||||
stock: (event) => follows.push(event.position),
|
||||
});
|
||||
controller.resolveEntryKind = () => 'vessel';
|
||||
controller.readVesselInfo = () => ({
|
||||
id: 'ship-1',
|
||||
latitude: 37.8,
|
||||
longitude: -122.4,
|
||||
});
|
||||
const was = { x: 100, y: 100 };
|
||||
// The first press notes where the ship is drawn; its click re-centres the
|
||||
// camera, and the ship is drawn elsewhere by the second press.
|
||||
onScenePointerDown.call(controller);
|
||||
input.tap(was);
|
||||
moveTo({ x: 300, y: 100 });
|
||||
input.down(was);
|
||||
assert.equal(
|
||||
input.stockEnabled('dblclickFollow'),
|
||||
false,
|
||||
'held at the press where the ship was',
|
||||
);
|
||||
input.up(was);
|
||||
input.dblclick(was);
|
||||
assert.equal(controller.entered, 1);
|
||||
assert.equal(follows.length, 0, 'the stock follow never ran');
|
||||
await Promise.resolve();
|
||||
assert.equal(input.stockEnabled('dblclickFollow'), true);
|
||||
});
|
||||
+10
-24
@@ -96,26 +96,12 @@ export function onScenePointerDown(nowMs = performance.now()) {
|
||||
* refused by the gate: the caller does nothing else with it.
|
||||
*/
|
||||
export function onSceneDoubleClick(position, nowMs = performance.now()) {
|
||||
const hit = hitsFollowedTrack.call(this, position, nowMs);
|
||||
const start = this.doubleClickStart;
|
||||
this.doubleClickStart = null;
|
||||
if (this.active || this.destroyed || !isPointerFree()) return false;
|
||||
if (!Number.isFinite(position?.x) || !Number.isFinite(position?.y))
|
||||
return false;
|
||||
if (!hit) return false;
|
||||
this.enter();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether `position` is on the followed track: where it is drawn now, or
|
||||
* where a ship was drawn as this gesture's first press began (its click
|
||||
* may have moved it).
|
||||
*/
|
||||
function hitsFollowedTrack(position, nowMs) {
|
||||
if (!Number.isFinite(position?.x) || !Number.isFinite(position?.y))
|
||||
return false;
|
||||
const start = this.doubleClickStart;
|
||||
return (
|
||||
const hit =
|
||||
doubleClickHitsSubject(position, subjectCanvasPosition.call(this)) ||
|
||||
(Boolean(start) &&
|
||||
nowMs - start.atMs <= DOUBLE_CLICK_MEMORY_MS &&
|
||||
@@ -123,8 +109,10 @@ function hitsFollowedTrack(position, nowMs) {
|
||||
// aircraft, another ship) is hit only where it is drawn.
|
||||
this.resolveEntryKind() === 'vessel' &&
|
||||
start.vesselId === (this.readVesselInfo()?.id ?? null) &&
|
||||
doubleClickHitsSubject(position, start))
|
||||
);
|
||||
doubleClickHitsSubject(position, start));
|
||||
if (!hit) return false;
|
||||
this.enter();
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Hold the renderer's own double-click follow off; returns the release. */
|
||||
@@ -190,9 +178,7 @@ export function routeSceneDoubleClick() {
|
||||
isPointerFree() &&
|
||||
(this.active
|
||||
? Boolean(this.orbitalSiteUnder?.(position))
|
||||
: // Where the ship was as the gesture began counts too: the first
|
||||
// click may have moved it, and the double-click still enters.
|
||||
hitsFollowedTrack.call(this, position, performance.now()));
|
||||
: doubleClickHitsSubject(position, subjectCanvasPosition.call(this)));
|
||||
endsDouble =
|
||||
!!last?.onSubject &&
|
||||
at - last.at <= SUBJECT_PRESS_HOLD_MS &&
|
||||
@@ -214,9 +200,9 @@ export function routeSceneDoubleClick() {
|
||||
// retarget that would end the view.
|
||||
if (!this.onSceneDoubleClick(position))
|
||||
this.onOrbitalDoubleClick?.(position);
|
||||
// The hold covers the whole double-click: subscribers after this one
|
||||
// (a layer's own follow on a double-click) must still find the stock
|
||||
// follow held, so it is given back once the dispatch is over.
|
||||
// The hold covers the whole double-click: it is given back once the
|
||||
// dispatch is over.
|
||||
|
||||
queueMicrotask(drop);
|
||||
});
|
||||
return () => {
|
||||
|
||||
Reference in new issue
Block a user