How to use Layer Definitions in Identify Parameters?

4029
14
12-02-2011 09:51 AM
JoannaLaroussi
New Contributor
I try to set my Identify tool to identify only the results of my query task instead all of them (this includes invisible). Setting LayerOption = LayerOption.visible does not work in my case, because the query task returns one result for polygon feature class and one for points, where the extent of polygons is much bigger than points. I would like to be able identify only these points, which were returned by a query, but all polygons. My guess is I should use Layer Definitions, but I do not know how exactly to do it. I tried something like this:
private void IdentifyStart()
        {
            ESRI.ArcGIS.Client.Tasks.IdentifyParameters identifyParams = new IdentifyParameters()
            {
                Geometry = _clickPont,
                MapExtent = Map.Extent,
                Width = (int)Map.ActualWidth,
                Height = (int)Map.ActualHeight,
                SpatialReference = Map.SpatialReference,
                Tolerance = 10,
               
IEnumerable < "PreKSitesGraphicsLayer" > IdentifyParameters.LayerDefinitions, 
            };

But this is not working. Does someone have idea how to solve it, or can provide me with any code sample? Thank you!
0 Kudos
14 Replies
DominiqueBroux
Esri Frequent Contributor
If you just want to show or hide some layers, you don't need to change the LayerDefinitions.
You can set the LayerIds with the sublayers that you want to show.
0 Kudos
JoannaLaroussi
New Contributor
If you just want to show or hide some layers, you don't need to change the LayerDefinitions.
You can set the LayerIds with the sublayers that you want to show.


Thank you for your advice. It turned out that the problem was much more complicated and required some changes in the way how layers are displayed and queries are made.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Thank you for your advice. It turned out that the problem was much more complicated and required some changes in the way how layers are displayed and queries are made.


You can look at the documentation of the ArcGISDynamicMapServiceLayer.
LayerDefinitions for this class is close from the layerDefinitions of an IdentifyTask.

The difference being that you can't set the LayerDefinitions of an IdentifyTask in XAML. You have to do it by code (look at the end of the topic).

In your case it's something like :
 
ESRI.ArcGIS.Client.Tasks.IdentifyParameters identifyParams = new IdentifyParameters()
{
Geometry = _clickPont,
MapExtent = Map.Extent,
Width = (int)Map.ActualWidth,
Height = (int)Map.ActualHeight,
SpatialReference = Map.SpatialReference,
Tolerance = 10,
 
LayerDefinitions = new[]
{
  new LayerDefinition {LayerID = 0, Definition = "Magnitude = 6"},
  new LayerDefinition {LayerID = 1, Definition = "Name = 'Paris'"}
  .........
} 
};
 


0 Kudos
JoannaLaroussi
New Contributor
Thanks a lot for a link to documentation �?? it helped me to better understand the entire process.
0 Kudos
JeffSauder
Occasional Contributor
If you just want to show or hide some layers, you don't need to change the LayerDefinitions.
You can set the LayerIds with the sublayers that you want to show.


When I try to set the LayerIds I get an error that it is read only.  Is there any way to set this?
0 Kudos
DominiqueBroux
Esri Frequent Contributor
When I try to set the LayerIds I get an error that it is read only. Is there any way to set this?


LayerIDs is not supposed to be a read-only property.

Code like: myLegend.LayerIDs = new[] {"ID1", "ID2"}; should work.

What is your code when you get this error?
0 Kudos
JeffSauder
Occasional Contributor
The code that gets the error below:

                ESRI.ArcGIS.Client.Tasks.IdentifyParameters idParams = new IdentifyParameters()
                {
                    Geometry = env,
                    //Tolerance = 3,
                    MapExtent = Gilbert.Extent,
                    Width = (int)Gilbert.ActualWidth,
                    Height = (int)Gilbert.ActualHeight,
                    LayerOption = LayerOption.all,
                    LayerIds = LayerIDList[cboLayerList.SelectedIndex]
                };

I found one answer, as of version 2.2 I have to code it as <IdentifyParameters>.LayerIds.Add(<layerid>);

However, I am having a problem with it, after I set it it does nothing, all layers are still returned.

What I am trying to do is have the user set a combo box with the layer they want to identify, then return only that layer.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Sorry, my previous answer was about the LayerIds property of the Legend not of the IdentifyParameter.

For IdentifyParameter, LayersIds is a read-only List of int.

So we can't set it but you can modify the list by code such as :
identifyParameter.LayerIds.Add(3);
or
identifyParameter.LayerIds.Clear();

So in your case, I guess it should be something like:
idParams.LayerIds.Add(LayerIDList[cboLayerList.SelectedIndex]);
0 Kudos
JeffSauder
Occasional Contributor
That is the code that I used, and I don't get an error.  However, identify still returns all layers for some reason.
0 Kudos