Re: Legend - toggle services - unchecked boxes

575
2
Jump to solution
09-09-2013 10:24 PM
EdwardGriffin
New Contributor II
Hi

I'm modifying this code a bit to make a web application:

https://developers.arcgis.com/en/javascript/jssamples/widget_legendvisible.html

The code produces a TOC and a legend, created dynamically using dynamic layers.

Is there any way of having the boxes unchecked when it opens? At the moment they are all checked.

This is the part of the code which controls the checkboxes. I thought it might be as easy as  exchanging
checked :layer.layer.visible, WITH
checked: false,

which does have some impact on the page but does not quite get there.

    //add check boxes
        dojo.forEach(legendLayers, function (layer) {
          var layerName = layer.title;
          var checkBox = new dijit.form.CheckBox({
            name    :"CheckBox" + layer.layer.id,
            value   :layer.layer.id,
            checked :layer.layer.visible,
            onChange:function (evt) {
              var clayer = map.getLayer(this.value);
              clayer.setVisibility(!clayer.visible);
              this.checked = clayer.visible;
             }
          });

Any ideas would be gratefully received!

Cheers

Ed
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor
Since the initial checked property of the check box is set by the layer's visibility, the easy way to do it is to set the visibility of the layers to false when they are created.

      var quakeLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Earthquakes/EarthquakesFromLastSevenDays/MapServer", {id:'quakes', visible: false});        var fireLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Fire/Sheep/MapServer", {id:'fire', visible: false});  

View solution in original post

0 Kudos
2 Replies
KenBuja
MVP Esteemed Contributor
Since the initial checked property of the check box is set by the layer's visibility, the easy way to do it is to set the visibility of the layers to false when they are created.

      var quakeLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Earthquakes/EarthquakesFromLastSevenDays/MapServer", {id:'quakes', visible: false});        var fireLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Fire/Sheep/MapServer", {id:'fire', visible: false});  
0 Kudos
EdwardGriffin
New Contributor II
Hi Ken

Thanks for the reply: awesome simple solution, worked first time.

I had to add "visible : true" the base layer to get that to show too.

Thanks again

Ed
0 Kudos