Select to view content in your preferred language

Identify problem

4496
35
04-25-2011 11:43 AM
DanielSchatt
Regular Contributor
I'm trying to use the identify functionality that is in the Identify sample. I have set

LayerOption = LayerOption.Visible

just as in the sample.  I assumed this means that all layers are accessible by the identify tool, but only layers that are checked as visible in the web application at any given time will be identified.  That's what I want.

But what's happening is that the identify function is only working on the layers that I set as visible in the original .mxd (and which therefore show initially as visible when I load the web site).  Those layers will always be identified in the web application whether they are visible or not, and other layers will never be identified whether they are visible or not.

Is this what's supposed to happen?  How can I get it to behave as I want? Thanks so much for any help...
0 Kudos
35 Replies
DominiqueBroux
Esri Frequent Contributor

Is this what's supposed to happen?

Yes, It's supposed to happen this way.
'LayerOption.Visible' doesn't take care of the layers currently visible at the client side since the identify task is executed at the server side that doesn't know anything about the client.

After setting LayerOption.Visible (without setting the LayerIds), the identify task will work on layers having a default viisbility set to true and being viisble at the current scale.


How can I get it to behave as I want?

You have to set the LayerIds property to the list of currently visible layers.
Once you have set the LayerIds property, you can set the LayerOption.Visible if you want to take care of the visibility depending on the scale.
0 Kudos
DanielSchatt
Regular Contributor
Thanks much Dominique!  There may be a better way for me to have done this since I don't know coding very well, but it seems to be working for the most part.  For anyone else who may face this issue, I defined a variable for my map service of type ArcGISDynamicMapServiceLayer and then found a line of code on another forum to add only visible layers of the service to the LayerIDs value, as follows:

            ArcGISDynamicMapServiceLayer shorelineAssessmentMapperMapLayer = (ArcGISDynamicMapServiceLayer)ShorelineAssessmentMapperMap.Layers[3];

            ESRI.ArcGIS.Client.Geometry.MapPoint clickPoint = e.MapPoint;

            ESRI.ArcGIS.Client.Tasks.IdentifyParameters identifyParams = new IdentifyParameters()
            {
                Geometry = clickPoint,
                MapExtent = ShorelineAssessmentMapperMap.Extent,
                Width = (int)ShorelineAssessmentMapperMap.ActualWidth,
                Height = (int)ShorelineAssessmentMapperMap.ActualHeight,
                LayerOption = LayerOption.all,
                SpatialReference = ShorelineAssessmentMapperMap.SpatialReference,
            };

            foreach (int x in shorelineAssessmentMapperMapLayer.VisibleLayers)
                identifyParams.LayerIds.Add(x);

            IdentifyTask identifyTask = new IdentifyTask(shorelineAssessmentMapperMapLayer.Url);
            identifyTask.ExecuteCompleted += IdentifyTask_ExecuteCompleted;
            identifyTask.Failed += IdentifyTask_Failed;
            identifyTask.ExecuteAsync(identifyParams);
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Great! looks very good.

Optionally you can set LayerOption to LayerOption.viisble if you'd rather to only identify the layers visible at the current scale (but this doesn't change anything if your layers are always visible whatever the scale).
0 Kudos
GaryBushek
Deactivated User
this works fine in all situations except when none of the layers are visible on the client side.  At that point identifyParams.LayerIds is set to have no layers. If thats the case then I get results for all layers visible in the mxd.  If I have at least 1 layer specified in the LayerIds array then I get the correct results.  Is there a fix for this?
0 Kudos
DominiqueBroux
Esri Frequent Contributor

this works fine in all situations except when none of the layers are visible on the client side. Is there a fix for this?

Right. Not really useful to query the server whether we are not expecting any result.

An initial test such as:
if (shorelineAssessmentMapperMapLayer.VisibleLayers.Length == 0) return;
should do the trick:)
0 Kudos
GaryBushek
Deactivated User
ha!! Sometimes the most obvious things are the easiest to miss. Thanks. I guess I would have just assumed if the array was blank going in that the querytask would respect that and handle it on that end just as if there were 1, 2 or 3 layers to identify.

thanks again.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Yes, the problem is that 'no visible layers' has to be managed as a particular case else we end up with default visible layers.
0 Kudos
JannalynPontello
Deactivated User
I also need to identify layers that are not visible initially. When I tried to create a variable for my map layers using the suggestions in this thread, I'm getting the error "Cannot convert type 'ESRI.ArcGIS.Client.LayerInfo' to 'ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer'.

This is the line with the problem.

ArcGISDynamicMapServiceLayer EMDataLayer = (ArcGISDynamicMapServiceLayer)EMDataLayer.Layers[20];
0 Kudos
DominiqueBroux
Esri Frequent Contributor
I'm getting the error "Cannot convert type 'ESRI.ArcGIS.Client.LayerInfo' to 'ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer'.

This is the line with the problem.

ArcGISDynamicMapServiceLayer EMDataLayer = (ArcGISDynamicMapServiceLayer)EMDataLayer.Layers[20];


You need to get the layer from the Map, not from the layer itself.
ArcGISDynamicMapServiceLayer EMDataLayer = (ArcGISDynamicMapServiceLayer)myMap.Layers[20]; 


Though, the code will be clearer if you give an ID to your layer in XAML, so you can reuse this ID by code:
ArcGISDynamicMapServiceLayer EMDataLayer = (ArcGISDynamicMapServiceLayer)myMap.Layers["MyLayerId"]; 
0 Kudos