Get Elevation with camera far from the earth

I created this example for testing (For now I'm using only the 3d version, no 2d or columbus):

In this example I show the elevation in the toolbar on mouse move.
Anyway, when you are far from the earth, the elevation values become wrong (negative values around -10000 - -20000).

I suppose the problem is that when you have a few poligons to represent whole earth, they cuts the ellipsoid going down the level of the sea of many kilometers.
If this is the problem, increasing the resolution at l0,1,2... can solve the problem, but too many points are required to approximate the whole earth.

I guessed it or the problem is another?
Do you know if there is a way to get a consistent elevation even when the camera is far from the earth?

Thank you in advance for your time.


Using getPickRay returns the intersection between a ray from the camera to the mouse position and the terrain tile that is loaded into the scene at that position. This changes based on the camera position because the terrain has a higher level of detail when the camera is closer to the tile and lower when the camera is far away.

To get consistent results, you can use sampleTerrain to query the terrain for a height at a specific level of detail.



Than you very much.
I see I have to call a promise that most probably will ask to the server the correct tile.
I should not run these calls on mouse move, because it can be hard for the server, do you agree?
Maybe I can set a timeout, so if the mouse stays there for a second or more, the elevation will be get from the sampleTerrain.
Is there a way, from the ray query to understand which level I’m querying, so I can simply disable the tool when the level has too low res?

You may be interested in how we do this in TerriaJS, which is pretty much just as you described: