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<SPAN class="punctuation token">.</SPAN>map <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Map</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"map"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">{</SPAN>
map<SPAN class="operator token">:</SPAN> map<SPAN class="punctuation token">,</SPAN>
basemap<SPAN class="operator token">:</SPAN> <SPAN class="string token">"topo"</SPAN><SPAN class="punctuation token">,</SPAN>
center<SPAN class="operator token">:</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">102.199176</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">23.068129</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN>
minZoom<SPAN class="operator token">:</SPAN> <SPAN class="number token">4</SPAN><SPAN class="punctuation token">,</SPAN>
autoResize<SPAN class="operator token">:</SPAN> <SPAN class="token boolean">true</SPAN><SPAN class="punctuation token">,</SPAN>
zoom<SPAN class="operator token">:</SPAN> <SPAN class="number token">5</SPAN><SPAN class="punctuation token">,</SPAN>
fadeOnZoom<SPAN class="operator token">:</SPAN> <SPAN class="token boolean">true</SPAN><SPAN class="punctuation token">,</SPAN>
infoWindow<SPAN class="operator token">:</SPAN> popup<SPAN class="punctuation token">,</SPAN>
navigationMode<SPAN class="operator token">:</SPAN> <SPAN class="string token">"css-transforms"</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
app<SPAN class="punctuation token">.</SPAN>map<SPAN class="punctuation token">.</SPAN><SPAN class="token function">on</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"layers-add-result"</SPAN><SPAN class="punctuation token">,</SPAN> function <SPAN class="punctuation token">(</SPAN>evt<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
var layerListDom <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">LayerList</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">{</SPAN>
map<SPAN class="operator token">:</SPAN> app<SPAN class="punctuation token">.</SPAN>map<SPAN class="punctuation token">,</SPAN>
layers<SPAN class="operator token">:</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">{</SPAN>
layer<SPAN class="operator token">:</SPAN> f1<SPAN class="punctuation token">,</SPAN>
showSubLayers<SPAN class="operator token">:</SPAN> <SPAN class="token boolean">false</SPAN><SPAN class="punctuation token">,</SPAN>
showLegend<SPAN class="operator token">:</SPAN> <SPAN class="token boolean">true</SPAN><SPAN class="punctuation token">,</SPAN>
showOpacitySlider<SPAN class="operator token">:</SPAN> <SPAN class="token boolean">true</SPAN><SPAN class="punctuation token">,</SPAN>
visibility<SPAN class="operator token">:</SPAN> <SPAN class="token boolean">false</SPAN><SPAN class="punctuation token">,</SPAN>
id<SPAN class="operator token">:</SPAN> <SPAN class="string token">"Aquifers"</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="punctuation token">{</SPAN>
layer<SPAN class="operator token">:</SPAN> f2<SPAN class="punctuation token">,</SPAN>
showSubLayers<SPAN class="operator token">:</SPAN> <SPAN class="token boolean">false</SPAN><SPAN class="punctuation token">,</SPAN>
showLegend<SPAN class="operator token">:</SPAN> <SPAN class="token boolean">true</SPAN><SPAN class="punctuation token">,</SPAN>
showOpacitySlider<SPAN class="operator token">:</SPAN> <SPAN class="token boolean">true</SPAN><SPAN class="punctuation token">,</SPAN>
visibility<SPAN class="operator token">:</SPAN> <SPAN class="token boolean">false</SPAN><SPAN class="punctuation token">,</SPAN>
id<SPAN class="operator token">:</SPAN> <SPAN class="string token">"Basins"</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"layerList"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
layerListDom<SPAN class="punctuation token">.</SPAN><SPAN class="token function">startup</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
app<SPAN class="punctuation token">.</SPAN>map<SPAN class="punctuation token">.</SPAN><SPAN class="token function">on</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"click"</SPAN><SPAN class="punctuation token">,</SPAN> function <SPAN class="punctuation token">(</SPAN>evt<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
var query <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Query</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
query<SPAN class="punctuation token">.</SPAN>geometry <SPAN class="operator token">=</SPAN> evt<SPAN class="punctuation token">.</SPAN>mapPoint<SPAN class="punctuation token">;</SPAN>
var layer_visible <SPAN class="operator token">=</SPAN> app<SPAN class="punctuation token">.</SPAN>map<SPAN class="punctuation token">.</SPAN><SPAN class="token function">getLayer</SPAN><SPAN class="punctuation token">(</SPAN>app<SPAN class="punctuation token">.</SPAN>map<SPAN class="punctuation token">.</SPAN>layerIds<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
var layer_visible1 <SPAN class="operator token">=</SPAN> app<SPAN class="punctuation token">.</SPAN>map<SPAN class="punctuation token">.</SPAN><SPAN class="token function">getLayer</SPAN><SPAN class="punctuation token">(</SPAN>app<SPAN class="punctuation token">.</SPAN>map<SPAN class="punctuation token">.</SPAN>layerIds<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>layer_visible<SPAN class="punctuation token">.</SPAN>visibility <SPAN class="operator token">==</SPAN><SPAN class="operator token">=</SPAN> <SPAN class="token boolean">true</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
var deferred <SPAN class="operator token">=</SPAN> f1<SPAN class="punctuation token">.</SPAN><SPAN class="token function">selectFeatures</SPAN><SPAN class="punctuation token">(</SPAN>query<SPAN class="punctuation token">,</SPAN> FeatureLayer<SPAN class="punctuation token">.</SPAN>SELECTION_NEW<SPAN class="punctuation token">,</SPAN> function
<SPAN class="punctuation token">(</SPAN>selection<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>layer_visible1<SPAN class="punctuation token">.</SPAN>visibility <SPAN class="operator token">==</SPAN><SPAN class="operator token">=</SPAN> <SPAN class="token boolean">true</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
var deferred <SPAN class="operator token">=</SPAN> f2<SPAN class="punctuation token">.</SPAN><SPAN class="token function">selectFeatures</SPAN><SPAN class="punctuation token">(</SPAN>query<SPAN class="punctuation token">,</SPAN> FeatureLayer<SPAN class="punctuation token">.</SPAN>SELECTION_NEW<SPAN class="punctuation token">,</SPAN> function <SPAN class="punctuation token">(</SPAN>selection<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
app<SPAN class="punctuation token">.</SPAN>map<SPAN class="punctuation token">.</SPAN>infoWindow<SPAN class="punctuation token">.</SPAN><SPAN class="token function">setFeatures</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN>deferred<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
app<SPAN class="punctuation token">.</SPAN>map<SPAN class="punctuation token">.</SPAN>infoWindow<SPAN class="punctuation token">.</SPAN><SPAN class="token function">show</SPAN><SPAN class="punctuation token">(</SPAN>evt<SPAN class="punctuation token">.</SPAN>mapPoint<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>