Using/Getting MSL in Cesium

Hello,

I am trying to use cesium to create point in a map. The point will be then flyable with a drone.

I have the following problem,

1) The user set a point altitude to 20 meters in a 2D flat map.
2) The point need to be create at the real world location (long/lat) + 20 meters (altitude).
3) The point will be visible on a 3D map, so at the location (long/lat) + 20meters (altitude).

Exemple (picture)

Right now, my problem is, when I set the point on the flat map, the altitude will be 20 meters, and so, in the 3D map that is using a worldTerrain, the point will be underground if for exemple, the point is on a mountain.

To fix this, I want to get the coordinate MSL, and adding 20 meter to that MSL.
(in the picture, getting the blue altitude(MSL), and then adding 20 meters to that blue altitude (50meters)

I tried to get that blue altitude by using this

var terrainProvider = Cesium.createWorldTerrain();
var promise = Cesium.sampleTerrain(terrainProvider, 11, position);
Cesium.when(promise, function(updatedPosition) {
    console.log(updatedPosition)
});

but this will give me the point above the ellipsoid, and so it will still be 20meters.

Is there a way to do so ?

Also, I read that

```Just a clarification, the ellipsoid and MSL are not the same thing. The ellipsoid (usually WGS84 for Earth), is a commonly-used mathematical approximation of the Earth's shape. Mean sea level (usually EGM96 or EGM2008 for Earth) is a much messier shape determined by measuring the Earth's gravitational field at a bunch of locations, and it may be either above or below the ellipsoid. Mixing up the ellipsoid and MSL will make your heights incorrect on the order of tens of meters.```

Does that mean MSL is unusable correctly in cesium? that even if I get the correct MSL, it might not work when importing the point to cesium ?

Thank you

I just saw also this https://cesium.com/blog/2015/10/26/cloudahoy-migration-to-cesium/ => Altitude: Sea Level and the Ellipsoid

But to be completely honest, I don't understand the totality.
can someone please explain or recap the step.

If I want to use MSL outside of cesium, and then "height above ellipsoid" in cesium, and that visually and practically, the height match in booth mode. what should I do ?

Thank you very much.

Using sampleTerrain should give you the terrain height at this location. If it’s giving you incorrect results (or just the ellipsoid height) it may be because the terrain hasn’t loaded in yet when that function was called. Try using sampleTerrainMostDetailed instead: https://cesiumjs.org/Cesium/Build/Documentation/sampleTerrainMostDetailed.html?classFilter=sampleTer

If you’re still having issues, can you put together a Sandcastle example (https://cesiumjs.org/Cesium/Apps/Sandcastle/index.html) of your code so I can test it out?

Actually, I tried again from 0 today, and it work on first try. I don't know what I was missing last time.

thank you

My favorite explanation of the different reference surfaces used to compute height relative to the surface of the Earth is at Esri.

If you want to store heights as MSL in your application’s database and use Cesium to display the vehicle’s path you must convert ellipsoid height to geoid height using EGM-96 or EGM-2008. GeographicLib is one option for performing the conversion.