The problem is after I zoom in, 3D terrain data will be loaded and the points will be covered by the terrains.
The 2D map works well.
To solve it, I’m trying to pick up the altitude of my click position and set it as the altitude of point like this:
var cartesian = viewer.camera.pickEllipsoid(movement.position, viewer.scene.globe.ellipsoid);
var cartographic = Cesium.Cartographic.fromCartesian(cartesian);
var longitude = Cesium.Math.toDegrees(cartographic.longitude).toFixed(10);
var latitude = Cesium.Math.toDegrees(cartographic.latitude).toFixed(10);
var altitude = cartographic.height;
But sadly, I can only get 0 as the height.
I’m wondering is there any way to solve that? How could I know the altitude of terrain at certain position(latitude/longitude).
That is happening because the pick is based on the current level of detail of terrain loaded. When you zoom out, the level of detail is more coarse which can lead to a high error like that.
You can try using the sampleTerrain function instead. This lets you query the terrain for the height of a point at a specific level of detail. If you pass in a higher number to level, the height approximation will be more accurate.