I want to change a point’s height by mouse, only height , because longitude and latitude was fixed. please tell me the answer.

Hi there,
You will likely want to convert Cartesian3 positions into Cartographic positions in order to perform this action.
Thanks for the reply.
I tried, but the mouse’s position is out of the earth,it dosen’t work
I would suggest avoiding picking to chose the position on the globe, and instead offset the height based on how much the mouse position itself has moved. You can use the MOUSE_MOVE event for this (or a native handler if you prefer).
May I ask how to implement this function? I also want the same function, but I haven’t found a suitable solution. Thank you
Hi @ruihua-code,
I can give some more pointers. What Gabby is referring to is the ScreenSpaceEventHandler class. You can use it to register a callback function that is invoked any time the mouse moves or is clicked (as two examples).
Here’s a sandcastle example that uses the ScreenSpaceEventHandler.
The solution you’re looking for will probably do something like this:
- Get the mouse start and end position (in screen space) from this handler callback
- Project those positions into world space (using your point’s position as the reference depth for projection)
- Connect the world start and world end positions of the mouse to form a vector.
- Take the dot product of that vector and the globe’s geodetic surface normal at your point’s position.
- Change the point’s height by that amount.
And here’s a sandcastle I had AI generate based on my description above (I tweaked it a bit to actually run without errors, but I would still suggest reviewing it thoroughly if you’re going to use it). Works surprisingly well!
Thank you very much. This sample code is amazing. It’s exactly the effect I wanted.