I have been modifying the basic viewer template project from ArcGIS.com for my own project. The Layer list is created by this function in the layout.js file:
//Create a menu with a list of operational layers. Each menu item contains a check box
//that allows users to toggle layer visibility.
function addLayerList(layers) {
var layerList = buildLayerVisibleList(layers);
if (layerList.length > 0) {
//create a menu of layers
layerList.reverse();
var menu = new dijit.Menu({
id : 'layerMenu'
});
dojo.forEach(layerList, function(layer) {
menu.addChild(new dijit.CheckedMenuItem({
label : layer.title,
checked : layer.visible,
onChange : function() {
if (layer.layer.featureCollection) {
//turn off all the layers in the feature collection even
//though only the main layer is listed in the layer list
dojo.forEach(layer.layer.featureCollection.layers, function(layer) {
layer.layerObject.setVisibility(!layer.layerObject.visible);
});
} else {
layer.layer.setVisibility(!layer.layer.visible);
}
}
}));
});
var button = new dijit.form.DropDownButton({
label : i18n.tools.layers.label,
id : "layerBtn",
iconClass : "esriLayerIcon",
title : i18n.tools.layers.title,
dropDown : menu
});
dojo.byId('webmap-toolbar-center').appendChild(button.domNode);
}
}
There is nothing wrong about this in runtime except the user can really see whatever is last checked in the list of checkboxes. I have been digging for few hours but I cannot find anyway to uncheck the other layers in runtime. I want these checkboxes to behave like Radio Buttons. There is no radio buttons in dijit menu items and I am not in the stage to rewrite this layer selection from scratch. If I give an "id" to the CheckedMenuItem, I can get to it using dojo.byId in runtime. But then none of the .checked, .set("checked", [true/false]), etc. will work.Is there anything I can do?