WMSLayer - turn off all layer

1207
7
Jump to solution
09-24-2014 04:51 AM
MichalSchneider
New Contributor II

Hi,

how can I turn off all layer at WMS service (WMSLayer)? When I'am using ArcGIS dynamic service (ArcGISDynamicMapServiceLayer) method setVisibleLayers([-1]) turns off all layers. I seems to me, that this approach doesn't help at WMS service...

Any idea?

Thanks a lot!

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Michal,

  All you do is send an empty array.

wmsLayer.setVisibleLayers([]);

View solution in original post

0 Kudos
7 Replies
RiyasDeen
Occasional Contributor III

Hi Michael,

wmsLayer.setVisibleLayers(["-1"]) does the trick.

Test with this ArcGIS API for JavaScript Sandbox  sample

0 Kudos
MichalSchneider
New Contributor II

Hi Riyas,

thank you for such a quick answer, but it doesn't work I've just tried it.

Michal

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Michal,

  All you do is send an empty array.

wmsLayer.setVisibleLayers([]);

0 Kudos
MichalSchneider
New Contributor II

Hi Robert,

thank you, it works! I just don't know why is there the difference in ArcGISDynamicMapServiceLayer?

Anyway, thanks again.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Michal,

   I would think that the same would be true for the ArcGISDynamicMapServiceLayer. What you are doing is sending an array of layer IDs that you want visible and because that is not a layer id with -1 the ArcGISDynamicMapServiceLayer do not set any to visible. But the WMSLayer probably sees the -1 and it does not have that layer id and internally throws and error when searching for -1 and then bails because of the error. So sending an empty array would be the more accurate approach for both layer types.

MichalSchneider
New Contributor II

Hi Robert,

sending empty array into setVisibleLayers for both ArcGISDynamicMapServiceLayer and WMSLayer would make sense, but unfortunatelly it doesn't work. To turn off all layer you have to send empty array for WMSLayer (as you said) and array with -1 -> [-1] for ArcGISDynamicMapServiceLayer. If I send empty array to ArcGISDynamicMapServiceLayer if show default visible layer as it's set in service 😉

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Michal,

   Thanks for the correction. I don't recall it being that way in other APIs like Flex where all my background comes from.

0 Kudos