From 9d3e99c8315338e7e2ef6afe79494fdae546e4e5 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Wed, 11 Nov 2026 19:29:04 -0800 Subject: [PATCH] Cesium draw: a clustered icon set clusters again after setColumns The wrapper that marks a clustered set for clustering again ran before setColumns was assigned, so column changes never reclustered; with no rows moving, positions or shown written by columns left the old clusters drawn. setColumns is now assigned first and wrapped with the rest. --- src/render/cesium/draw.js | 23 ++++++------- src/render/cesium/gpuIcons.test.mjs | 51 +++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 11 deletions(-) diff --git a/src/render/cesium/draw.js b/src/render/cesium/draw.js index b88fef27d..81fbb452f 100644 --- a/src/render/cesium/draw.js +++ b/src/render/cesium/draw.js @@ -647,7 +647,18 @@ export function createCesiumDraw({ requestRender(); }, }; - // A clustered set clusters again in the next frame drawn after a change. + // `columns`: column updates of an icon set, on the GPU. + if (kind === 'icons' && capabilities.has('columns')) + handle.setColumns = (columns) => { + onGpu(record, [], false, true); + record.gpu.columns(columns); + patched(); + }; + // Any other set takes columns as the rows they make, replacing its items. + else if (capabilities.has('columns')) + handle.setColumns = (columns) => handle.set(columnRows(columns, items)); + // A clustered set clusters again in the next frame drawn after a change + // (`setColumns` too: set before this, so it is wrapped with the rest). for (const name of [ 'set', 'upsert', @@ -722,16 +733,6 @@ export function createCesiumDraw({ handle.upsert([...record.inertialDraped.values()]); }; } - // `columns`: column updates of an icon set, on the GPU. - if (kind === 'icons' && capabilities.has('columns')) - handle.setColumns = (columns) => { - onGpu(record, [], false, true); - record.gpu.columns(columns); - patched(); - }; - // Any other set takes columns as the rows they make, replacing its items. - else if (capabilities.has('columns')) - handle.setColumns = (columns) => handle.set(columnRows(columns, items)); sets.set(spec.id, record); setsVersion += 1; return handle; diff --git a/src/render/cesium/gpuIcons.test.mjs b/src/render/cesium/gpuIcons.test.mjs index 1179ecfcb..74dda5a0d 100644 --- a/src/render/cesium/gpuIcons.test.mjs +++ b/src/render/cesium/gpuIcons.test.mjs @@ -580,6 +580,57 @@ test('a GPU icon set clusters its rows where their segments put them in the fram } }); +test('a clustered GPU icon set clusters again after static column changes', () => { + const transforms = Cesium.SceneTransforms; + const project = transforms.worldToWindowCoordinates; + transforms.worldToWindowCoordinates = (_, position, result) => { + const at = Cesium.Cartographic.fromCartesian(position); + result ??= new Cesium.Cartesian2(); + result.x = 200 + Cesium.Math.toDegrees(at.longitude) * 100; + result.y = 150 - Cesium.Math.toDegrees(at.latitude) * 100; + return result; + }; + try { + const { part, draw, scene } = drawOver({ + capabilities: new Set(['columns', 'cluster']), + }); + scene.camera.directionWC = new Cesium.Cartesian3(-1, 0, 0); + scene.camera.positionCartographic = { height: 1000 }; + scene.canvas = { clientWidth: 400, clientHeight: 300 }; + const counts = []; + const set = draw.icons({ + id: 'gpu:cluster-columns', + cluster: { + pixelRange: 10, + minimumSize: 2, + icon: (count) => (counts.push(count), 'badge.png'), + }, + }); + const at = (lon) => ecef(Cesium.Cartesian3.fromDegrees(lon, 0)); + set.set([ + icon('a', { pos: at(0), size: [8, 8] }), + icon('b', { pos: at(1), size: [8, 8] }), + ]); + set.setColumns({ ids: ['a', 'b'] }); + // Apart (100 px a degree): no cluster. + part.beforeRender(); + assert.deepEqual(counts, []); + const flat = (...points) => + new Float64Array(points.flatMap((p) => [p.x, p.y, p.z])); + // Positions only, nothing moving, the camera still: together now. + set.setColumns({ ids: ['a', 'b'], positions: flat(at(0), at(0.01)) }); + part.beforeRender(); + assert.deepEqual(counts, [2], 'clustered where the columns put them'); + // Shown only: one hidden, no cluster left. + set.setColumns({ ids: ['a', 'b'], shown: new Uint8Array([1, 0]) }); + part.beforeRender(); + assert.equal(part.sets.get('gpu:cluster-columns').clusterHost.length, 0); + set.dispose(); + } finally { + transforms.worldToWindowCoordinates = project; + } +}); + test('columns update rows by index: positions, courses, shown, scales, tints and meta', () => { const { part, draw } = drawOver(); const set = draw.icons({ id: 'gpu:columns' });