Select to view content in your preferred language

How to restrict identify layers

5777
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
MaciejGolebiewski
Emerging Contributor
Hello everyone,

I wanted to use Brandon's solution but with no luck - can't even go through debugging... 😞

When I add "public List<int> checkVisibility()" code to my MainPage.xaml.cs VS underlines "MapLegend" and shows "The name 'MapLegend' does not exist in the current context" error. If I add x:Name="MapLegend" to my <esri:Legend> in XAML the underline disappears, but the same error concerning "!ExcludeLayerList" occurs ("does not exist in current context").

What am I doing wrong? Am I missing something or just put the code in wrong place?

I'm quite unexperienced with SL and C# therefore my question could be a little trivial - sorry about that... 😉
I'm attaching screen shot of my code from VWD2010Express.

EDIT:
False alarm - I worked it out using Barra's code:
ArcGISDynamicMapServiceLayer topo = (ArcGISDynamicMapServiceLayer)Map.Layers["Topo"];
            if (topo.VisibleLayers != null)
                foreach (int x in topo.VisibleLayers)
                    identifyParameters.LayerIds.Add(x);
            if (topo.VisibleLayers.Length == 0) return;

Many thanks for publishing it! 🙂
0 Kudos
BrandonCales
Regular Contributor
Glad to here you got it working...

For my ExcludeLayerList, I had added the declaration above 'public MainPage()'

List<int> ExcludeLayerList = new List<int> { 14, 15 }; //These numbers come from the ID for each layer when you list them in REST
0 Kudos
MaciejGolebiewski
Emerging Contributor
I also put it there into "public partial class", but it didn't work correctly, maybe we could leave some support for others?
0 Kudos