Select to view content in your preferred language

Identify problem

4485
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
JannalynPontello
Deactivated User
Yes. I didn't read the example carefully enough. I made that changed and used the ID from xaml, but now I'm getting a NullReferenceException on this part.

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

Here's the full code.

private void QueryPoint_Click(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e)
        {
            if (IdentifyBtn.IsChecked.Value)
            {
                ArcGISDynamicMapServiceLayer EMDataLayer = (ArcGISDynamicMapServiceLayer)Map.Layers["Data"];

                IdentifyBorder.Visibility = System.Windows.Visibility.Visible;

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

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

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

                IdentifyTask identifyTask = new IdentifyTask(EMDataLayer.Url);
                identifyTask.ExecuteCompleted += IdentifyTask_ExecuteCompleted;
                identifyTask.Failed += IdentifyTask_Failed;
                identifyTask.ExecuteAsync(identifyParams);

                GraphicsLayer graphicsLayer = Map.Layers["IDGraphicsLayer"] as GraphicsLayer;
                graphicsLayer.ClearGraphics();
                ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic()
                {
                        Geometry = clickPoint,
                        Symbol = LayoutRoot.Resources["IDPictureSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol
                };
                graphicsLayer.Graphics.Add(graphic);
            }
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Yes. I didn't read the example carefully enough. I made that changed and used the ID from xaml, but now I'm getting a NullReferenceException on this part.

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


VisibleLayers can be null if you never changed the sublayer visibilities. In this case the default sublayer visibilities are used.

So code like :
if (EMDataLayer.VisibleLayers != null)
  foreach (int x in EMDataLayer.VisibleLayers)
    identifyParams.LayerIds.Add(x);
should work.
0 Kudos
JannalynPontello
Deactivated User
That fixed the error, but now it seems that the task doesn't use that code. I'm getting all layers whether or not they're visible. I put a break at the foreach statement, but it never gets hit.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
LayerOption = LayerOption.all,


You have to use the visible option.
0 Kudos
JannalynPontello
Deactivated User
I'm using all.

Here's what I've got now.

private void QueryPoint_Click(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e)
{
if (IdentifyBtn.IsChecked.Value)
{
ArcGISDynamicMapServiceLayer EMDataLayer = (ArcGISDynamicMapServiceLayer)Map.Layers["Data"];

IdentifyBorder.Visibility = System.Windows.Visibility.Visible;

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

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

if (EMDataLayer.VisibleLayers != null)
foreach (int x in EMDataLayer.VisibleLayers)
identifyParams.LayerIds.Add(x);

IdentifyTask identifyTask = new IdentifyTask(EMDataLayer.Url);
identifyTask.ExecuteCompleted += IdentifyTask_ExecuteCompleted;
identifyTask.Failed += IdentifyTask_Failed;
identifyTask.ExecuteAsync(identifyParams);

GraphicsLayer graphicsLayer = Map.Layers["IDGraphicsLayer"] as GraphicsLayer;
graphicsLayer.ClearGraphics();
ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic()
{
Geometry = clickPoint,
Symbol = LayoutRoot.Resources["IDPictureSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol
};
graphicsLayer.Graphics.Add(graphic);
}
0 Kudos
DominiqueBroux
Esri Frequent Contributor
I'm using all.


You have to use the 'visible' option (not all) : LayerOption = LayerOption.visible,

With 'all', all layers are identifiable.
0 Kudos
JannalynPontello
Deactivated User
Got it. I misunderstood. I changed to visible and now it works as I need it. Thanks for your help.
0 Kudos
JannalynPontello
Deactivated User
Now that I can actually identify all visible layers, I realized there are two layers that I don't want to identify. So I found some code on another thread that checks visibility and can also exclude layers, and now I'm getting duplicate results (actually it shows up six times) in the drop down list for the results window. Do you know why this would happen? I only have the layer in the map one time.

I tried to paste in the new code, but it makes my post too long. How do I attach code so that it shows up in a box?
0 Kudos
JannalynPontello
Deactivated User
I found the problem. It was in some previous code.
0 Kudos
BarraLoubna
Deactivated User
I did the same thing as what you have presented here, but there is nothing that displays in my Identify.

Enclosed is my code and the result.

Thank you for your help.
0 Kudos