fix(library): a double-click follows a view dot and zooms to a view area or coverage border again

A view-bounded layer's features and a tile entry's coverage outline were
entities, which the default renderer's double-click followed (points) or
zoomed to (lines and areas); a new view replaced them and ended the
follow. As draw-port items they took no part in it, and the outline was
drawn unpickable. It is picked again, as its entities were.
This commit is contained in:
Sameh Khamis committed 2026-11-14 01:34:13 -08:00
1 parent 898909c245
commit df0afa82e1
3 files changed
+172 -12

No files matched your search

+89
View File
@@ -324,3 +324,92 @@ 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);
});