+ Reply to Thread
Results 1 to 3 of 3

Thread: setVisibleLayers isn't working as expected

  1. #1
    Stephen Lead
    Join Date
    May 2010
    Posts
    772
    Points
    160
    Answers Provided
    31


    0

    Default 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:

    Code:
    <!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

  2. #2
    Paul Bushore
    Join Date
    Apr 2010
    Posts
    65
    Points
    21
    Answers Provided
    3


    1
    This post is marked as the answer

    Default Re: setVisibleLayers isn't working as expected

    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/ArcGI..._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!
    -----------------------------
    Paul Bushore
    Senior GIS Analyst
    Riley County, KS

  3. #3
    Stephen Lead
    Join Date
    May 2010
    Posts
    772
    Points
    160
    Answers Provided
    31


    0

    Default Re: setVisibleLayers isn't working as expected

    Quote Originally Posted by pmbushore View Post
    The URL: http://server.arcgisonline.com/ArcGI..._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

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts