thebillcarr

Layer toggle stops refreshing.

Discussion created by thebillcarr on Apr 3, 2014
Latest reply on Apr 16, 2014 by thebillcarr
Greetings,

I'm trying to add layer toggle function to my dynamic map layer based off of this [HTML]https://developers.arcgis.com/javascript/jssamples/map_dynamiclayerlist.html[/HTML] example.

The app works fine with the layers toggling on and off but the problem is that during testing the map quits refreshing the dynamic layer after about 30 seconds. Changing extent, panning, clicking doesn't do anything. Here's the kicker, if I leave the tab open in Firefox and open another test tab( from Aptana Studio 3) the first tab starts refreshing again for about 30 seconds then it stops. It goes on like this the more tabs I open, the previous tabs begin refreshing like normal for a bit then stop.



     function init() {
        map = new esri.Map("map");
        layer = new esri.layers.ArcGISDynamicMapServiceLayer("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer");

        if (layer.loaded) {
          buildLayerList(layer);
        } else {
          dojo.connect(layer, "onLoad", buildLayerList);
        }
      }

      function buildLayerList(layer) {
        var items = dojo.map(layer.layerInfos,function(info,index){
          if (info.defaultVisibility) {
            visible.push(info.id);
          }
          return "<input type='checkbox' class='list_item'" + (info.defaultVisibility ? "checked=checked" : "") + "' id='" + info.id + "' onclick='updateLayerVisibility();' /><label for='" + info.id + "'>" + info.name + "</label>";
        });

        dojo.byId("layer_list").innerHTML = items.join(' ');

        layer.setVisibleLayers(visible);
        map.addLayer(layer);
      }

      function updateLayerVisibility() {
        var inputs = dojo.query(".list_item"), input;
    
        visible = [];

        dojo.forEach(inputs,function(input){
          if (input.checked) {
              visible.push(input.id);
          }
        });
        //if there aren't any layers visible set the array to be -1
        if(visible.length === 0){
          visible.push(-1);
        }
        layer.setVisibleLayers(visible);
      }
      dojo.ready(init);


Any ideas?

Outcomes