I am trying to incorporate an IdentifyTask in my JS web application that identifies layers within an ArcGISDynamicMapServiceLayer upon a "click".
I have successfully integrated the function and can identify features with a click, however a popup will display whether or not that layer is toggled in the web app. I require my end users to be able to enable/disable layers they choose. If I understand correctly, LAYER_OPTION_VISIBLE will allow popups for all layers initially set to be visible in the MXD, and LAYER_OPTION_ALL will allow popups for all layers, regardless of default MXD visibility.
I am trying to only call popups when the layer is enabled in the web application itself. I have too many layers for my users to have to sift through all of the disabled ones to find the one they are looking for.
I have searched high and low to find a working example so the identify task is "listening" to when a layer is toggled on/off, but cannot find a sample that works for me. I am still very new to JS, this may be easier than I am making it out to be.
Below is a JS Fiddle that demonstrates the problems I am having. Had to substitute ESRI sample services due to company network restrictions.
Am working in NetBeans 8.0.2 BTW.
I appreciate any and all feedback!
EDIT: as you can see below, regardless if the layer is "enabled", the popup will display.