# Poyline through mountain / under terrain?

**URL:** <https://community.cesium.com/t/poyline-through-mountain-under-terrain/17245>\
**Category:** CesiumJS\
**Created:** [February 9, 2022, 2:26pm UTC](https://community.cesium.com/t/poyline-through-mountain-under-terrain/17245 "2022-02-09T14:26:51Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ruediger\_Brand](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/ruediger_brand/32/4004_2.png) [@Ruediger\_Brand](https://community.cesium.com/u/Ruediger_Brand)\
**Post date:** [February 9, 2022, 2:26pm UTC](https://community.cesium.com/t/poyline-through-mountain-under-terrain/17245/1 "2022-02-09T14:26:51Z")

</div>

Hi,

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 ?

Rüdiger

---

<div class="post-metadata">

**Author:** ![sam.rothstein](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/sam.rothstein/32/6584_2.png) [@sam.rothstein](https://community.cesium.com/u/sam.rothstein)\
**Post date:** [February 9, 2022, 4:54pm UTC](https://community.cesium.com/t/poyline-through-mountain-under-terrain/17245/2 "2022-02-09T16:54:52Z")

</div>

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.

Best,  
Sam

---

<div class="post-metadata">

**Author:** ![Ruediger\_Brand](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/ruediger_brand/32/4004_2.png) [@Ruediger\_Brand](https://community.cesium.com/u/Ruediger_Brand)\
**Post date:** [February 9, 2022, 5:42pm UTC](https://community.cesium.com/t/poyline-through-mountain-under-terrain/17245/3 "2022-02-09T17:42:30Z")

</div>

@sam.rothstein

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

I would like to achieve something like in the screenshot:

 ![image](https://global.discourse-cdn.com/cesium/original/2X/e/ea5c8fbca6180414f1576f56187cf3d4acfd17fa.jpeg)

Rüdiger

---

<div class="post-metadata">

**Author:** ![lennart.imberg](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/lennart.imberg/32/9788_2.png) [@lennart.imberg](https://community.cesium.com/u/lennart.imberg)\
**Post date:** [February 10, 2022, 6:20am UTC](https://community.cesium.com/t/poyline-through-mountain-under-terrain/17245/4 "2022-02-10T06:20:51Z")

</div>

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.

```auto
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

---

<div class="post-metadata">

**Author:** ![sam.rothstein](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/sam.rothstein/32/6584_2.png) [@sam.rothstein](https://community.cesium.com/u/sam.rothstein)\
**Post date:** [February 10, 2022, 3:01pm UTC](https://community.cesium.com/t/poyline-through-mountain-under-terrain/17245/5 "2022-02-10T15:01:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Alexander\_Johannesen](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/alexander_johannesen/32/2008_2.png) [@Alexander\_Johannesen](https://community.cesium.com/u/Alexander_Johannesen)\
**Post date:** [February 10, 2022, 11:50pm UTC](https://community.cesium.com/t/poyline-through-mountain-under-terrain/17245/6 "2022-02-10T23:50:52Z")

</div>

I would do something like this;

```auto
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.

Cheers,

Alex

---

<div class="post-metadata">

**Author:** ![Ruediger\_Brand](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/ruediger_brand/32/4004_2.png) [@Ruediger\_Brand](https://community.cesium.com/u/Ruediger_Brand)\
**Post date:** [February 11, 2022, 8:02am UTC](https://community.cesium.com/t/poyline-through-mountain-under-terrain/17245/7 "2022-02-11T08:02:33Z")

</div>

@sam.rothstein @Alexander_Johannesen @lennart.imberg

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

former solution:

 ![image](https://global.discourse-cdn.com/cesium/original/3X/5/3/5354afbec22d2a3ac0079c4ddf50550353f39595.jpeg)

new

 ![image](https://global.discourse-cdn.com/cesium/original/2X/8/84e6389353ad2b6e70aa1af9e6155dd4d95dd0eb.jpeg)

Great

Rüdiger

---

<div class="post-metadata">

**Author:** ![sam.rothstein](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/sam.rothstein/32/6584_2.png) [@sam.rothstein](https://community.cesium.com/u/sam.rothstein)\
**Post date:** [February 14, 2022, 3:26pm UTC](https://community.cesium.com/t/poyline-through-mountain-under-terrain/17245/8 "2022-02-14T15:26:01Z")

</div>

Hi @Ruediger_Brand, this looks amazing! Thanks for sharing 😁

---

<div class="post-metadata">

**Author:** ![Shashi](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/shashi/32/3649_2.png) [@Shashi](https://community.cesium.com/u/Shashi)\
**Post date:** [March 21, 2023, 12:53pm UTC](https://community.cesium.com/t/poyline-through-mountain-under-terrain/17245/9 "2023-03-21T12:53:31Z")

</div>

@Alexander_Johannesen  
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

---

<div class="post-metadata">

**Author:** ![Alexander\_Johannesen](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/alexander_johannesen/32/2008_2.png) [@Alexander\_Johannesen](https://community.cesium.com/u/Alexander_Johannesen)\
**Post date:** [March 21, 2023, 10:25pm UTC](https://community.cesium.com/t/poyline-through-mountain-under-terrain/17245/10 "2023-03-21T22:25:47Z")

</div>

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?

Cheers,

Alex

---

<div class="post-metadata">

**Author:** ![Shashi](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/shashi/32/3649_2.png) [@Shashi](https://community.cesium.com/u/Shashi)\
**Post date:** [March 22, 2023, 4:40am UTC](https://community.cesium.com/t/poyline-through-mountain-under-terrain/17245/11 "2023-03-22T04:40:31Z")

</div>

@Alexander_Johannesen  
I’m willing the same result.  
Please late me know if you find something.  
Cheers,  
Shashi
