Poyline through mountain / under terrain?


i have a line which goes through a mountain - is it possible to draw the whole line, i.e. the part in the mountain with a different color ?


Hi @Ruediger_Brand.

One simple workaround would be to use three lines rather than one. The middle line segment would go through the mountain and could be colored differently than the other two segments. I think this would likely be the easiest solution.



But in which way do I get the line-segments ?

I would like to achieve something like in the screenshot:


Hi @Ruediger_Brand,

you could use the depthFailMaterial for that. It just dont work with dynamic polylines.

Look at this code snippet. You can use a simple color or, as I did, some other stuff like a dashed line.

let entity = viewer.entities.add({
  polyline: {
    positions: [Cesium.Cartesian3.fromDegrees(point1.lon, point1.lat, point1.height), Cesium.Cartesian3.fromDegrees(point2.lon, point2.lat, point2.height)],
    width: 2.0,
    material: color,
    depthFailMaterial: new Cesium.PolylineDashMaterialProperty({
      color: color

Best, Lennart


Hi @lennart.imberg! Thank you for the suggestions. This seems like a much more elegant approach.

I would do something like this;

material: new Cesium.PolylineOutlineMaterialProperty({
   color: color,
   outlineColor: Cesium.Color.LIGHTGREY.withAlpha(0.4)
depthFailMaterial: new Cesium.PolylineOutlineMaterialProperty({
   color: Cesium.Color.LIGHTGREY.withAlpha(0.4),
   outlineColor: Cesium.Color.LIGHTGREY.withAlpha(0.4)

Adjust as you like.



1 Like

@sam.rothstein @Alexander_Johannesen @lennart.imberg

This is a great idea, I have to try, first experiences are super

former solution:





Hi @Ruediger_Brand, this looks amazing! Thanks for sharing :grin:

Is it possible to get all depthFailMaterial line segments which is under the ground?
I mean is it possible to find all line information which in falling under the ground of the terrain (like failed line positions).
Thanks in Advance

You mean like a query for all lines where a portion or whole is under the terrain? If so, I don’t know how to do that without sampling or knowing the terrain and testing lines against it (old-school and a lot of work), but there might be ways to write some low-level code against the renderer, as those depthFailMaterials already do this, and then flagging items accordingly. However, I’m not that savvy when it comes to this stuff, but Cesium is open-source so I would poke my head in the code and see if there’s anything obvious you can hang on to. Anyone?



I’m willing the same result.
Please late me know if you find something.