Picking Sand Castle Example doesn't work with Terrain

I was looking at the Picking Sandcastle example, and I noticed that in the ‘Show Cartographic Position on Mouse Over’ example that if I ‘turned on’ terrain, STK World Terrain meshes, the label would not stay above the terrain and would be hidden depending on the mouse position.

I’m also seeing a similar issue in a cesium app I’m working on.

What is your recommendation for solving this issue?


Sunny Little

Hello Sunny,

It’s not part of the entity API yet, but we recently added a heightReference property to labels and billboards. Setting heightReference: Cesium.HeightReference.CLAMP_TO_GROUND will clamp the label to the terrain. Here is an example:

var viewer = new Cesium.Viewer(‘cesiumContainer’);
var scene = viewer.scene;

var cesiumTerrainProviderMeshes = new Cesium.CesiumTerrainProvider({
url : ‘//assets.agi.com/stk-terrain/world
viewer.terrainProvider = cesiumTerrainProviderMeshes;
viewer.scene.globe.depthTestAgainstTerrain = true;

var labels = scene.primitives.add(new Cesium.LabelCollection({
scene : viewer.scene
var label = labels.add({
text: ‘My Label’,
position: Cesium.Cartesian3.fromDegrees(-120, 40),
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
horizontalOrigin: Cesium.HorizontalOrigin.CENTER

position: new Cesium.Cartesian3(-2448719.8735619076, -4250107.43283317, 4067838.088739029),
heading: 5.999866663850403,
pitch: 0.04494318727342117,
roll: 6.282261310513073