fix(data-packs): a double-click follows a pack's point again

A pack's points and media marker were point entities, which the default
renderer's double-click followed; removing the pack ended the follow. As
draw-port points they took no part in it. Lines, polygons and images were
primitives before, so they still take none.
This commit is contained in:
Sameh Khamis committed 2026-11-14 01:29:22 -08:00
1 parent a9de7b3510
commit 9c4c831ba2
2 files changed
+117 -2

No files matched your search

+38 -2
View File
@@ -1,6 +1,10 @@
import { packItemId, renderPackGeometry } from './geometry.js';
import { fromDegrees } from '../../geo/ellipsoid.js';
import { drawOf, findFrame } from '../../render/rendererOf.js';
import { drawOf, findFrame, findInput } from '../../render/rendererOf.js';
import {
drawnItemTarget,
followOnDoubleClick,
} from '../../data/stockFollow.js';
import { useDataPacksStore } from '../../ui/stores/dataPacks.js';
import { applicationPinia } from '../../ui/vueRuntime.js';
@@ -66,6 +70,34 @@ 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 has no double-click.
const input = findInput(viewer);
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 = [],
@@ -89,6 +121,7 @@ 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;
},
@@ -126,7 +159,10 @@ 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)) set.dispose();
for (const set of sets.splice(0)) {
unfollowPoints(set.id);
set.dispose();
}
if (labelSource) {
labels.length = 0;
overlayHost.clearSource(labelSource);
@@ -3,6 +3,8 @@ 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;
@@ -302,3 +304,80 @@ 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);
});