Layers missing from identify results

2943
2
04-27-2010 01:37 PM
DonFreeman
New Contributor
I have implemented the identify sample as shown in the ESRI samples at
http://resources.esri.com/help/9.3/arcgisserver/apis/silverlight/samples/start.htm#Identify

It seems to work OK BUT . . .

My map consists of 2 roadway layers plus any one of 3 layers showing the area's school districts. The 3 school layers are turned on/off by making selections with a checkbox to display elementary, middle, or high schools. My problem is that irregardless of which school layer is displayed, the identify always reveals only the elementary and roadway layer data. How can I cause the identify results to contain the visible school layer data? Code below.
Thanks

#Region "Identify"

 Private Sub QueryPoint_MouseClick(ByVal sender As Object, ByVal e As ESRI.ArcGIS.Client.Map.MouseEventArgs)
  Dim clickPoint As ESRI.ArcGIS.Client.Geometry.MapPoint = e.MapPoint

  Dim identifyParams As ESRI.ArcGIS.Client.Tasks.IdentifyParameters = New IdentifyParameters() With {.Geometry = clickPoint, .MapExtent = MyMap.Extent, .Width = CInt(Fix(MyMap.ActualWidth)), .Height = CInt(Fix(MyMap.ActualHeight)), .LayerOption = LayerOption.visible}

  Dim identifyTask As New IdentifyTask("http://maps.pagnet.org/arcgis/rest/services/SchoolSearch2/MapServer")
  AddHandler identifyTask.ExecuteCompleted, AddressOf IdentifyTask_ExecuteCompleted
  AddHandler identifyTask.Failed, AddressOf IdentifyTask_Failed
  identifyTask.ExecuteAsync(identifyParams)

  Dim graphicsLayer As GraphicsLayer = TryCast(MyMap.Layers("MyGraphicsLayer"), GraphicsLayer)
  graphicsLayer.ClearGraphics()
  Dim graphic As New ESRI.ArcGIS.Client.Graphic() With {.Geometry = clickPoint, .Symbol = DefaultPictureSymbol}
  graphicsLayer.Graphics.Add(graphic)
 End Sub

 Public Sub ShowFeatures(ByVal results As List(Of IdentifyResult))
  _dataItems = New List(Of DataItem)()

  If results IsNot Nothing AndAlso results.Count > 0 Then
   IdentifyComboBox.Items.Clear()
   For Each result As IdentifyResult In results
    Dim feature As Graphic = result.Feature
    Dim title As String = result.Value.ToString() & " (" & result.LayerName & ")"
    _dataItems.Add(New DataItem() With {.Title = title, .Data = feature.Attributes})
    IdentifyComboBox.Items.Add(title)
   Next result

   ' Workaround for bug with ComboBox 
   IdentifyComboBox.UpdateLayout()

   IdentifyComboBox.SelectedIndex = 0
  End If
 End Sub

 Private Sub cb_SelectionChanged(ByVal sender As Object, ByVal e As SelectionChangedEventArgs)
  Dim index As Integer = IdentifyComboBox.SelectedIndex
  If index > -1 Then
   IdentifyDetailsDataGrid.ItemsSource = _dataItems(index).Data
  End If
 End Sub

 Private Sub IdentifyTask_ExecuteCompleted(ByVal sender As Object, ByVal args As IdentifyEventArgs)
  IdentifyDetailsDataGrid.ItemsSource = Nothing
  IdentifyResultsPanel.Visibility = Windows.Visibility.Visible

  If args.IdentifyResults IsNot Nothing AndAlso args.IdentifyResults.Count > 0 Then
   If DataGridScrollViewer.Visibility = Visibility.Collapsed Then
    DataGridScrollViewer.Visibility = Visibility.Visible
    IdentifyGrid.Height = Double.NaN
    IdentifyGrid.UpdateLayout()
   End If

   ShowFeatures(args.IdentifyResults)
  Else
   IdentifyComboBox.Items.Clear()
   IdentifyComboBox.UpdateLayout()

   If DataGridScrollViewer.Visibility = Visibility.Visible Then
    DataGridScrollViewer.Visibility = Visibility.Collapsed
    IdentifyGrid.Height = Double.NaN
    IdentifyGrid.UpdateLayout()
   End If
  End If
 End Sub

 Public Class DataItem
  Private privateTitle As String
  Public Property Title() As String
   Get
    Return privateTitle
   End Get
   Set(ByVal value As String)
    privateTitle = value
   End Set
  End Property
  Private privateData As IDictionary(Of String, Object)

  Public Property Data() As IDictionary(Of String, Object)
   Get
    Return privateData
   End Get
   Set(ByVal value As IDictionary(Of String, Object))
    privateData = value
   End Set
  End Property
 End Class

 Private Sub IdentifyTask_Failed(ByVal sender As Object, ByVal e As TaskFailedEventArgs)
  MessageBox.Show("Identify failed. Error: " & e.Error.Message)
 End Sub

#End Region
0 Kudos
2 Replies
DominiqueBroux
Esri Frequent Contributor
You have to initialize the LayerIds property of your identifyParameter with the list of currently visible layers.

The confusion is coming from the 'visible' value of the LayerOption. This option means 'identify the layers visible in the map service' (i.e the layers visible before you turned on/off some layers  by code).

/Dominique
0 Kudos
DonFreeman
New Contributor
OK Thanks. I was able to get what I want with this change. Note, I had to change the layer option to all to make them all available as needed.

  Dim identifyParams As ESRI.ArcGIS.Client.Tasks.IdentifyParameters = New IdentifyParameters() With {.Geometry = clickPoint, .MapExtent = MyMap.Extent, .Width = CInt(Fix(MyMap.ActualWidth)), .Height = CInt(Fix(MyMap.ActualHeight)), .LayerOption = LayerOption.all}

  If Elementary_Checkbox.IsChecked Then
   identifyParams.LayerIds.Add(2)
  End If
  If Middle_Checkbox.IsChecked Then
   identifyParams.LayerIds.Add(5)
  End If
  If High_Checkbox.IsChecked Then
   identifyParams.LayerIds.Add(8)
  End If
0 Kudos