Entities on Terrain

Hi,

I have some simple entities that I’m trying to display in Cesium.js. Here’s my setup:

  • Using Cesium.js 1.123
  • Using terrain - Cesium World Terrain for this example
  • Using imagery - Bing Maps Aerial for this example
  • 1 Polygon - in an area with significant terrain, should “follow” terrain
  • 1 Label - should “follow” terrain
  • viewer.scene.globe.depthTestAgainstTerrain = true

This scenario can be seen in this Sandcastle link.

I’m having issues with the terrain obscuring my entities and trying to get the entity options/properties correct to fix it.

First some details about the displayed polygon:

  • If I set heightReference to NONE and don’t specify a height, it seems to follow the terrain but the polygon’s outline doesn’t display (supported by the message in the Console stating that outlines are not supported on terrain). Ok, I can live with that.
  • If I set heightReference to CLAMP_TO_GROUND and keep the height unspecified, it follows the terrain like before, but the Console shows a message stating that Entity corridor, ellipse, polygon or rectangle with a heightReference must also have a height defined. heightReference will be ignored. Seems odd but ok?
  • If I keep heightReference set to CLAMP_TO_GROUND and set a height (0) on the polygon as hinted by the Console message, a couple of things happen:
    • The outline is displayed
    • The polygon no longer follows the terrain but rather is shown as a plane at some non-zero height, clearly visible in the scene as being above ground level
    • The peaks of the mountains in the area stick out the top of the polygon.
    • Increasing the height value causes the polygon to move further away from the ground

Is there a combination of options (these or others) that would allow me to clamp the polygon to the ground without visual artifacts or Console warnings?

Now on to the label:

  • If I set heightReference to NONE and don’t specify a height, the label is not visible. It’s there (under the terrain) and can be seen if depthTestAgainstTerrain is disabled but that is not the behavior I desire.
  • If I set heightReference to CLAMP_TO_GROUND and keep the height unspecified, it becomes visible but is obscured by the terrain in various ways depending on the camera position.
  • If I keep heightReference to CLAMP_TO_GROUND and set a height (any value) I see the same behavior as the previous combination
  • If I set heightReference to NONE and set a height (something large enough to get it to be above the terrain) the label is displayed unobscured but not where I want it.

Is there a combination of options (these or others) that would allow me to have the label clamped to the ground but not obscured by the terrain?

Thank you in advance for your time and consideration.

-Jeff

outline has a lot of issues which have long history so it is not recommended to use it. Use polyline instead:

const myPolygonPositions = Cesium.Cartesian3.fromDegreesArray(/* ... */)
new Cesium.Entity({
  polygon: {
    hierarchy: new Cesium.PolygonHierarchy(myPolygonPositions),
  },
  polyline: {
    positions: myPolygonPositions,
    clampToGround: true,
    // other options!
  }
})

For the issue about label, maybe try:

new Entity({
  label: {
    disableDepthTestDistance: Number.POSITIVE_INFINITY
  }
})
1 Like

Hi @jeffricks, welcome to the community! And thanks for the Sandcastle! It makes it much easier to understand what you are trying to do.

If you don’t specify a height for the polygon, it is assumed to be “on the ground”, and will be used to classify the terrain. See classificationType. You mentioned that it “seems to follow the terrain”. It might be more accurate to say that the classification is coloring everything inside the polygon. This is why we can even use polygon classification to highlight 3D buildings within the polygon.

As you noticed, polygon outlines are not supported on terrain. See Support for polygon outlines on terrain · Issue #6694 · CesiumGS/cesium · GitHub for more details.

For the label, have you looked at disableDepthTestDistance? This would be like disabling depthTestAgainstTerrain for the label only, but still allowing depth test for the rest of the scene. (Edit: I see @s3xysteak already suggested this!)

But if you’re wanting to adjust the height of the label relative to the terrain, you may want to look at HeightReference.RELATIVE_TO_TERRAIN.

Let me know if I’m misunderstanding any of your questions.