Select to view content in your preferred language

Restrict layers or null values in identify task

1466
8
10-01-2012 06:21 AM
JannalynPontello
Deactivated User
I'm using code posted at the end of this thread (http://forums.arcgis.com/threads/25597-How-to-restrict-identify-layers?highlight=identify+null) to use the identify task to query visible layers while restricting two layers.  The problem I'm having is that one of the layers I want to restrict is visible when the app loads, and the Legend is empty until a layer is turned on or off. As a result, the code I added is not finding any layers in the Legend. I tried putting a refresh event using Loaded in the legend definition xaml, but since the legend isn't being loaded until I hover over the legend icon on the toolbar, the refresh event isn't working. Once I hover over the legend, then the tool works as it should.

Alternatively, my end goal is to hide fields with null values in the identify task. I couldn't figure that one out, so I decided to restrict the two layers that contain the null values I want to hide. I'm happy to use either solution, but neither one is working for me.

Any suggestions?
0 Kudos
8 Replies
HyrumErnstrom
Regular Contributor
The TOC and the Identify Task are independant of each other. The Identify Task will only query the layers you tell it to query in the IdentifyParameters Object.

The Layer in the MapControl contains the same information on the LayerIds in the LayerInfo Property as the TOC contol.

You can check to see if the TOC is null then go to the map to get your parameters.


Also sometimes you can startup Controls in Silverlight by calling the Control.ApplyTemplate(). This should only be called if you are sure it's time to initialize the control, if not it could miss part of the initialization and not function properly.
0 Kudos
JannalynPontello
Deactivated User
I add layers to the identify parameters based on whether or not they're checked in the TOC and remove two layers based on the layer index. My problem is that until the TOC is populated, the Legend Items are not loaded, so there's nothing being added to the identify parameters. I tried to load the LegendItemTemplate at the beginning of the function, but because the Legend Items hadn't been loaded, the code didn't do anything. I'm a newbie at writing code, so I'm not sure where to go from here.
0 Kudos
HyrumErnstrom
Regular Contributor
Take a look at
http://resources.arcgis.com/en/help/silverlight-api/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Arc...

There is an example on how to get the default visibility for a layer. Run this code if the TOC isn't initialized yet, because all layers will be in there default state.
0 Kudos
JannalynPontello
Deactivated User
I was in training last week, so I'm just getting back to this. I think I see what's going on in the example, but I just don't have the skills to translate that to my code. There's a lot going on in that example that I don't need (checkboxes, stack panels, etc.), so I haven't been able to pick out the parts that might work for me. Thanks for your suggestions. Loading the TOC shouldn't be this difficult.
0 Kudos
HyrumErnstrom
Regular Contributor

ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer myArcGISDynamicMapServiceLayer = (ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer)(Map1.Layers[0]);
  
  // Get the count of the number of sub-layers in the ArcGISDynamicMapServiceLayer. 

  int numLayers = myArcGISDynamicMapServiceLayer.Layers.Length;

  List<int> visibleLayers = new List<int>();
  
  // Loop through each sub-layer.
  for (var i = 0; i < numLayers; i++)
  {
    // Get the sub-layer visibility.
    bool myLayerVisibility = myArcGISDynamicMapServiceLayer.GetLayerVisibility(i);

    if (myLayerVisibility)
    {
        visibleLayers.Add(i);
     }
  }


0 Kudos
JannalynPontello
Deactivated User
The code runs without an error, but it also queries all layers rather than just the layers that are visible on the map. Is it because GetLayerVisibility checks for the ability to turn on/off layers rather than just layers that are visible on the map?
0 Kudos
HyrumErnstrom
Regular Contributor
In the IdentifyParams make sure you set the LayerOption to visible.
This will only query the layers you have sent with the LayerIds in identifyParams
0 Kudos
JannalynPontello
Deactivated User
LayerOption is already set to visible.
0 Kudos