Having to convert to Cartesian3 two times in order to set elevation

1. A concise explanation of the problem you’re experiencing.

Greetings everyone, I’m a little confused on how to do this right. My current code works, but I doubt it is the most efficient way to do it. Below you’ll see a similar setup to the Sand Castle demo for Cesium where the user is allowed to draw a line. I’ve set it up this scenario with similar variable names to avoid confusion as much as I can.

Anyway, once an event occurs I’m getting Cartesian values using “pickEllipsoid”, but since the client needs the elevation to be set at a default (this is for aircraft) I’m then having to convert it to latitude and longitude only to convert those values back into Cartesian alongside a custom elevation of “30000”.

Is there anyway to just feed pickEllipsoid a default elevation in order to skip one of these steps? I’m feel sure I’ve just missed something in the documentation.

2. A minimal code example. If you’ve found a bug, this helps us reproduce and repair it.

handler.setInputAction(function(e) {

let mousePosition = e.position

let ellipsoid = viewer.scene.globe.ellipsoid

// Converts to cartesian3

let earthPosition = viewer.camera.pickEllipsoid(mousePosition, ellipsoid)

if (Cesium.defined(earthPosition)) {

// Converts cartesian3 to latitude and longitude

let cartographic = ellipsoid.cartesianToCartographic(earthPosition)

let long = Cesium.Math.toDegrees(cartographic.longitude)

let lat = Cesium.Math.toDegrees(cartographic.latitude)

// Converts back to cartesian3 along with custom elevation

let coords = Cesium.Cartesian3.fromDegrees(long, lat, 30000)

if (activeShapePoints.length === 0) {

floatingPoint = createPoint(coords)

activeShapePoints.push(coords)

let dynamicPositions = new Cesium.CallbackProperty(function (time, result) {

return activeShapePoints

}, false)

activeShape = drawShape(dynamicPositions, 5, cString)

}

activeShapePoints.push(coords)

createPoint(coords)

}

}, Cesium.ScreenSpaceEventType.LEFT_CLICK)

handler.setInputAction(function(event) {

if (Cesium.defined(floatingPoint)) {

let ellipsoid = viewer.scene.globe.ellipsoid

console.log(event.endPosition)

// Converts to cartesian3

let earthPosition = viewer.camera.pickEllipsoid(event.endPosition, ellipsoid)

// Converts cartesian to latitude and longitude

if (Cesium.defined(earthPosition)) {

let cartographic = ellipsoid.cartesianToCartographic(earthPosition)

let long = Cesium.Math.toDegrees(cartographic.longitude)

let lat = Cesium.Math.toDegrees(cartographic.latitude)

// Converts back to cartesian3 along with custom elevation

let coords = Cesium.Cartesian3.fromDegrees(long, lat, 30000)

floatingPoint.position.setValue(coords)

activeShapePoints.pop()

activeShapePoints.push(coords)

}

}

}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);

3. Context. Why do you need to do this? We might know a better way to accomplish your goal.

This is needed due to my client needing to the ability to draw routes for aircraft.

4. The Cesium version you’re using, your operating system and browser.

**Cesium **1.55.0

**Browser: Google Chrome **Version 75.0.3770.90

This is a little verbose, but I think this is the right way to do it. If entities can take a Cartographic position you could just modify the height directly and pass that, but I’m not sure if they do off the top of my head.

It’s not any less efficient or anything for runtime performance, I think these conversions are negligible in the grand scheme of things if that’s your worry. What kind of application/project are you working on?

Thanks for the response. Yes, I was concerned about performance. This is for a mission planning tool that will handle logistics for aircraft, ships and/or vehicles.