Here is some code to create the checkbox list. However, when i pan the map the check boxes in the list become unchecked. Is there a way to stop this from happening?
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" ) {
if (myLayer.visibleLayers) {
//console.log(myLayer.id + " : " + "has vis Layers");
var items = arrayUtils.map(myLayer.layerInfos, function (info, index) {
if (info.name === "Label SEO wells by depth" || info.name === "Label SEO wells by actual yield" || info.name === "Label SEO wells by MWBZ top") {
// console.log(info.name);
} else {
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";
});
}
I am calling on the buildLayerListin the map:
mapLayer.on('update-end', buildLayerList);