AnsweredAssumed Answered

Checkbox becomes unchecked when map pans

Question asked by Mr_Kirkwood on Mar 9, 2015
Latest reply on Mar 19, 2015 by Mr_Kirkwood

I have a table of contents that is used to toggle visibility of layers. I also have a dialog box that populates with the visible layers so that the user can pick from the visible layers what layer they would like to identify on. They use a checkbox to do this. However, when the map is panned or a feature is zoomed to the checkbox becomes unchecked.  here is a screen shot.

 

checkbox.JPG

 

Here is the code i am using for creating the visible layer checkbox:

 

//get layer names for layers window and create checkboxes
function buildLayerList() {
    require(["dojo/on", "dojo/dom", "dojo/_base/array"], function (on, dom, arrayUtils) {
        var mapLayer = map.layerIds;
        var myItems = [];
        arrayUtils.map(mapLayer, function (layerName) {
            var myLayer = map.getLayer(layerName);
            if (myLayer.id !== "NAIP2012" && myLayer.id !== "NAIP2009" && myLayer.id !== "NAIP2006" && myLayer.id !== "trLayer") {


                if (myLayer.visibleLayers) {
                    //console.log(myLayer.id + " : " + "has vis Layers");
                    var items = arrayUtils.map(myLayer.layerInfos, function (info, index) {
                        if (myLayer.visibleLayers.indexOf(info.id) > -1) {
                            return "<input type='checkbox' class='list_item'" + (info.defaultVisibility ? "checked=checked" : "") + "' id='" + info.name + "CB'' /><label for='" + info.id + "'>"
                                    + info.name + "</label><br>";
                        }


                    });


                    myItems = myItems.concat(items);
                }
            }


        });
        var ll = dom.byId("legendDiv");
        ll.innerHTML = myItems.join(' ');
        document.getElementById("legendDiv").style.display = "block";


    });


}

Outcomes