mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Build the selected vessel's trail without Cesium
Trail vertices are geo/ellipsoid positions and the minimum move is measured with geo/vector, both giving what the Cesium calls gave. Re-anchoring rows when the geoid loads asks the rendering part for the anchor, now one function prepareRecordVisual shares, so icon positions stay Cesium values. The shared trail renderer takes plain ECEF positions as well, turning them into Cartesian3s for its polyline; the Cartesian3s other layers hand it pass through untouched. tracking leaves the Cesium allow-list.
This commit is contained in:
1 parent
1c840cb66f
commit
e327760074
6 files changed
+224
-26
No files matched your search
@@ -49,7 +49,7 @@ const MIN_SEGMENT_DISTANCE_SQ = 0.01;
|
||||
* @param {object} options - Trail options.
|
||||
* @param {string} options.color - CSS color string for the trail hue.
|
||||
* @param {number} [options.width=2.5] - Polyline width in pixels.
|
||||
* @returns {{setPositions: function(Cesium.Cartesian3[]): void, setVisible: function(boolean): void, clear: function(): void, destroy: function(): void}}
|
||||
* @returns {{setPositions: function(Array<Cesium.Cartesian3|{x: number, y: number, z: number}>): void, setVisible: function(boolean): void, clear: function(): void, destroy: function(): void}}
|
||||
* Trail handle: setPositions replaces the geometry, setVisible temporarily
|
||||
* hides it without discarding history, clear empties it, and destroy removes
|
||||
* the entity permanently.
|
||||
@@ -92,7 +92,8 @@ export function createTrail(viewer, { color, width = 2.5 }) {
|
||||
/**
|
||||
* Replace the trail geometry with a chronological position list
|
||||
* (oldest first). Fewer than 2 distinct positions clears the trail.
|
||||
* @param {Cesium.Cartesian3[]} cartesians - Positions, oldest -> newest.
|
||||
* @param {Array<Cesium.Cartesian3|{x: number, y: number, z: number}>} cartesians
|
||||
* ECEF positions, oldest -> newest.
|
||||
*/
|
||||
setPositions(cartesians) {
|
||||
if (destroyed || !viewer || viewer.isDestroyed()) return;
|
||||
@@ -107,7 +108,12 @@ export function createTrail(viewer, { color, width = 2.5 }) {
|
||||
MIN_SEGMENT_DISTANCE_SQ
|
||||
)
|
||||
continue;
|
||||
positions.push(position);
|
||||
// Callers may hand plain ECEF {x, y, z}: the polyline gets Cartesian3s.
|
||||
positions.push(
|
||||
position instanceof Cesium.Cartesian3
|
||||
? position
|
||||
: new Cesium.Cartesian3(position.x, position.y, position.z),
|
||||
);
|
||||
}
|
||||
current = positions.length >= 2 ? positions : [];
|
||||
ensureEntity();
|
||||
|
||||
@@ -37,3 +37,26 @@ test('trail visibility can change without discarding its accumulated geometry',
|
||||
trail.destroy();
|
||||
assert.deepEqual(removed, [added[0]]);
|
||||
});
|
||||
|
||||
test('trail positions may be plain ECEF: the polyline still draws Cartesian3s', () => {
|
||||
const added = [];
|
||||
const viewer = {
|
||||
isDestroyed: () => false,
|
||||
entities: {
|
||||
add(definition) {
|
||||
added.push(definition);
|
||||
return definition;
|
||||
},
|
||||
remove() {},
|
||||
},
|
||||
};
|
||||
const trail = createTrail(viewer, { color: '#ffffff' });
|
||||
const given = new Cesium.Cartesian3(1, 2, 3);
|
||||
trail.setPositions([given, { x: 1, y: 2, z: 3.01 }, { x: 4, y: 5, z: 6 }]);
|
||||
const drawn = added[0].polyline.positions.getValue();
|
||||
// The near-duplicate merges; a Cartesian3 given passes through as it is.
|
||||
assert.equal(drawn.length, 2);
|
||||
assert.equal(drawn[0], given);
|
||||
assert.ok(drawn[1] instanceof Cesium.Cartesian3);
|
||||
assert.deepEqual([drawn[1].x, drawn[1].y, drawn[1].z], [4, 5, 6]);
|
||||
});
|
||||
Reference in new issue
Block a user