AnsweredAssumed Answered

setVisibleLayers isn't working as expected

Question asked by stevel on Apr 25, 2012
Latest reply on Apr 26, 2012 by stevel
Hopefully this is a simple resolution - but I can't see what I'm doing wrong in attempting to set the visible layers of a Dynamic Map Service Layer.

DynamicMap :: setVisibleLayers says that an array of [-1] will over-ride the layerInfos object and display no visible layers. But I'm finding that this is not the case:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" ""> <html>   <head>     <link rel="stylesheet" type="text/css" href="">     <script type="text/javascript" src=""></script>     <script type="text/javascript">       dojo.require("");          function init() {         var map = new esri.Map("map");         var layer = new esri.layers.ArcGISDynamicMapServiceLayer("");         map.addLayer(layer);                  dojo.connect(map, "onLayerAddResult", function(){          layer.setVisibleLayers([-1]);          console.log(layer.visibleLayers);         });                }         dojo.addOnLoad(init);     </script>   </head>   <body class="claro">     <div id="map" style="width:900px; height:600px; border:1px solid #000;"></div>   </body> </html>

Why is the layer still displaying when I've specified no visible layers? Similarly, whether I specify 0, 1 or 2 (the available layers in this sample service) the map draws the same.

I've tried putting the setVisibleLayers line in various places, including after the layer has loaded as in this example. What am I doing wrong here?