How to set Polyline extruded height when cesium world terrain enabled

Hello,
Is it possible to set per position height for polylines in czml with cesium world terrain enabled. It is possible without the terrain enabled. here is my code. Thank you.

var czml = [
{
id: “document”,
name: “CZML Geometries: Polyline”,
version: “1.0”,
},

{
id: “1”,
name: " red line",
polyline: {
positions: {
cartographicDegrees: [79.99003238, 6.87834315, 100, 79.9833608, 6.8813874, 0],
},
material: {
solidColor: {
color: {
rgba: [255, 0, 0, 255],
},
},
},
perPositionHeight: true,
width: 1,
relativeToGround: true
},
}
];

var viewer = new Cesium.Viewer(“cesiumContainer”);
var dataSourcePromise = Cesium.CzmlDataSource.load(czml);
viewer.dataSources.add(dataSourcePromise);
viewer.zoomTo(dataSourcePromise);

1 Like

Hello @arithh,

Polygons don’t currently have a way to specify a heightReference to have the positions set relative to the terrain height. The positions are treated relative to the WGS84 ellipsoid. However, you can use the function sampleTerrainMostDetailed to query the terrain dataset. This will return an array of Cartographic positions where the height is the height of terrain at each position. From there, you can compute the offset yourself. See the API documentation here: Global - Cesium Documentation and a sandcastle example that uses sampleTerrainMostDetailed here: Cesium Sandcastle

Cheers,

Hannah
Cesium Staff