Cesium equivalent of terrain.getHeight(x, y)

What is the equivalent of terrain.getHeight(x, y) in Cesium?

I found a few examples on non Cesium websites but they all seem to be outdated.
I am looking for a code snippet to perform something like that:

let height = (?someCesiumStructure?).getHeight(longitude, latitude);
let dog = viewer.entities.add({ //dog's 3d model
    position: Cesium.Cartesian3.fromDegrees(-121.732796, 36.4799, height),
    model: { uri: ionDogResource.url },
});
this.viewer.trackedEntity = dog;

So the below worked for me however I am not sure that is the right way (or most straight forward way) to do that?

Cesium.sampleTerrain(viewer.terrainProvider, 9, [pointOfInterest]).
    then((samples) => {
        console.log('Height in meters is: ' + samples[0].height);
    });
viewer.scene.globe.getHeight(Cesium.Cartographic.fromDegrees(longitude, latitude));

See this Sandcastle link

1 Like

The code below returns about -44000 for height?

this.viewer.scene.globe.depthTestAgainstTerrain = true;
const height = this.viewer.scene.globe.getHeight(Cesium.Cartographic.fromDegrees(longitude, latitude, 0));