# Disabling KML/KMZ clipping into terrain?

**URL:** <https://community.cesium.com/t/disabling-kml-kmz-clipping-into-terrain/13512>\
**Category:** CesiumJS\
**Created:** [May 7, 2021, 5:41am UTC](https://community.cesium.com/t/disabling-kml-kmz-clipping-into-terrain/13512 "2021-05-07T05:41:07Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![jos](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/jos/32/3102_2.png) [@jos](https://community.cesium.com/u/jos)\
**Post date:** [May 7, 2021, 5:41am UTC](https://community.cesium.com/t/disabling-kml-kmz-clipping-into-terrain/13512/1 "2021-05-07T05:41:08Z")

</div>

Hello,

When a KML/KMZ file containing a label is imported into Cesium, often the label, text, lines, polygons, etc will be clipped into the terrain, which makes them hard to see.

Here’s an example file in Google Earth:

 ![Screenshot_20210507_150800](https://global.discourse-cdn.com/cesium/original/2X/0/0fdcf4750f87b062c6a3db5fe3b074382b712e43.png)

And here’s those entities in Cesium when the file is imported:

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

The label is stuck under the ground. In some cases, the line is also mostly under the ground.

For some entities, this can be somewhat alleviated by adding `<tessellate>1</tessellate>` inside the KML file, but for the sake of those using my Cesium application I would rather they do not have to know how to edit the KML file. Plus, `tessellate` doesn’t work for every KML object.

Is there a way to disable KML/KMZ clipping into terrain, like `disableDepthTestDistance`? Adding `clampToGround` to the KML source on import doesn’t work.

---

<div class="post-metadata">

**Author:** ![dzung](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/dzung/32/2996_2.png) [@dzung](https://community.cesium.com/u/dzung)\
**Post date:** [May 7, 2021, 3:37pm UTC](https://community.cesium.com/t/disabling-kml-kmz-clipping-into-terrain/13512/2 "2021-05-07T15:37:19Z")

</div>

I think what you are looking for is setting `depthTestAgainstTerrain = false`.

For more details, please see the setting’s description here: [Globe - Cesium Documentation](https://cesium.com/docs/cesiumjs-ref-doc/Globe.html?classFilter=globe#depthTestAgainstTerrain)

---

<div class="post-metadata">

**Author:** ![jos](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/jos/32/3102_2.png) [@jos](https://community.cesium.com/u/jos)\
**Post date:** [May 8, 2021, 1:06am UTC](https://community.cesium.com/t/disabling-kml-kmz-clipping-into-terrain/13512/3 "2021-05-08T01:06:59Z")

</div>

@dzung I’d rather not disable depth test against the terrain for the entire globe if possible, just for KML objects that I import.

---

<div class="post-metadata">

**Author:** ![jos](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/jos/32/3102_2.png) [@jos](https://community.cesium.com/u/jos)\
**Post date:** [May 10, 2021, 7:38am UTC](https://community.cesium.com/t/disabling-kml-kmz-clipping-into-terrain/13512/4 "2021-05-10T07:38:56Z")

</div>

Additionally, several of the tools in my Cesium application require `depthTestAgainstTerrain` to be activated.

EDITL @dzung is there any way to disable the `depthTestAgainstTerrain` for KMLs only?

---

<div class="post-metadata">

**Author:** ![jos](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/jos/32/3102_2.png) [@jos](https://community.cesium.com/u/jos)\
**Post date:** [May 17, 2021, 4:57am UTC](https://community.cesium.com/t/disabling-kml-kmz-clipping-into-terrain/13512/5 "2021-05-17T04:57:34Z")

</div>

I’m guessing then that there’s no way to specific to KMLs that they should ignore terrain features via `depthTestAgainstTerrain`?

---

<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:** [May 17, 2021, 11:15am UTC](https://community.cesium.com/t/disabling-kml-kmz-clipping-into-terrain/13512/6 "2021-05-17T11:15:48Z")

</div>

Hi there,

There’s plenty of options for you, but it can be a bit more tedious than simply setting one parameter. After the import, you can grab the datasource, and pull out the entities it has created. You can then loop through those items, and adjust them through the API accordingly. I do this, for example, with points (that are converted to billboards) that I now can set clamping individually, or labels which I can set an eyeOffset (0, 0, -100) or something appropriate (often based on the labels height, you might have to pull that out and do some calculations to get it).

In short; no, you can’t set a simple parameter for the KML, but you can loop through the entities it creates and tweak them accordingly.

Cheers,

Alex

---

<div class="post-metadata">

**Author:** ![jos](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/jos/32/3102_2.png) [@jos](https://community.cesium.com/u/jos)\
**Post date:** [May 20, 2021, 2:58am UTC](https://community.cesium.com/t/disabling-kml-kmz-clipping-into-terrain/13512/7 "2021-05-20T02:58:41Z")

</div>

@Alexander_Johannesen Is there any way to force billboards and labels to be clamped to terrain? Not just the ellipsoid, but any terrain model that is used afterward.

I tried doing as you said with the billboards and labels’ `HeightReference` being set to `CLAMP_TO_TERRAIN`, but this didn’t work for all KMLs - some stayed on top of the terrain, while others would disappear underground and wouldn’t surface at all. Changing `eyeOffset` didn’t really do anything.

Is is something to do with altitude or height?

---

<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:** [May 20, 2021, 3:25am UTC](https://community.cesium.com/t/disabling-kml-kmz-clipping-into-terrain/13512/8 "2021-05-20T03:25:41Z")

</div>

No, it kinda depends on what’s in your scene, what sort of terrain you’re trying to clamp to, is it a label or billboard, etc. For example, is it a label, the property you’re after is;

`disableDepthTestDistance: Number.POSITIVE_INFINITY`

There’s more in this working Sandcastle, so when your entities come through, set the properties that apply. To find out what kind of entities comes through the KML renderer, just dump it to the console and look for any \_label, or \_billboard, and so on. If they’re non-null, that’s the type;

> **[Cesium Sandcastle](https://sandcastle.cesium.com/?src=Clamp%20to%20Terrain.html)**
>
> The Cesium Sandcastle provides an interactive environment for testing Cesium code.

Cheers,

Alex

---

<div class="post-metadata">

**Author:** ![jos](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/jos/32/3102_2.png) [@jos](https://community.cesium.com/u/jos)\
**Post date:** [May 20, 2021, 4:08am UTC](https://community.cesium.com/t/disabling-kml-kmz-clipping-into-terrain/13512/9 "2021-05-20T04:08:08Z")

</div>

@Alexander_Johannesen I should say that I was also using the `disableDepthTestDistance` for both labels and billboards, using the method you described (pulling the entities out of the data source and changing the labels and billboards in each.

The terrain i’m trying to be on top of is an `ArcGISTiledElevationTerrainProvider` terrain model.

Even with the ellipsoid terrain, however, some KMLs billboards are, for some reason, far beneath the earth on load and slowly ‘rise’ to the surface. When the new terrain is enabled, they rise slightly but only into a flat plane - even with ClampToGround enabled, they stay to some predetermined ‘height’ that I seemingly can’t change, not matching the height of terrain at all. Disabling the new terrain makes them sink back below the earth, so I have to wait a few minutes for it to rise up again.

The options mentioned in the sandcastle are unfortunately not helping in this manner.

Here is what I’m doing:

```
if (entityCollection) {
  for (let entity of entityCollection) {
    if (entity.billboard) {
      entity.billboard.disableDepthTestDistance = new ConstantProperty(
        Number.POSITIVE_INFINITY
      );
      entity.billboard.heightReference = new ConstantProperty(
        HeightReference.CLAMP_TO_GROUND
      );
    }
    if (entity.label) {
      entity.label.disableDepthTestDistance = new ConstantProperty(
        Number.POSITIVE_INFINITY
      );
      entity.label.heightReference = new ConstantProperty(
        HeightReference.CLAMP_TO_GROUND
      );
      entity.label.verticalOrigin = new ConstantProperty(VerticalOrigin.BASELINE)
    }
    if (entity.polyline) {
      entity.polyline.clampToGround = new ConstantProperty(true);
    }
  }
}
```

---

<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:** [May 20, 2021, 4:40am UTC](https://community.cesium.com/t/disabling-kml-kmz-clipping-into-terrain/13512/10 "2021-05-20T04:40:23Z")

</div>

Hmm, it sounds like all the labels height’s are below ground, possibly undefined and just set to 0? Clamping should correct it, but you could also try a crazy thing of setting their height to 4000 or up in the sky, and see if they clamp down. Maybe up-clamping is tricky?

As soon as the KML is rendered, what does a console.log() say about if you took out one of these labels by random?

Cheers,

Alex

---

<div class="post-metadata">

**Author:** ![jos](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/jos/32/3102_2.png) [@jos](https://community.cesium.com/u/jos)\
**Post date:** [May 20, 2021, 4:51am UTC](https://community.cesium.com/t/disabling-kml-kmz-clipping-into-terrain/13512/11 "2021-05-20T04:51:56Z")

</div>

@Alexander_Johannesen Actually as far as I can tell these are billboards, instead of labels. I’m guessing this because i tested setting `label.show = false` for every point and still saw the kml points.

Additionally, this isn’t happening for every KML I import - some attach to terrain just fine, and I can’t tell the difference in KML structure or value that allows this to happen.

I also thought that labels don’t have height - only billboards do? And even then, it seems that billboard height is actually a reference to the length of the billboard.

---

<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:** [May 20, 2021, 4:57am UTC](https://community.cesium.com/t/disabling-kml-kmz-clipping-into-terrain/13512/12 "2021-05-20T04:57:07Z")

</div>

Labels are part of a collection which has 3D Position. Maybe check if these labels are standalone, have a 3D position (so entity.position, not entity.label.position), maybe they have a point or polygon/polyline with it, etc. This is why I asked about that entity’s console.log() output, it might tell you heaps about your issue. If you can replicate it in a Sandcastle, that would truly be the best, inject a sample KML file into it (maybe through Ion) so we can look at it?

Cheers,

Alex

---

<div class="post-metadata">

**Author:** ![jos](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/jos/32/3102_2.png) [@jos](https://community.cesium.com/u/jos)\
**Post date:** [May 20, 2021, 6:31am UTC](https://community.cesium.com/t/disabling-kml-kmz-clipping-into-terrain/13512/13 "2021-05-20T06:31:01Z")

</div>

It seems to be something to do with number of points, or perhaps computer performance. Having a lot of points in one place and then enabling the new terrain model makes it seem like it doesn’t go to the top of terrain; however, if I reduce the number of points, then it eventually occurs - It just takes a very long time.

I should note, however, that I had to set `HeightReference = HeighReference.RELATIVE_TO_GROUND` in order to see it.

---

<div class="post-metadata">

**Author:** ![jos](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/jos/32/3102_2.png) [@jos](https://community.cesium.com/u/jos)\
**Post date:** [May 20, 2021, 7:44am UTC](https://community.cesium.com/t/disabling-kml-kmz-clipping-into-terrain/13512/14 "2021-05-20T07:44:17Z")

</div>

Is there a way to make sure polylines are clamped too? I tried setting `entity.polyline.clampToGround` = true, but I ran into this error:

```auto
CesiumWidget.js?d9c1:690 An error occurred while rendering. Rendering has stopped.
DeveloperError: Valid options for arcType are ArcType.GEODESIC and ArcType.RHUMB.
Error
    at new DeveloperError (webpack-internal:///./node_modules/cesium/Source/Core/DeveloperError.js:41:11)
    at new GroundPolylineGeometry (webpack-internal:///./node_modules/cesium/Source/Core/GroundPolylineGeometry.js:113:11)
    at PolylineGeometryUpdater.createFillGeometryInstance (webpack-internal:///./node_modules/cesium/Source/DataSources/PolylineGeometryUpdater.js:441:17)
    at StaticGroundPolylinePerMaterialBatch.add (webpack-internal:///./node_modules/cesium/Source/DataSources/StaticGroundPolylinePerMaterialBatch.js:365:34)
    at insertUpdaterIntoBatch (webpack-internal:///./node_modules/cesium/Source/DataSources/PolylineVisualizer.js:57:45)
    at PolylineVisualizer.update (webpack-internal:///./node_modules/cesium/Source/DataSources/PolylineVisualizer.js:271:5)
    at DataSourceDisplay.update (webpack-internal:///./node_modules/cesium/Source/DataSources/DataSourceDisplay.js:313:31)
    at Viewer._onTick (webpack-internal:///./node_modules/cesium/Source/Widgets/Viewer/Viewer.js:1858:43)
    at Event.raiseEvent (webpack-internal:///./node_modules/cesium/Source/Core/Event.js:141:20)
    at Clock.tick (webpack-internal:///./node_modules/cesium/Source/Core/Clock.js:325:15)

```

---

<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:** [May 20, 2021, 8:21am UTC](https://community.cesium.com/t/disabling-kml-kmz-clipping-into-terrain/13512/15 "2021-05-20T08:21:01Z")

</div>

Is this latest Cesium version? Might be a bug with the KML renderer that it doesn’t set ArcType properly?

You could always try to set the ArcType.GEODESIC before turning on clamping, the API might have a bug that it doesn’t. Again, just before you set the clamping, I’d do a console.log(’@@here’, myEntity); and open it and take a screenshot of it and paste it here.

Cheers,

Alex

---

<div class="post-metadata">

**Author:** ![jos](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/jos/32/3102_2.png) [@jos](https://community.cesium.com/u/jos)\
**Post date:** [May 21, 2021, 1:33am UTC](https://community.cesium.com/t/disabling-kml-kmz-clipping-into-terrain/13512/16 "2021-05-21T01:33:04Z")

</div>

Current version of npm is `1.75` apparently, `npm` doesn’t want to update it.

It seems that setting `ArcType` to equal `GEODESIC` works, and I can clamp to ground afterward.

Here’s an image of an example line before clamping occurs:

 ![image](https://global.discourse-cdn.com/cesium/original/2X/1/182835c9a79ef6c8dd76a4b858ee79d27be8f303.png)

It looks like it’s not setting the arcType and clamping is `undefined`, although there is that known part of the KML import where it doesn’t clamp a line if `tesselate` isn’t present in the KML.

---

<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:** [May 21, 2021, 2:39am UTC](https://community.cesium.com/t/disabling-kml-kmz-clipping-into-terrain/13512/17 "2021-05-21T02:39:01Z")

</div>

At least you’re moving forward. 🙂 I might try to report that as a bug, ArcType is important for a number of things, and should be set on any polygon/polyline. Do you have anything like a small KML you can share with the bug report as well?

Cheers,

Alex

---

<div class="post-metadata">

**Author:** ![jos](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/jos/32/3102_2.png) [@jos](https://community.cesium.com/u/jos)\
**Post date:** [May 21, 2021, 3:10am UTC](https://community.cesium.com/t/disabling-kml-kmz-clipping-into-terrain/13512/18 "2021-05-21T03:10:52Z")

</div>

Here’s a KML I can share for the bug report. I created it via Google Earth:  
[workingKML.kml](https://community.cesium.com/uploads/short-url/v0vvZBzzE6L5vBOW7S2iBjqm2e1.kml) (1.9 KB)

And here’s the bug report:

> <https://github.com/CesiumGS/cesium/issues/9555>
>
> \<!--
> Thanks for helping us improve Cesium! Please describe what the expected be…havior is vs what actually happens.
> 
> Creating a Sandcastle example (https://sandcastle.cesium.com) that reproduces the issue helps us a lot in tracking down bugs. Paste the link you get from the "Share" button in Sandcastle below.
> \--\>
> 
> Sandcastle example: None Specifically
> 
> Browser: Chrome
> 
> Operating System: Linux (Kubuntu) 20.04
> 
> \<!--
> 
> If you can also contribute a fix, we'd absolutely appreciate it! Fixing a bug in Cesium often means fixing a bug for thousands of applications and millions of end users.
> 
> Check out the contributor guide to get started:
> 
> https://github.com/CesiumGS/cesium/blob/master/CONTRIBUTING.md
> 
> Just let us know you're working on it and we'd be happy to provide advice and feedback.
> 
> \--\>
> 
> When importing a KML into Cesium, polylines will either have their ArcType value set as \`undefined\` or \`ArcType.NONE\`. 
> 
> \[Here's a polyline printed to the log after import.\](https://global.discourse-cdn.com/cesium/original/2X/1/182835c9a79ef6c8dd76a4b858ee79d27be8f303.png)
> 
> 
> I discovered this when trying to force polylines from Cesium to be clamped to terrain upon import. Often without the right \`ArcType\` value the engine will crash trying to get the line to clamp, with the error:
> 
> \`\`\`CesiumWidget.js?d9c1:690 An error occurred while rendering. Rendering has stopped.
> DeveloperError: Valid options for arcType are ArcType.GEODESIC and ArcType.RHUMB.\`\`\`
> 
> I think whether or not the line has \`tessellate\` in the KML file determines what ArcType is chosen. If \`tessellate\` is present, then ArcType will be \`undefined\`; if it's not, then \`ArcType\` will be \`ArcType.NONE\`.
> 
> 
> An example KML file \[can be located here.\](https://community.cesium.com/uploads/short-url/v0vvZBzzE6L5vBOW7S2iBjqm2e1.kml)
