From 91b080a45af3aabdd9a421d007af3d01bd0c08e4 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Sat, 14 Nov 2026 02:03:26 -0800 Subject: [PATCH] fix(geo-import): KML icons stay on their points when zoomed out, and turn by heading as before Cesium's KML loader shrank an icon's hot-spot offset with the icon and turned a heading about the Earth's axis. The drawn pins kept the full offset at globe distance (up to ~14 px off for the Google Earth pushpin) and turned about local north, which differs in a tilted view. They now scale the offset with the icon and turn about the Earth's axis by the heading. --- src/data/geoImportFeatures.js | 2 ++ src/data/geoImportFeatures.test.mjs | 1 + src/data/geoImportPins.js | 8 ++++++-- src/data/geoImportPins.test.mjs | 8 +++++++- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/data/geoImportFeatures.js b/src/data/geoImportFeatures.js index 56ac86197..349a0da6b 100644 --- a/src/data/geoImportFeatures.js +++ b/src/data/geoImportFeatures.js @@ -274,6 +274,8 @@ function kmlPin(name, style, at, mode) { course: billboard.course, pixelOffset: billboard.pixelOffset, scaleByDistance: KML_ICON_SCALE_BY_DISTANCE, + // Its hot spot's offset shrinks with it, as Cesium's KML icons' did. + offsetScalesByDistance: true, }; } diff --git a/src/data/geoImportFeatures.test.mjs b/src/data/geoImportFeatures.test.mjs index 1997bb52b..b0dd4953c 100644 --- a/src/data/geoImportFeatures.test.mjs +++ b/src/data/geoImportFeatures.test.mjs @@ -58,6 +58,7 @@ test('a placemark takes its last inline style over its shared one, property by p far: 1.6093e7, farValue: 0.1, }); + assert.equal(f.offsetScalesByDistance, true, 'its offset shrinks too'); } }); diff --git a/src/data/geoImportPins.js b/src/data/geoImportPins.js index 3c5f873b5..597aca2cf 100644 --- a/src/data/geoImportPins.js +++ b/src/data/geoImportPins.js @@ -127,9 +127,13 @@ export function createImportedDrawing( if (pin.anchor) item.anchor = pin.anchor; if (pin.scaleByDistance) item.scaleByDistance = pin.scaleByDistance; if (pin.pixelOffset) item.pixelOffset = pin.pixelOffset; + if (pin.offsetScalesByDistance) item.offsetScalesByDistance = true; if (pin.course !== undefined) { - item.rotationMode = 'course'; - item.course = pin.course; + // Turned clockwise by its heading from the Earth's axis as it stands + // on screen, as Cesium's KML icons were. + item.rotationMode = 'axis'; + item.alignedAxis = { x: 0, y: 0, z: 1 }; + item.rotation = (-pin.course * Math.PI) / 180; } // On the ground or above it, drawn over what is in front. if (pin.mode !== 'absolute') item.disableDepthTest = Infinity; diff --git a/src/data/geoImportPins.test.mjs b/src/data/geoImportPins.test.mjs index 52335b482..0924feea5 100644 --- a/src/data/geoImportPins.test.mjs +++ b/src/data/geoImportPins.test.mjs @@ -19,6 +19,7 @@ const FEATURES = [ course: 90, pixelOffset: { x: 0, y: -16 }, scaleByDistance: { near: 1, nearValue: 1, far: 2, farValue: 0.1 }, + offsetScalesByDistance: true, }, { kind: 'pin', lon: 3, lat: 4, height: 0, mode: 'clamp', image: null }, { @@ -102,8 +103,13 @@ test('pins draw as icons with the look their file gave them', (t) => { [pin.image, pin.size, pin.scale, pin.color], ['blob:icon', [32, 32], 1.5, [1, 0, 0, 1]], ); - assert.deepEqual([pin.rotationMode, pin.course], ['course', 90]); + // As Cesium's KML icon: turned by its heading from the Earth's axis. + assert.deepEqual( + [pin.rotationMode, pin.alignedAxis, pin.rotation], + ['axis', { x: 0, y: 0, z: 1 }, -Math.PI / 2], + ); assert.deepEqual(pin.pixelOffset, { x: 0, y: -16 }); + assert.equal(pin.offsetScalesByDistance, true); assert.equal(pin.scaleByDistance.farValue, 0.1); assert.equal(pin.disableDepthTest, undefined, 'at its own height'); assert.deepEqual(pin.meta, { name: 'tower' });