identifyTask filter by TOC visibility?

680
4
11-29-2016 11:45 AM
BenCamp
New Contributor III

I've searched the forums, but can't find anything recent regarding this topic. Is there an easy/convenient way to filter the identifyTask by layers that are toggled on or off in the Table of Contents?

Thanks in advance.

0 Kudos
4 Replies
KenBuja
MVP Esteemed Contributor

Just set the layerOption method of the IdentifyParameters to IdentifyParameters.LAYER_OPTION_VISIBLE. This might be overkill, but I also set the layerIds option to the visibleLayers of the layer I'm running the task on.

var idParams = new IdentifyParameters();
idParams.width = map.width;
idParams.height = map.height;
idParams.geometry = evt.mapPoint;
idParams.mapExtent = map.extent;
idParams.layerOption = IdentifyParameters.LAYER_OPTION_VISIBLE;
idParams.layerIds = layer.visibleLayers;
idParams.tolerance = 3;
idParams.returnGeometry = true;
idParams.spatialReference = map.spatialReference;
BenCamp
New Contributor III

Thanks, and I apologize if I am using the incorrect terminology. I want to be able to toggle visibility on and off within the application and only identify those layers which are currently toggled on. 

0 Kudos
KenBuja
MVP Esteemed Contributor

That's what I do in my application. Here's one version of it: NCCOS BIOmapper Notice as you turn on different layers, only those will be shown in the popup window IdentifyTask.

BenCamp
New Contributor III

Thank you. I ended up writing a new function that fires when the layer check box changes state. The function then updates an array, which is then passed on to the identify function to limit the layers identified to only those which are toggled on (checkbox is checked). 

Thanks again for your help!

0 Kudos