Select to view content in your preferred language

How to restrict identify layers

5750
32
03-10-2011 08:20 AM
DonFreeman
Emerging Contributor
Is there a way to restrict the layers that are returned with an identify query?
  private void QueryPoint_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e)
   {
   ESRI.ArcGIS.Client.Geometry.MapPoint clickPoint = e.MapPoint;

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

   IdentifyTask identifyTask = new IdentifyTask("http://gismaps.pagnet.org/arcgis/rest/services/Interactive_TIP_2011/MapServer");
   identifyTask.ExecuteCompleted += IdentifyTask_ExecuteCompleted;
  
   identifyTask.ExecuteAsync(identifyParams);

   GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
   graphicsLayer.ClearGraphics();
   ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic()
   {
    Geometry = clickPoint,
    Symbol = LayoutRoot.Resources["DefaultPictureSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol
   };
   graphicsLayer.Graphics.Add(graphic);
   }

I tried putting the layer numbers in the url but that did not work.
Thanks
0 Kudos
32 Replies
JenniferNery
Esri Regular Contributor
You can refer to this link for IdentifyParameters http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Tasks.Iden...

You can set LayerIds property.
0 Kudos
DonFreeman
Emerging Contributor
Thanks Jenn. That is helpful.
0 Kudos
DonFreeman
Emerging Contributor
You can refer to this link for IdentifyParameters http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Tasks.Iden...

You can set LayerIds property.


What is the syntax to set LayerIds? When I try LayerIds = [1,2] it tells me the property is readonly.
0 Kudos
JenniferNery
Esri Regular Contributor
Ah yes, this is read-only but you can add id's to it:

 identifyParams.LayerIds.AddRange(new int[] { 1, 2 });
0 Kudos
DonFreeman
Emerging Contributor
Thanks Jenn. This works. I don't understand how it can be readonly but you can still write to it, but as long as it works I'm happy.
Have a great weekend.
🙂
0 Kudos
JenniferNery
Esri Regular Contributor
Oh it is read-only in the sense that the instance cannot be changed but the collection can be modified. 🙂
 
//identifyParameters.LayerIds = new System.Collections.Generic.List<int>(); <-- cannot change instance
identifyParameters.LayerIds.AddRange(new int[] { 1, 2 }); // can change collection 


You have a good weekend too.
0 Kudos
BrandonCales
Regular Contributor
Is there a way to remove specific ones without list all of them except the specific ones...

e.g. RemoveRange (2, 4)...
0 Kudos
DominiqueBroux
Esri Frequent Contributor
The REST API doesn't offer an option to exclude some sublayers.
You have to build by yourself a layerIds list with all values except the values to exclude.
0 Kudos
DonFreeman
Emerging Contributor
Build the list of layers you want to be included like this:
 private void QueryPoint_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e)
        {

            ESRI.ArcGIS.Client.Geometry.MapPoint clickPoint = e.MapPoint;
            List<int> LayerList = new List<int>();
            LayerList.Add(0);
            LayerList.Add(1);
            LayerList.Add(2);
            LayerList.Add(3);

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

            identifyParams.LayerIds.AddRange(new int[] { 4,5 }); // These are the layers you want included.

            IdentifyTask identifyTask = new IdentifyTask("http://gismaps.pagnet.org/arcgis/rest/services/ARRA_042211_plot/MapServer");
            identifyTask.ExecuteCompleted += IdentifyTask_ExecuteCompleted;

            identifyTask.ExecuteAsync(identifyParams);

            GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
            graphicsLayer.ClearGraphics();
            ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic()
            {
                Geometry = clickPoint,
                Symbol = LayoutRoot.Resources["DefaultPictureSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol
            };
            graphicsLayer.Graphics.Add(graphic);
        }
0 Kudos