I programmed an application in ArcGIS JavaScript version 3.23. The aplication uses a LayerList. It is required to know if one of the layers is visible (active) or not in order to be able to perform another action. Which is te ay to access de visibility property of any of the layers? or How sholuld I know if one of the layers was activated by te user and it is visible?. The idea is that when any of the layers Aquifers or Basins is selected and that the user clicks on some element, Aquifer or Basin, select this element in a unique way.
Next I show the parts of the program that I use
app.map = new Map("map", {
map: map,
basemap: "topo",
center: [-102.199176, 23.068129],
minZoom: 4,
autoResize: true,
zoom: 5,
fadeOnZoom: true,
infoWindow: popup,
navigationMode: "css-transforms"
});
app.map.on("layers-add-result", function (evt) {
var layerListDom = new LayerList({
map: app.map,
layers: [{
layer: f1,
showSubLayers: false,
showLegend: true,
showOpacitySlider: true,
visibility: false,
id: "Aquifers"
},{
layer: f2,
showSubLayers: false,
showLegend: true,
showOpacitySlider: true,
visibility: false,
id: "Basins"
},
},"layerList");
layerListDom.startup();
app.map.on("click", function (evt) {
var query = new Query();
query.geometry = evt.mapPoint;
var layer_visible = app.map.getLayer(app.map.layerIds[0]);
var layer_visible1 = app.map.getLayer(app.map.layerIds[1]);
if (layer_visible.visibility === true) {
var deferred = f1.selectFeatures(query, FeatureLayer.SELECTION_NEW, function
(selection) { });
}
if (layer_visible1.visibility === true) {
var deferred = f2.selectFeatures(query, FeatureLayer.SELECTION_NEW, function (selection) { });
}
app.map.infoWindow.setFeatures([deferred]);
app.map.infoWindow.show(evt.mapPoint);
});