Hi,
I've used the ESRI sample for dynamically building checkbox toggles for layer visibility. However, as the layers in my map service occur several times albeit in different scales, the list layers function shows both the name of the parent group layer as well as the names of the children. Like so:
-Checkbox- Roads
-Checkbox- Roads 500
-Checkbox- Roads 1000
-Checkbox- Roads 1500
Thusly, I need a way to exclude the children from the list (Roads 500, 1000, 1500) while still having the Roads group checkbox hiding or showing all of its children. Is there some variable that I can check in the buildlayerlist function that filters out the layers I want to exclude? How would the code look?
Any help is very appreciated!
Thank you
function buildLayerList(layer) { var items = dojo.map(layer.layerInfos,function(info,index){ if (layer.parentLayerId == -1) { visible.push(info.id); } return "<input type='checkbox' class='list_item' checked='" + (info.defaultVisibility ? "checked" : "") + "' id='" + info.id + "' onclick='updateLayerVisibility();' /><label for='" + info.id + "'>" + info.name + "</label>"; }); dojo.byId("layer_list").innerHTML = items.join(); layer.setVisibleLayers(visible); map.addLayer(layer); }
Thank you for the help!
However, I'm still having problems integrating it into the appropriate function.
I tried doing this, but it doesn't seem to have any effect:function buildLayerList(layer) { var items = dojo.map(layer.layerInfos,function(info,index){ if (layer.parentLayerId == -1) { visible.push(info.id); } return "<input type='checkbox' class='list_item' checked='" + (info.defaultVisibility ? "checked" : "") + "' id='" + info.id + "' onclick='updateLayerVisibility();' /><label for='" + info.id + "'>" + info.name + "</label>"; }); dojo.byId("layer_list").innerHTML = items.join(); layer.setVisibleLayers(visible); map.addLayer(layer); }
The idea was to insert a condition where it only creates checkboxes for the group parents, but I'm obviously missing something.
Thanks again for help!
EDIT:
To clarify: I want to toggle the visibility of a group of layers with the help of a checkbox that refers to the parent in the group. I want to prevent the script from generating checkboxes for the children, but I still want to show the children in the map when their parent is checked.