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.
This commit is contained in:
Sameh Khamis committed 2026-11-14 02:03:26 -08:00
1 parent 7ba15deb5e
commit 91b080a45a
4 files changed
+16 -3

No files matched your search

+2
View File
@@ -274,6 +274,8 @@ function kmlPin(name, style, at, mode) {
course: billboard.course, course: billboard.course,
pixelOffset: billboard.pixelOffset, pixelOffset: billboard.pixelOffset,
scaleByDistance: KML_ICON_SCALE_BY_DISTANCE, scaleByDistance: KML_ICON_SCALE_BY_DISTANCE,
// Its hot spot's offset shrinks with it, as Cesium's KML icons' did.
offsetScalesByDistance: true,
}; };
} }
+1
View File
@@ -58,6 +58,7 @@ test('a placemark takes its last inline style over its shared one, property by p
far: 1.6093e7, far: 1.6093e7,
farValue: 0.1, farValue: 0.1,
}); });
assert.equal(f.offsetScalesByDistance, true, 'its offset shrinks too');
} }
}); });
+6 -2
View File
@@ -127,9 +127,13 @@ export function createImportedDrawing(
if (pin.anchor) item.anchor = pin.anchor; if (pin.anchor) item.anchor = pin.anchor;
if (pin.scaleByDistance) item.scaleByDistance = pin.scaleByDistance; if (pin.scaleByDistance) item.scaleByDistance = pin.scaleByDistance;
if (pin.pixelOffset) item.pixelOffset = pin.pixelOffset; if (pin.pixelOffset) item.pixelOffset = pin.pixelOffset;
if (pin.offsetScalesByDistance) item.offsetScalesByDistance = true;
if (pin.course !== undefined) { if (pin.course !== undefined) {
item.rotationMode = 'course'; // Turned clockwise by its heading from the Earth's axis as it stands
item.course = pin.course; // 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. // On the ground or above it, drawn over what is in front.
if (pin.mode !== 'absolute') item.disableDepthTest = Infinity; if (pin.mode !== 'absolute') item.disableDepthTest = Infinity;
+7 -1
View File
@@ -19,6 +19,7 @@ const FEATURES = [
course: 90, course: 90,
pixelOffset: { x: 0, y: -16 }, pixelOffset: { x: 0, y: -16 },
scaleByDistance: { near: 1, nearValue: 1, far: 2, farValue: 0.1 }, scaleByDistance: { near: 1, nearValue: 1, far: 2, farValue: 0.1 },
offsetScalesByDistance: true,
}, },
{ kind: 'pin', lon: 3, lat: 4, height: 0, mode: 'clamp', image: null }, { 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], [pin.image, pin.size, pin.scale, pin.color],
['blob:icon', [32, 32], 1.5, [1, 0, 0, 1]], ['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.deepEqual(pin.pixelOffset, { x: 0, y: -16 });
assert.equal(pin.offsetScalesByDistance, true);
assert.equal(pin.scaleByDistance.farValue, 0.1); assert.equal(pin.scaleByDistance.farValue, 0.1);
assert.equal(pin.disableDepthTest, undefined, 'at its own height'); assert.equal(pin.disableDepthTest, undefined, 'at its own height');
assert.deepEqual(pin.meta, { name: 'tower' }); assert.deepEqual(pin.meta, { name: 'tower' });