Checkboxes unticked and layers not visible when page starts up

Discussion created by roryhall on Sep 4, 2013
Latest reply on Sep 5, 2013 by roryhall
Good day all,
I have an application of 2 maps which requires 40 + layers per map to be toggled on and off for a time series comaparison. I have seperated the layers into groups of checkboxes (page design, trying to fit it all in) and have done this grouping the layers using .push to load layers into lists. To create the checkbox groups I use the following code:

        //add check boxes Map 1 Layers
        var layerName = layer.title;
        var checkBox = new dijit.form.CheckBox({
        name: "checkBox" +,
        checked: layer.layer.visible,
        onChange: function(evt) {
            var clayer = map1.getLayer(this.value);
           this.checked = clayer.visible;
        //add the check box and label to the toc Map 1 Layers,dojo.byId("Map1_layers"),"after");
        var checkLabel = dojo.create('label',{'for', innerHTML:layerName},checkBox.domNode,"after");"<br />",checkLabel,"after");     

What I need to do is only show a few of the layers when the page loads. I have been able to accomplish this by setting the visibilty of the layers to true/false in the layer constructor but this interupts the way the checkbox functions. When I check a layer to make it visible "only" the first layer in the list toggles and not the associated layer with the checkbox.

Below is an example of my layer lists and layer constructor:

layersList1.push({layer:Sept09_fl_1m1,title:"Sept 2009"}); 
 layersList1.push({layer:Dec09_fl_2m1,title:'Dec 2009'});
 layersList1.push({layer:Mar10_fl_3m1,title:'Mar 2010'});
 layersList1.push({layer:June10_fl_4m1,title:'June 2010'});

var Landsat_2010_m1 = new esri.layers.ArcGISDynamicMapServiceLayer("http://sirgis2/ArcGIS/rest/services/CentralWest/Landsat_Callide/MapServer");

thanks for any assistance
cheers ~ Rory