KmlDataSource.load() - how to get clampToGround working?

Hey guys!

I'm puzzling something together based on the Sandcastle KML bike ride example. I got most of it working, except how to get the KML path stick to the terrain surface. The KML is exported straight out of GE, and has times embedded. See data at the bottom of this post (I've shortened it a bit).

The code I'm using is this:

var viewer = new Cesium.Viewer(‘cesiumContainer’);
viewer.terrainProvider = new Cesium.CesiumTerrainProvider({
    url : ‘
viewer.scene.globe.depthTestAgainstTerrain = true;

var options = {
    camera :,
    canvas : viewer.scene.canvas,
    clampToGround : true
viewer.dataSources.add(Cesium.KmlDataSource.load('../myFile.kml', options))
    //do stuff

Yet the KML path is sunken into the ground and only now and then bits pop out of the terrain surface. Can anyone point me into the right direction how to get this to work? I have also tried it with removing the Z component from the KML file, as suggested in some posts, but that made it actually worse.

Thanks for your help,

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="" xmlns:gx="" xmlns:kml="" xmlns:atom="">
  <name>GPS device</name>
  <snippet>Created 08/04/17 13:59:44</snippet>
  <Style id="multiTrack_n">
    <Placemark id="tour">
        <gx:coord>172.01701 -41.554678 27.57</gx:coord>
        <gx:coord>172.017208 -41.553992 28.6</gx:coord>
        <gx:coord>172.01754 -41.553676 29.92</gx:coord>

Hi there,

Try iterating through your datasource after load ( and setting height to undefined. If height is set, clamping is disabled.


  • Rachel

Hi Max,

Sorry I can’t offer any help here. But I’m trying to generate paths in KML for Cesium to show. I assume when you said “GE” you meant “Google Earth”. I created a path from VSIM to Parliament Hill (I work in Ottawa) in Google Earth Pro, and exported a kml file of the route. However, there is no time embedded, and the coordinates are not inside the gx:coord tags. All I have are turn instructions with comma-separated coordinates, and of course Cesium doesn’t read them. How did you create your kml file?

Here are the first 7x lines in the file. I’ve also attached the file here for your reference. Thanks for your help!


<?xml version="1.0" encoding="UTF-8"?> Route from VSIM to Parliament Hill 1 <![CDATA[
]]> ff000000 default VSIM Building VSIM (Visualization, Simulation and Modeling) #dir_startpoint -75.7002,45.380532,0 Parliament Hill Parliament Hill #dir_endpoint -75.700929,45.4235937,0 Route 7fa00000 normal 6 Head north on Library Rd Head north on Library Rd -75.7009376 45.3805352 0 2.0845308 45 360 #dir_step 45.48053520000001 45.2805352 -75.60093760000001 -75.8009376 0 0 absolute 512 -1 0 0 1 -75.7009376,45.3805352,0 ...