Select to view content in your preferred language

Identify Task issues

5058
25
04-13-2010 08:40 AM
AngelGonzalez
Frequent Contributor
I am using the ESRI sample for Identify and got a problem. I have a sublayer list with about 13 layers. Only the first 4 are set to be visible when the silverlight app is first run. The identify Task works fine with these first 4 layers. When I click on the checkbox to make another layer visible and use the Identify tool the fifth layer does not appear on the identify tool. Yet when I go back and update the mxd to make the fifth layer visible and reboot my ArcGIS server (the refreshing of a service to pickup and any changes made to the mxd is not being pickup by Silverlight app, only a reboot will do this , bug??) the identify tool picks up the the fifth layer. 

Does the Identify task works with sublayer list? Do I need to refresh something?
I am using SL3 with ESRI 1.2 SL API

Thanks

Angel
0 Kudos
25 Replies
dotMorten_esri
Esri Notable Contributor
Did you set the LayerIds property on the identify parameters to match the visible layers of the map?
0 Kudos
AngelGonzalez
Frequent Contributor
Yes, I found the following thread:

http://forums.esri.com/Thread.asp?c=158&f=2455&t=298582&mc=11

and it gave me some clues.  Debugging in VS and with Fiddler I see the Layerid being sent across but it is not returning anything for this layer.  If I turn off a layer that was originally set to be visible and do an identify it does not show up(which is correct). If I turn on this same layer again it does.  The only issues are with layers whose visibility are set to false at startup.  Any clues?

Thanks

Angel
0 Kudos
ERNESTOGIRON
Deactivated User
angelg:

As shapGIS said you have to set the LayersIds property, but don't set LayerOption at the same time. Use LayerOption property (All, Top, Visible) if you start up your service with any layer visible.

Try to use for example LayerIds = [0,1,2,etc] . It works for me using 110 layers off at startup.

I hope it helps.
0 Kudos
DavidAshton
Frequent Contributor
Hello egrion or angelg,

I am trying to follow your guys trail of post to solve the same problem that angelg was looking to solve.  I was hoping to link up my sublayer list with the identify tool so the identify tool only works with the layers that are checked visible.  Currently I have over 50 layers and it takes a while to identify because it is identifing all 50 and I only want to identify the one visible.  I'm having trouble. Would/Could you post your code to get these two tools to work together?

Thanks
Dave
0 Kudos
DavidAshton
Frequent Contributor
angelg:

As shapGIS said you have to set the LayersIds property, but don't set LayerOption at the same time. Use LayerOption property (All, Top, Visible) if you start up your service with any layer visible.

Try to use for example LayerIds = [0,1,2,etc] . It works for me using 110 layers off at startup.

I hope it helps.



Ernesto,

If I change the  LayerOption = LayerOption.all    the identify tool will identify all my layers no matter what is checked in my sublayer list.  If I change  LayerOption = LayerOption.visible the identify tool doesn't respect the layerlist.....it only identifies the layers that were visible at startup. 

Where do I hard code the layers (like you stated)  LayerIds = [0,1,2,etc]  I can't find this code and I'm unsure where to add it? 

Or better yet how do I make the identify pick up the new visible layers from the sublayer list?

