Get and set checkbox visibility by JavaScript code

Discussion created by on Jun 11, 2014
Latest reply on Jun 13, 2014 by
We have a large number of layers in our map and every user complains about the lack of ability to save what's turned on/off.
So my task was to create some code that would store variables in local storage to remember what was checked, and then on-load setup the map for them. So I wrote some code that works from a button that reads all the layers and sublayers and gets the default visibility. However it doesn't read the current map settings. i.e. you can uncheck a layer and it still read true in this code. So how do I get the current check box setting, and how would I set it's value?

What I have so far.

function getTheMapLayers() {
   var theInfo2 = []
   var theList2 =""
  for (var j=0, jl=map.layerIds.length; j<jl; j++) {

  theList2 = theList2 +"\n"+map.getLayer(map.layerIds[j]).id+" - Map Service, Visible = "+ map.getLayer(map.layerIds[j]).visible+"\n"

    var items2 =[j]).layerInfos,function(info,index){
     theInfo2[] = ( "id: "+ +" Name: "+" Visibility: "+info.defaultVisibility);
     theList2 = theList2 +"\n"+theInfo2[]