I am building a drone tracker which updates the drone’s position in realtime. I use “heightReference: HeightReference.RELATIVE_TO_GROUND” on my drone model, to visualise its actual position above ground.
I wish to draw a line which shows a “power output” for a specific coordinate on its flight path. But the flight path appears way below the drone due to “HeightReference.RELATIVE_TO_GROUND”.
Is there a way to get my entity’s actual current position, so i can draw the line corresponding to the drone’s real position?
i draw the flight path as such:
update(lon: number, lat: number, alt: number, color: Color) {
const newPosition = Cartesian3.fromDegrees(lon, lat, alt);
// Add the new position and color to the arrays
this.positions.push(newPosition);
this.colors.push(color);
// If the primitive exists, remove it before creating the updated one
if (this.primitive) {
this.viewer.scene.primitives.remove(this.primitive);
}
// Create a new primitive with updated geometry
if (this.positions.length > 1) {
this.createPrimitive();
}
}
private createPrimitive() {
if (!this.viewer) {
return
}
const geometry = new PolylineGeometry({
positions: this.positions,
vertexFormat: PolylineColorAppearance.VERTEX_FORMAT,
colors: this.colors,
colorsPerVertex: true,
width: 5
});
const geometryInstance = new GeometryInstance({
geometry: geometry,
});
this.primitive = new Primitive({
geometryInstances: geometryInstance,
appearance: new PolylineColorAppearance(),
asynchronous: false
});
this.viewer.scene.primitives.add(this.primitive);
}
And i give the exact same coordinates when moving the drone as when updating the flight path:
this.moveDrone(lon, lat, alt);
const color = this.getColorForPower(power);
this.flightPath.update(lon, lat, alt, color);