# Shadows not supported in CZML

**URL:** <https://community.cesium.com/t/shadows-not-supported-in-czml/4571>\
**Category:** CesiumJS\
**Created:** [September 4, 2016, 7:50pm UTC](https://community.cesium.com/t/shadows-not-supported-in-czml/4571 "2016-09-04T19:50:42Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![MP1](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/mp1/32/1987_2.png) [@MP1](https://community.cesium.com/u/MP1)\
**Post date:** [September 4, 2016, 7:50pm UTC](https://community.cesium.com/t/shadows-not-supported-in-czml/4571/1 "2016-09-04T19:50:42Z")

</div>

Shadows feature does not work with CZML. I get following error when tried:  
Cesium.js:448 TypeError: Cannot read property ‘length’ of undefined(…)

terrainShadows property is enabled in js as follows:

viewer.terrainShadows = Cesium.ShadowMode.ENABLED;

What am i missing to get this working?

This is my sample CZML file.  
[  
{  
“id”:“document”,  
“name”:“CZML Geometries: Polygon”,  
“version”:“1.0”  
},  
{  
“id”:“abcd”,  
“name”:“Sample Data”,  
“polygon”:{  
“positions”:{  
“cartographicDegrees”:[  
-96.804157261687,  
32.779763115598,  
0,  
-96.804112061058,  
32.779769858449,  
0,  
-96.804112051068,  
32.779769856449,  
0  
]  
},  
“extrudedHeight”:{  
“number”:3  
},  
“heightReference”:1,  
“material”:{  
“solidColor”:{  
“color”:{  
“rgba”:[135,206,250,100]  
}  
}  
},  
“outline”:true,

“shadows” =\> 1 // 1 For enabled  
}  
}  
]

---

<div class="post-metadata">

**Author:** ![sean\_lilley](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/sean_lilley/32/2083_2.png) [@sean\_lilley](https://community.cesium.com/u/sean_lilley)\
**Post date:** [September 5, 2016, 4:33pm UTC](https://community.cesium.com/t/shadows-not-supported-in-czml/4571/2 "2016-09-05T16:33:50Z")

</div>

By default terrain shadows are Cesium.ShadowMode.RECEIVE\_ONLY, which means you don’t need to set it to ENABLED unless you want terrain to cast shadows onto itself (good with really hilly terrain, but not needed for flat areas). Besides that you also need to set:

viewer.shadows = true;

To turn shadowing on for the entire engine.

The problem with your CZML is that it should be “shadows” : “ENABLED”. In CZML you need to use the name of the enum rather than the number value.

Here is the working code:

---

<div class="post-metadata">

**Author:** ![MP1](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/mp1/32/1987_2.png) [@MP1](https://community.cesium.com/u/MP1)\
**Post date:** [September 6, 2016, 9:25am UTC](https://community.cesium.com/t/shadows-not-supported-in-czml/4571/3 "2016-09-06T09:25:24Z")

</div>

Thanks Sean. I tried with following czml sample and could not see shadows of the drawn polygon.

[![](https://lh3.googleusercontent.com/-xKJJ853-6Bo/V86LekPVDFI/AAAAAAAACJQ/aQRp9lM282UYwgSj7MB8o3fsldYZFXjeQCLcB/s320/Capture.PNG)](https://lh3.googleusercontent.com/-xKJJ853-6Bo/V86LekPVDFI/AAAAAAAACJQ/aQRp9lM282UYwgSj7MB8o3fsldYZFXjeQCLcB/s1600/Capture.PNG)

var czml = [

{

“id”:“document”,

“name”:“CZML Geometries: Polygon”,

“version”:“1.0”

},

{

“id”:“abcd”,

“name”:“Sample Data”,

“polygon”:{

“positions”:{

“cartographicDegrees”:[

-90.0, 30.0, 0, -80.0, 30.0, 0, -80.0, 40.0,0, -90.0, 40.0,0

]

},

“extrudedHeight”:{

“number”:300000

},

“material”:{

“solidColor”:{

“color”:{

“rgba”:[135,206,250,100]

}

}

},

“heightReference”:“CLAMP\_TO\_GROUND”,

“outline”:true,

“shadows” : “ENABLED”

}

}

];

var viewer = new Cesium.Viewer(‘cesiumContainer’);

var dataSource = Cesium.CzmlDataSource.load(czml);

viewer.dataSources.add(dataSource);

viewer.zoomTo(dataSource);

viewer.shadows = true;

---

<div class="post-metadata">

**Author:** ![sean\_lilley](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/sean_lilley/32/2083_2.png) [@sean\_lilley](https://community.cesium.com/u/sean_lilley)\
**Post date:** [September 6, 2016, 1:18pm UTC](https://community.cesium.com/t/shadows-not-supported-in-czml/4571/4 "2016-09-06T13:18:29Z")

</div>

Ah ok. Right now the shadow system is tuned for views that are closer to the earth like primitives/models that are close to the ground. It works on a range of about 5000 meters which views from space usually exceed. We may get around to supporting views like this eventually.

---

<div class="post-metadata">

**Author:** ![MP1](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/mp1/32/1987_2.png) [@MP1](https://community.cesium.com/u/MP1)\
**Post date:** [September 7, 2016, 3:41am UTC](https://community.cesium.com/t/shadows-not-supported-in-czml/4571/5 "2016-09-07T03:41:58Z")

</div>

Hey Sean,

That was just an example I posted here. I tried with smaller polygon. But does not seem to work. No shadow is visible if I load data from CZML. Here is my example:

var czml = [

{

“id”:“document”,

“name”:“CZML Geometries: Polygon”,

“version”:“1.0”

},

{

“id”:“abcd”,

“name”:“Sample Data”,

“polygon”:{

“positions”:{

“cartographicDegrees”:[

-90.0, 30.0, 0, -90.0001, 30.0, 0, -90.0001, 30.0001,0, -90.0, 30.0001,0

]

},

“extrudedHeight”:{

“number”:10

},

“material”:{

“solidColor”:{

“color”:{

“rgba”:[135,206,250,100]

}

}

},

“heightReference”:“CLAMP\_TO\_GROUND”,

“outline”:true,

“shadows” : “ENABLED”

}

}

];

var viewer = new Cesium.Viewer(‘cesiumContainer’);

var dataSource = Cesium.CzmlDataSource.load(czml);

viewer.dataSources.add(dataSource);

viewer.zoomTo(dataSource);

viewer.shadows = true;

---

<div class="post-metadata">

**Author:** ![sean\_lilley](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/sean_lilley/32/2083_2.png) [@sean\_lilley](https://community.cesium.com/u/sean_lilley)\
**Post date:** [September 7, 2016, 1:20pm UTC](https://community.cesium.com/t/shadows-not-supported-in-czml/4571/6 "2016-09-07T13:20:05Z")

</div>

That example works for me, check out the attached screenshot. Shadows are affected by the sun position so it’s possible the sun was below the horizon and so there weren’t any shadows. Try adjusting the time slider and let me know how that goes. It’s also possible there’s some latent issue that is only affecting your machine.

![shadows.JPG](https://global.discourse-cdn.com/cesium/original/2X/f/f4689ad2f5ef0471fcc4f4624ad72c4ac2e6e205.jpeg)

---

<div class="post-metadata">

**Author:** ![MP11](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@MP11](https://community.cesium.com/u/MP11)\
**Post date:** [September 7, 2016, 1:30pm UTC](https://community.cesium.com/t/shadows-not-supported-in-czml/4571/7 "2016-09-07T13:30:59Z")

</div>

Hi Sean,

Can “Mapbox streets classic” imagery provider be the issue for this? Coz when I tried with default imagery provider it worked.

---

<div class="post-metadata">

**Author:** ![sean\_lilley](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/sean_lilley/32/2083_2.png) [@sean\_lilley](https://community.cesium.com/u/sean_lilley)\
**Post date:** [September 7, 2016, 1:41pm UTC](https://community.cesium.com/t/shadows-not-supported-in-czml/4571/8 "2016-09-07T13:41:14Z")

</div>

Do you have some sample code I can test out? When I choose different imagery providers they all work for me.

---

<div class="post-metadata">

**Author:** ![MP11](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@MP11](https://community.cesium.com/u/MP11)\
**Post date:** [September 7, 2016, 1:54pm UTC](https://community.cesium.com/t/shadows-not-supported-in-czml/4571/9 "2016-09-07T13:54:02Z")

</div>

Hey Sean, M sorry. I was trying with sample czml which had no ‘“shadows” :“ENABLED”’ added in it.

Thanks.
