# WMS imageryLayers removal / refresh

**URL:** <https://community.cesium.com/t/wms-imagerylayers-removal-refresh/3788>\
**Category:** CesiumJS\
**Created:** [March 2, 2016, 12:56am UTC](https://community.cesium.com/t/wms-imagerylayers-removal-refresh/3788 "2016-03-02T00:56:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![brent252](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/brent252/32/3476_2.png) [@brent252](https://community.cesium.com/u/brent252)\
**Post date:** [March 2, 2016, 12:56am UTC](https://community.cesium.com/t/wms-imagerylayers-removal-refresh/3788/1 "2016-03-02T00:56:34Z")

</div>

I'm having a some trouble understanding how to remove this layer on a timer the basic idea is to refresh the wms layer so from what I have looked at the best way is to remove it and add it again maybe using a extra parameters like date : Math.random(); but I'm stumped on removing the layer is it something like viewer.remove(radar, true); I guess I could use a code sample to understand it more. It would be great to get a sample so I could understand it.

var radar = viewer.imageryLayers;  
imageryLayers.addImageryProvider(new Cesium.WebMapServiceImageryProvider({  
&nbsp;&nbsp;&nbsp;&nbsp;url : '[//mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi?'](https://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi?'),  
&nbsp;&nbsp;&nbsp;&nbsp;layers : 'nexrad-n0r',  
&nbsp;&nbsp;&nbsp;&nbsp;parameters : {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;transparent : true,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;format : 'image/png'  
&nbsp;&nbsp;&nbsp;&nbsp;}  
}));

---

<div class="post-metadata">

**Author:** ![hannah](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/hannah/32/4509_2.png) [@hannah](https://community.cesium.com/u/hannah)\
**Post date:** [March 2, 2016, 3:18pm UTC](https://community.cesium.com/t/wms-imagerylayers-removal-refresh/3788/2 "2016-03-02T15:18:17Z")

</div>

Hello,

You can use viewer.imageryLayers.remove function. Here is an example:

//Add the layer  
var imageryLayers = viewer.imageryLayers;  
var layer = imageryLayers.addImageryProvider(new Cesium.WebMapServiceImageryProvider({  
url : ‘//[mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi?](http://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi?)’,  
layers : ‘nexrad-n0r’,  
parameters : {  
transparent : true,  
format : ‘image/png’  
}  
}));

//Remove the layer  
imageryLayers.remove(layer);

``

Best,

Hannah

---

<div class="post-metadata">

**Author:** ![brent252](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/brent252/32/3476_2.png) [@brent252](https://community.cesium.com/u/brent252)\
**Post date:** [March 2, 2016, 5:06pm UTC](https://community.cesium.com/t/wms-imagerylayers-removal-refresh/3788/3 "2016-03-02T17:06:44Z")

</div>

Got it, one more problem is come up layer.alpha = 0.5;  
is not working after I readd the layer? Am I doing something incorrectly or is there a way to default the layer alpha to .5?  
function myTimer() {  
imageryLayers.remove(layer);  
imageryLayers.remove(warnings);  
var layer = imageryLayers.addImageryProvider(new Cesium.WebMapServiceImageryProvider({  
&nbsp;&nbsp;&nbsp;&nbsp;url : '[//mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi?'](https://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi?'),  
&nbsp;&nbsp;&nbsp;&nbsp;layers : 'nexrad-n0r',  
&nbsp;&nbsp;&nbsp;&nbsp;parameters : {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;transparent : true,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;format : 'image/png',  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mydata : Math.random()  
&nbsp;&nbsp;&nbsp;&nbsp;}  
}));  
var warnings = imageryLayers.addImageryProvider(new Cesium.WebMapServiceImageryProvider({  
&nbsp;&nbsp;&nbsp;&nbsp;url : '[//mesonet.agron.iastate.edu/cgi-bin/wms/us/wwa.cgi?'](https://mesonet.agron.iastate.edu/cgi-bin/wms/us/wwa.cgi?'),  
&nbsp;&nbsp;&nbsp;&nbsp;layers : 'warnings\_p',  
&nbsp;&nbsp;&nbsp;&nbsp;parameters : {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;transparent : true,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;format : 'image/png',  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mydata : Math.random()  
&nbsp;&nbsp;&nbsp;&nbsp;}  
}));  
layer.alpha = 0.5;  
}

---

<div class="post-metadata">

**Author:** ![brent252](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/brent252/32/3476_2.png) [@brent252](https://community.cesium.com/u/brent252)\
**Post date:** [March 2, 2016, 6:12pm UTC](https://community.cesium.com/t/wms-imagerylayers-removal-refresh/3788/4 "2016-03-02T18:12:08Z")

</div>

Uncaught TypeError: Cannot read property ‘remove’ of undefined

wx1.html:100 Uncaught TypeError: Cannot read property ‘remove’ of undefinedmyTimer @ wx1.html:100

also getting this error?

---

<div class="post-metadata">

**Author:** ![hannah](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/hannah/32/4509_2.png) [@hannah](https://community.cesium.com/u/hannah)\
**Post date:** [March 2, 2016, 6:29pm UTC](https://community.cesium.com/t/wms-imagerylayers-removal-refresh/3788/5 "2016-03-02T18:29:29Z")

</div>

You have to be careful about the scope of your variables in Javascript. Moving var layer and var warnings outside of the function should solve the problem:

var layer;  
var warnings;  
function myTimer() {  
imageryLayers.remove(layer);  
imageryLayers.remove(warnings);  
layer = imageryLayers.addImageryProvider(new Cesium.WebMapServiceImageryProvider({  
url : '[//mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi?’](https://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi?'),  
layers : ‘nexrad-n0r’,  
parameters : {  
transparent : true,  
format : ‘image/png’,  
mydata : Math.random()  
}  
}));  
warnings = imageryLayers.addImageryProvider(new Cesium.WebMapServiceImageryProvider({  
url : '[//mesonet.agron.iastate.edu/cgi-bin/wms/us/wwa.cgi?’](https://mesonet.agron.iastate.edu/cgi-bin/wms/us/wwa.cgi?'),  
layers : ‘warnings\_p’,  
parameters : {  
transparent : true,  
format : ‘image/png’,  
mydata : Math.random()  
}  
}));  
layer.alpha = 0.5;  
}

``

-Hannah

---

<div class="post-metadata">

**Author:** ![hannah](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/hannah/32/4509_2.png) [@hannah](https://community.cesium.com/u/hannah)\
**Post date:** [March 2, 2016, 6:29pm UTC](https://community.cesium.com/t/wms-imagerylayers-removal-refresh/3788/6 "2016-03-02T18:29:59Z")

</div>

Make sure var imageryLayers = viewer.imagerLayers; is included in your code.

-Hannah
