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:
Sameh Khamis committed 2026-11-14 09:10:14 -08:00
1 parent bb2d22dbce
commit b86014244d
69 files changed
+94 -2797

No files matched your search

+4 -114
View File
@@ -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,
-12
View File
@@ -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;
},
};
}
+1 -105
View File
@@ -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();
});