Points are covered by the Terrain Data


I’m trying to implement a point-select logic as a combination of picking example and point example

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).


Instead of using pickEllipsoid, you can use camera.getPickRay and scene.globe.pick to get a position that includes the height of the terrain.

Here is an demo to show you how to do it: http://analyticalgraphicsinc.github.io/cesium-google-earth-examples/examples/groundAlt.html



Hi Hannah,

Thanks for your reply.

I tried your link but when I zoom out, the altitude is about -20000 meters, is that normal?

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.

You can see how to use the sampleTerrain function in this demo: http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Terrain.html&label=All

Look for the ‘Sample Everest Terrain’ section.

Hope this helps!


Thanks Hannah!

This really helps!