From 0e8be0fb789b95612ad398864004fc2f62355997 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Wed, 11 Nov 2026 15:52:56 -0800 Subject: [PATCH] Icons turned about an axis stand along it on the Cesium port's billboards rotationMode 'axis' was drawn upright: the item's alignedAxis now becomes the billboard's (normalised), and a changed axis restyles it in place. --- src/render/cesium/draw.js | 17 +++++++++++++++++ src/render/cesium/draw.test.mjs | 29 +++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/src/render/cesium/draw.js b/src/render/cesium/draw.js index a50a3813d..788bca101 100644 --- a/src/render/cesium/draw.js +++ b/src/render/cesium/draw.js @@ -976,6 +976,15 @@ export function createCesiumDraw({ ), }; if (item.rotationMode === 'screen') look.rotation = item.rotation ?? 0; + // Its up turned along the axis on screen, as Cesium's own aligned + // billboards stand; an axis of zero length stands upright. + if (item.rotationMode === 'axis' && item.alignedAxis) { + const { x = 0, y = 0, z = 0 } = item.alignedAxis; + const axis = new Cesium.Cartesian3(x, y, z); + const length = Cesium.Cartesian3.magnitude(axis); + if (length > 0) + look.alignedAxis = Cesium.Cartesian3.divideByScalar(axis, length, axis); + } if (item.rotationMode === 'course') { const enu = Cesium.Transforms.eastNorthUpToFixedFrame(position); look.alignedAxis = Cesium.Matrix4.multiplyByPointAsVector( @@ -1015,6 +1024,9 @@ export function createCesiumDraw({ fadeByDistance: curve(item.fadeByDistance), rotationMode: item.rotationMode, rotation: item.rotation, + alignedAxis: item.alignedAxis + ? [item.alignedAxis.x, item.alignedAxis.y, item.alignedAxis.z] + : undefined, course: item.course, pixelOffset: item.pixelOffset ? [item.pixelOffset.x ?? 0, item.pixelOffset.y ?? 0] @@ -1065,6 +1077,11 @@ export function createCesiumDraw({ sameCurve(style.fadeByDistance, item.fadeByDistance) && style.rotationMode === item.rotationMode && (item.rotationMode === 'screen' || style.rotation === item.rotation) && + (item.alignedAxis + ? style.alignedAxis?.[0] === item.alignedAxis.x && + style.alignedAxis[1] === item.alignedAxis.y && + style.alignedAxis[2] === item.alignedAxis.z + : style.alignedAxis === undefined) && style.course === item.course && (item.pixelOffset ? style.pixelOffset?.[0] === (item.pixelOffset.x ?? 0) && diff --git a/src/render/cesium/draw.test.mjs b/src/render/cesium/draw.test.mjs index aa796a115..28c930dc0 100644 --- a/src/render/cesium/draw.test.mjs +++ b/src/render/cesium/draw.test.mjs @@ -3352,6 +3352,35 @@ test('an icon stands off its position by its pixel offset, and back when it has set.dispose(); }); +test('an icon turned about an axis stands along it, restyled in place when the axis changes', () => { + const { scene, draw } = drawOver(); + const set = draw.icons({ id: 'axis-pins' }); + const icon = (alignedAxis) => ({ + id: 'a', + pos: { lon: 0, lat: 0 }, + image: 'pin.png', + size: [8, 8], + rotationMode: 'axis', + alignedAxis, + }); + set.set([icon({ x: 0, y: 0, z: 2 })]); + const pin = () => scene.added[0].get(0); + const axis = () => [ + pin().alignedAxis.x, + pin().alignedAxis.y, + pin().alignedAxis.z, + ]; + assert.deepEqual(axis(), [0, 0, 1], 'normalised'); + assert.equal(pin().rotation, 0); + const drawn = pin(); + set.upsert([icon({ x: 0, y: 1, z: 0 })]); + assert.equal(pin(), drawn, 'the same billboard'); + assert.deepEqual(axis(), [0, 1, 0]); + set.upsert([{ ...icon(undefined), rotationMode: 'screen' }]); + assert.deepEqual(axis(), [0, 0, 0], 'upright again'); + set.dispose(); +}); + test('a wall stands up from the ellipsoid to its positions, with or without a fill', () => { const { scene, draw } = drawOver(); const set = draw.shapes({ id: 'walls' });