push track to ground

We have ground and fly tracks in our app. The task is to push ground tracks to ground and ensure that fly tracks are above the ground. For now I do the following:

var cartesianCoords = […]; // Here are track’s coords that we have to process and push to ground

var checkLevelOfDetails = 11;

var promise = Cesium.sampleTerrain(self.map.scene.globe.terrainProvider,checkLevelOfDetails,self.map.scene.globe.ellipsoid.cartesianArrayToCartographicArray(cartesianCoords));

Cesium.when(promise,function(updatedPositions) {

cartesianCoords = self.map.scene.globe.ellipsoid.cartographicArrayToCartesianArray(updatedPositions);



The question is how to define checkLevelOfDetails? We use //cesiumjs.org/stk-terrain/tilesets/world/tiles for terrain. It has different precision for different map areas. That’s why we can’t set it to some constant. If it’s set to the lower value than the actual terrain is drawn, there’s mismatch (track does not actually lie on the ground). If it’s greater than actual terrain, files for SampleTerrain are not found at all.

.getHeight will yield terrain height for the LOD currently rendered. Since the data is already local you don’t have to do promise/when.


If you’re using STK World Terrain, you can inspect the (private but accessible) _availability property to determine the most detailed available tile at a location. Here’s some code I wrote in National Map to do it:



If you push a track down to the most detailed LOD tile at that location but it’s rendering a lower LOD tile at that location isn’t possible it could either be up in the air or buried? But I suppose if the camera always stays close to the track the most detailed LOD tile will also be the rendered tile.

Thanks a lot!
That’s the code I was looking for. It’s simple and clear.