Viewer.flyTo(entity) and Cesium.HeightReference.CLAMP_TO_GROUND

First off, thanks for adding entity terrain clamping in Cesium 1.23! That’s a great addition which has been needed for a while!

I am adding an entity to terrain in Cesium 1.23 with the following code:

var myNewEntity = myCesiumViewer.entities.add({

id: someId,

name: “someName”,

polygon: {

material: Cesium.Color.RED.withAlpha(0.4),

hierarchy: Cesium.Cartesian3.fromDegreesArray(someCoordArray),

heightReference: Cesium.HeightReference.CLAMP_TO_GROUND

}

});

Then I fly to that entity with the following code:

myCesiumViewer.flyTo(myNewEntity);

The camera flies to the polygon coordinates but does not respect the terrain height. The camera goes down through the ground.

I was previously using perPositionHieght on PolygonGraphics to simulate clamp to ground functionality. Specifying perPositionHeight (or height or extrudedHeight) on PolygonGraphics makes the viewer.flyTo() respect the height of the entity, but of course it negates the new CLAMP_TO_GROUND/GroundPrimitive rendering of the entity (which is awesome and which I’d like to use).

Can you guys make CesiumViewer.flyTo(entity) respect the height of entities that use the new “heightReference: Cesium.HeightReference.CLAMP_TO_GROUND” property?

Thanks and Regards,

Jamie

Hello Jamie,

I believe the terrain clamping should happen automatically. Here is an example:

var viewer = new Cesium.Viewer(‘cesiumContainer’);
var cesiumTerrainProviderMeshes = new Cesium.CesiumTerrainProvider({
url : ‘https://assets.agi.com/stk-terrain/world
});
viewer.terrainProvider = cesiumTerrainProviderMeshes;

var redPolygon = viewer.entities.add({
polygon : {
hierarchy : Cesium.Cartesian3.fromDegreesArray([-115.0, 37.0,
-115.0, 36.0,
-114.0, 34.0,
-114.0, 36.0]),
material : Cesium.Color.RED.withAlpha(0.5)
}
});

viewer.zoomTo(viewer.entities);

``

Best,

Hannah

After some more digging, I think this is related to the HeadingPitchRange parameter on the viewer.flyTo() call. My flyTo() call looks like this:

viewer.flyTo(myNewEntity, {

duration: 4.0,

offset: new Cesium.HeadingPitchRange(Cesium.Math.toRadians(90), Cesium.Math.toRadians(-25), 1200);

});

I didn’t include the flyTo parameters in my initial post because I didn’t think they were relevant, but now I think that might be the problem. The HeadingPitchRange has a different effect on entities that are clamped to terrain (I.e. entities that do not have an explicit height attribute set). In particular the range seems off when flying to a terrain-clamped entity.