2 Replies Latest reply on Apr 26, 2012 3:35 PM by stevel

    setVisibleLayers isn't working as expected

      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" "http://www.w3.org/TR/html4/strict.dtd"> <html>   <head>     <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/2.8/js/dojo/dijit/themes/claro/claro.css">     <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.8"></script>     <script type="text/javascript">       dojo.require("esri.map");          function init() {         var map = new esri.Map("map");         var layer = new esri.layers.ArcGISDynamicMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/Specialty/Soil_Survey_Map/MapServer");         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?