How to set czml path to clamp to ground?

There is an example for drawing polyline on Terrain by setting “clampToGround” to true like this:
shape = viewer.entities.add({

polyline : {

positions : positionData,

clampToGround : true,

width : 3

}

});

The example is here: https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/?src=Drawing%20on%20Terrain.html

Right now I have drawn a czml path with polylineOutline material and but I failed to draw it clamp to ground.

Part of the code:
var czml = [{

“id” : “document”,

“name” : “CZML Path”,

“version” : “1.0”,

“clock”: {

“interval”: “2012-08-04T10:00:00Z/2012-08-04T15:00:00Z”,

“currentTime”: “2012-08-04T10:00:00Z”,

“multiplier”: 10

}

}, {

“id” : “path”,

“name” : “path with GPS flight data”,

“description” : “

Hang gliding flight log data from Daniel H. Friedman.
Icon created by Larisa Skosyrska from the Noun Project

”,

“availability” : “2012-08-04T10:00:00Z/2012-08-04T15:00:00Z”,

“path” : {

“material” : {

“polylineOutline” : {

“color” : {

“rgba” : [255, 0, 255, 255]

},

“outlineColor” : {

“rgba” : [0, 255, 255, 255]

},

“outlineWidth” : 5

}

},

“width” : 8,

“leadTime” : 10,

“trailTime” : 1000,

“resolution” : 5

},

“position” : {

“epoch” : “2012-08-04T10:00:00Z”,

“cartographicDegrees” : [

0,-122.93797,39.50935,0,

10,-122.93822,39.50918,0,

20,-122.9385,39.50883,0,

]

}

}];

Is there anyway to draw a czml path clamp to ground?

Yup! You can set the clampToGround property on the polyline in the CZML in the same way you’re doing it with the Cesium API. Check out this Sandcastle example. The red line is clamped to ground.

Thank you very much, Omar. But it is not exactly what I am doing, that example is a polyline object created through czml, what I am trying to do is create a clamped to ground path.
Could you make the path in this example clamp to ground? https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/?src=CZML%20Path.html&label=CZML

Ah, I see what you mean now. Looks like this isn’t supported at the moment, but I opened a GitHub feature request for it:

Feel free to chime in there. It sounds like it might be slow, at least the naive approach, to support this. Can you describe your use case a bit more? I wonder if a simpler workaround would just be to have the entity that’s being followed to be clamped to ground, that way the path follows the terrain as well.

Thank you very much, Omar!
I found that sometimes the path will be eaten by the terrain, I think it is due to LOD.

So I wonder if I can make the path clamp to ground, in this way, the path and terrain will be transformed together through LOD.

Do you have any idea?

I believe when it clamps to ground it uses whatever LOD is currently loaded, so it shouldn’t sink into the ground. I think another approach that I used recently was to set the height reference of my entity to relative to ground instead of clamp, so I can set it a few pixels above the ground to make it look nicer.

Try it out, and if you can get a Sandcastle example (you can click the share button to get a link to share) of how it looks if it doesn’t look great, that could help a lot in providing us a test case that we can use to improve Cesium.

Thanks again!

I have tried to set height reference, but it didn’t work.
I have tried in this example:
https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/?src=HeadingPitchRoll.html&label=ion%20Assets

And this is how I change the code:

var entityPath = viewer.entities.add({

position : pathPosition,

name : ‘path’,

path : {

show : true,

leadTime : 0,

trailTime : 60,

width : 10,

resolution : 1,

material : new Cesium.PolylineGlowMaterialProperty({

glowPower : 0.3,

color : Cesium.Color.PALEGOLDENROD

}),

heightReference : Cesium.HeightReference.CLAMP_TO_GROUND

}

});

After changing it, the path is still pretty high above the ground.

Here is my confuse about mramato’s word in https://github.com/AnalyticalGraphicsInc/cesium/issues/7133.

Why this is fast and ok, while rendering GroundPolyline for every frame will be really slow?

That’s because PathGraphics doesn’t take a height reference, see the docs here:

https://cesiumjs.org/Cesium/Build/Documentation/PathGraphics.html

My suggestion was more to try clamping the entity the path is following (not the path itself) to the ground. That way the positions you add to the path will thus be already on the ground.

Although, thinking more about it, this might not work depending on what what you’re clamping to ground since Cesium doesn’t always expose the true clamped position. There are other ways you can use to get a position on the ground directly, see the discussion here, especially the last comment about using scene.globe.getHeight. That way, instead of adding the position of the entity that’s being followed to the path direction, you would first get the height of terrain at that position, and then add that new point instead to the path.

Would that work for your situation? I’m curious what sort of visualization you’re working on that would require the path to be clamped but not the entity that’s being followed. Learning more about these use cases helps us a lot in improving Cesium.

I’ll let MrAmato follow up on that.

Hi Omar,
Thanks for all the suggestions,

I have tried to use scene.globe.getHeight for some experiments.

I found a problem,

check this screen shot in attachments.

This polyline have three points, circled in red.

scene.globe.getHeight may get the height of the three points correct, but rest part of the polyline will still be inside of the terrain.

I’m afraid this will be the same for the path.

What I really want is just clamp to ground path, I don’t mind if it is slow, I can modify the source code if necessary.

Do you still have any ideas?

That looks like it’s almost there. All you have to do now is instead of just calling getHeight on those 3 points, call it on a series of points along the way. So you can divide the distance between each 2 points by perhaps a 100 and sample the height at those 100 points (or more if you want more accurate clamping).

You might have already seen this, but the other approach would be to just use a polyline which can be clamped to terrain. Click on “Draw polyline” in this example:

It isn’t exposed, but you could then try to get the ground positions from that polyline. I would start with the GroundPolylineGeometry class, this is where it actually computes all the positions I believe:

Thanks, Omar!
Let me try it.