WMS imageryLayers removal / refresh

1,133 views
Skip to first unread message

justlearning

unread,
Mar 1, 2016, 7:56:34 PM3/1/16
to cesium-dev
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'
}
}));

Hannah Pinkos

unread,
Mar 2, 2016, 10:18:18 AM3/2/16
to cesium-dev, ki4...@gmail.com
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

ki4...@gmail.com

unread,
Mar 2, 2016, 12:06:45 PM3/2/16
to cesium-dev, ki4...@gmail.com
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;
}

Chris B

unread,
Mar 2, 2016, 1:12:10 PM3/2/16
to cesium-dev
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?

Hannah Pinkos

unread,
Mar 2, 2016, 1:29:29 PM3/2/16
to cesium-dev, ki4...@gmail.com
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

Hannah Pinkos

unread,
Mar 2, 2016, 1:29:59 PM3/2/16
to cesium-dev, ki4...@gmail.com
Make sure var imageryLayers = viewer.imagerLayers; is included in your code.

-Hannah
Reply all
Reply to author
Forward
0 new messages