Icon sets cluster on the Cesium renderer

Clustered icon sets cluster with clusterScreenPoints over the shown icons
each frame drawn after the camera moves or the set changes. A cluster draws
one icon (icon(count), else a count badge) at its members' mean in place of
the members; a pick on it answers each member, seed first, at the cluster's
position. GPU icon sets refuse clustering. The stub clusters the same way,
the contract documents the semantics, and the check draw.icons.cluster
covers it.
This commit is contained in:
Sameh Khamis committed 2026-11-11 16:33:21 -08:00
1 parent d497435b61
commit a4a4366b13
12 files changed
+583 -11

No files matched your search

+105
View File
@@ -1714,6 +1714,111 @@ export function portChecks() {
for (const set of sets) set.dispose();
},
),
check(
'draw.icons.cluster',
'icons close on screen draw as one cluster, picked as its members seed first at its position; apart again, each is its own',
async (h, r) => {
await overAustin(h, r, 2000);
const counts = [];
const set = r.draw.icons({
id: 'conf:cluster',
cluster: {
pixelRange: 20,
minimumSize: 3,
icon: (count) => {
counts.push(count);
return DOT;
},
},
});
const at = (dx, dy) =>
h.toEcef({
lon: AUSTIN.lon + 0.0008 + dx * 0.0003,
lat: AUSTIN.lat + 0.0006 + dy * 0.0003,
height: 0,
});
const members = [
['a', at(0, 0)],
['b', at(1, 0)],
['c', at(0, 1)],
['d', at(1, 1)],
];
const far = h.toEcef({
lon: AUSTIN.lon - 0.003,
lat: AUSTIN.lat - 0.002,
height: 0,
});
set.set([
...members.map(([id, pos]) => ({
id,
pos,
image: DOT,
size: [16, 16],
meta: { m: id },
})),
{ id: 'far', pos: far, image: DOT, size: [16, 16] },
]);
await drawn(h, r);
await settled(r);
await drawn(h, r);
ok(counts.includes(4), 'the icon is drawn for its count');
const mean = members.reduce(
(m, [, p]) => ({
x: m.x + p.x / members.length,
y: m.y + p.y / members.length,
z: m.z + p.z / members.length,
}),
{ x: 0, y: 0, z: 0 },
);
const s = r.query.project(mean);
ok(s, 'the cluster projects');
const hit = r.query.pick(s.x, s.y);
deepEqual(
[hit?.set, hit?.id, hit?.meta],
['conf:cluster', 'a', { m: 'a' }],
'pick gives the seed, with its own meta',
);
ok(hit?.position, 'at a position');
nearVec(hit.position, mean, 1, 'the cluster’s position');
const drilled = r.query
.drillPick(s.x, s.y)
.filter((x) => x.set === 'conf:cluster');
deepEqual(
drilled.map((x) => [x.id, x.meta?.m]),
members.map(([id]) => [id, id]),
'drillPick gives every member, seed first',
);
const sf = r.query.project(far);
equal(r.query.pick(sf.x, sf.y)?.id, 'far', 'an icon on its own');
await overAustin(h, r, 300);
r.camera.setView({
destination: {
lon: AUSTIN.lon + 0.00095,
lat: AUSTIN.lat + 0.00075,
height: 300,
},
orientation: { heading: 0, pitch: -Math.PI / 2, roll: 0 },
});
await drawn(h, r);
await settled(r);
await drawn(h, r);
for (const [id, pos] of members) {
const m = r.query.project(pos);
ok(m, `${id} projects`);
deepEqual(
r.query
.drillPick(m.x, m.y)
.filter((x) => x.set === 'conf:cluster')
.map((x) => x.id),
[id],
`${id} on its own once apart`,
);
}
set.dispose();
},
{ capability: 'cluster' },
),
check(
'draw.icons.update',
'an upserted icon keeps drawing, as it now is, from the next frame: picked at its new size with its new meta, even while a new image loads; a removed one is gone',