WMS imageryLayers removal / refresh

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({
    url : '//mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi?',
    layers : 'nexrad-n0r',
    parameters : {
        transparent : true,
        format : 'image/png'
    }
}));

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?’,
layers : ‘nexrad-n0r’,
parameters : {
transparent : true,
format : ‘image/png’
}
}));

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

``

Best,

Hannah

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({
    url : '//mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi?',
    layers : 'nexrad-n0r',
    parameters : {
        transparent : true,
        format : 'image/png',
        mydata : Math.random()
    }
}));
var warnings = imageryLayers.addImageryProvider(new Cesium.WebMapServiceImageryProvider({
    url : '//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;
}

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?

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?’,
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?’,
layers : ‘warnings_p’,
parameters : {
transparent : true,
format : ‘image/png’,
mydata : Math.random()
}
}));
layer.alpha = 0.5;
}

``

-Hannah

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

-Hannah