Hello,
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.
Solved! Go to Solution.
You can use the layerIds property and your visibleLayerIds variable to only identify the visible layers.
function executeIdentifyTask(event) { identifyParams.layerIds = visibleLayerIds; identifyParams.geometry = event.mapPoint; identifyParams.mapExtent = map.extent;
You could also use the visibleLayers property of the layer itself
identifyParams.layerIds = SG_ml.visibleLayers;
You can use the layerIds property and your visibleLayerIds variable to only identify the visible layers.
function executeIdentifyTask(event) { identifyParams.layerIds = visibleLayerIds; identifyParams.geometry = event.mapPoint; identifyParams.mapExtent = map.extent;
You could also use the visibleLayers property of the layer itself
identifyParams.layerIds = SG_ml.visibleLayers;
This functionality can be achieved with only 4 additional lines of code?
I only want to be able to identify on a subset of my visible layers. As such can I perform an "and" statement where I put in an explicit list of layers and then only identify on those explicit layers when they are visible? This is different from the scenario where you want to have all layers be identified if the end user makes the layer visible through a TOC.
Actually, it's only one additional line of code to set the layerIds. The other lines were already existing in his code. I included those to show where I added the line.
I knew it had to be easier than I thought it was.
I now recall you mentioned a similar (if not exactly the same) comment on my previous question, Ken. I guess I glossed over it because I took a different direction with my code.
Very much appreciate the help and patience! That one extra line of code did the trick (used the identifyParams.layerIds = SG_ml.visibleLayers; choice).