setVisibleLayers isn't working as expected

337
2
Jump to solution
04-25-2012 08:38 PM
StephenLead
Regular Contributor III
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?

Thanks,
Steve
0 Kudos
1 Solution

Accepted Solutions
PaulBushore
Occasional Contributor
Hello,

From what I can see, the mapservice you are using there isn't actually a dynamic map service even though you are adding it as one.  The URL: http://server.arcgisonline.com/ArcGIS/rest/services/Specialty/Soil_Survey_Map/MapServer shows under the "Single Fused Map Cache" header that it is true, indicating that the map is cached, which I believe means that you cannot adjust the visibility of the layers.

I added my own dynamic map to the code you provided and it removed the map layers as well.

I would check that the map you are trying to add is really dynamic and not a fused cache.

Hope this helps!

View solution in original post

0 Kudos
2 Replies
PaulBushore
Occasional Contributor
Hello,

From what I can see, the mapservice you are using there isn't actually a dynamic map service even though you are adding it as one.  The URL: http://server.arcgisonline.com/ArcGIS/rest/services/Specialty/Soil_Survey_Map/MapServer shows under the "Single Fused Map Cache" header that it is true, indicating that the map is cached, which I believe means that you cannot adjust the visibility of the layers.

I added my own dynamic map to the code you provided and it removed the map layers as well.

I would check that the map you are trying to add is really dynamic and not a fused cache.

Hope this helps!
0 Kudos
StephenLead
Regular Contributor III
The URL: http://server.arcgisonline.com/ArcGIS/rest/services/Specialty/Soil_Survey_Map/MapServer shows under the "Single Fused Map Cache" header that it is true, indicating that the map is cached, which I believe means that you cannot adjust the visibility of the layers.


Bingo - thanks for the tip. I wonder if this limitation is documented anywhere?

Cheers,
Steve
0 Kudos