Thanks
D


  #region Identify
        // Jay's Identify

        private void QueryPoint_MouseClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            e.Handled = true; // to get rid of the default "Silverlight" Context Menu.
            ESRI.ArcGIS.Client.Geometry.MapPoint clickPoint = this.Map.ScreenToMap(e.GetPosition(Map));


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

            IdentifyTask identifyTask = new IdentifyTask("http://hqtr-gis10/ArcGIS/rest/services/DRECP_20101008/MapServer");
            identifyTask.ExecuteCompleted += IdentifyTask_ExecuteCompleted;
            identifyTask.Failed += IdentifyTask_Failed;
            identifyTask.ExecuteAsync(identifyParams);

            GraphicsLayer graphicsLayer = Map.Layers["MySelectionGraphicsLayer"] 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);
        }

        public void ShowFeatures(List<IdentifyResult> results)
        {
            _dataItems = new List<DataItem>();

            if (results != null && results.Count > 0)
            {
                IdentifyComboBox.Items.Clear();
                foreach (IdentifyResult result in results)
                {
                    Graphic feature = result.Feature;
                    string title = result.Value.ToString() + " (" + result.LayerName + ")";
                    _dataItems.Add(new DataItem()
                    {
                        Title = title,
                        Data = feature.Attributes
                    });
                    IdentifyComboBox.Items.Add(title);
                }
                IdentifyComboBox.SelectedIndex = 0;
            }
        }

        void cb_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            int index = IdentifyComboBox.SelectedIndex;
            if (index > -1)
                IdentifyDetailsDataGrid.ItemsSource = _dataItems[index].Data;
        }

        private void IdentifyTask_ExecuteCompleted(object sender, IdentifyEventArgs args)
        {
            IdentifyDetailsDataGrid.ItemsSource = null;

            if (args.IdentifyResults != null && args.IdentifyResults.Count > 0)
            {
                IdentifyResultsPanel.Visibility = Visibility.Visible;

                ShowFeatures(args.IdentifyResults);
                ShowIDtab.Begin();
            }
            else
            {
                IdentifyComboBox.Items.Clear();
                IdentifyComboBox.UpdateLayout();

                IdentifyResultsPanel.Visibility = Visibility.Collapsed;
                
            }
        }

        public class DataItem
        {
            public string Title { get; set; }
            public IDictionary<string, object> Data { get; set; }
        }

        void IdentifyTask_Failed(object sender, TaskFailedEventArgs e)
        {
            MessageBox.Show("Identify failed. Error: " + e.Error);
        }


        //end Jay's identify
        #endregion 
0 Kudos
MarkCederholm
Frequent Contributor
I'm trying to set the LayerIDs property and Visual Studio says it's read-only.  Is that a bug?
0 Kudos
dotMorten_esri
Esri Notable Contributor
The property is read only, but the collection is not.
Ie: identifyParams.LayerIDs.Add(1);
0 Kudos
MarkCederholm
Frequent Contributor
That did the trick.  Thanks!
0 Kudos
DavidAshton
Frequent Contributor
With the help of Morton answering Mark question I was able to somewhat answer mine.  Now I�??m hoping maybe Mark, Morton, Ernesto or some other kind sole will be able to help me Solve the final parts of my problem.

I took what Morton told Mark and add this to my code, it seems like it now only identifies the layers 1,5,14,17, and 18.  But it doesn�??t respect the fact if they are visible.  If I set LayerOption = LayerOption.visible it only works for the layers visible at start up and doesn't respect the identifyParams.LayerIds.Add statements. 

Two questions:
Is there a way to have the identify tool respect the sublayer list visible layers?

Like Ernesto pointed out how do I just write identifyParams.LayerIds.Add(1,5,17,18) or identifyParams.LayerIds.Add[1,5,17,18], both give errors in VS; I don�??t want to keep listing identifyParams.LayerIds.Add() over and over.


ESRI.ArcGIS.Client.Tasks.IdentifyParameters identifyParams = new IdentifyParameters

            
            {
                
                Geometry = clickPoint,
                MapExtent = Map.Extent,
                Width = (int)Map.ActualWidth,
                Height = (int)Map.ActualHeight,
                LayerOption = LayerOption.all,
            
                

            };
            //these identifyParams.LayerIds.Add do nothing if LayerOption is set to visible
           //these identifyParams.LayerIds.Add work if LayerOption is set to all but doesn't respect if the layers are turned on/off

            identifyParams.LayerIds.Add(1);
            identifyParams.LayerIds.Add(5);
            identifyParams.LayerIds.Add(14);
            identifyParams.LayerIds.Add(17);
            identifyParams.LayerIds.Add(18);


            // identifyParams.LayerIds = [2, 5];  This errors out not sure how to list a list


0 Kudos