Select to view content in your preferred language

identify

920
4
12-06-2010 08:24 AM
JayKappy
Frequent Contributor
I am using the example fro identify from this page:
http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#Identify

I am using the code as is from the exampel above...no modifications...

I have it working but now want to change the layer that is being identiftified...
I went here to find another identifiable layer..
http://services.arcgisonline.com/ArcGIS/rest/services

I tried these: BUT THE only one that works with the identify is the first one (supplied int eh example)....WHY IS THIS? Why cant I identify....seems nothing is beign returned....I dont get errors but no data return....very confused....

        Dim identifyTask2 As New IdentifyTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/" & "Demographics/ESRI_Census_USA/MapServer")
        Dim identifyTask2 As New IdentifyTask("http://services.arcgisonline.com/ArcGIS/rest/services/" & "Demographics/ESRI_Population_World/MapServer")
        Dim identifyTask2 As New IdentifyTask("http://services.arcgisonline.com/ArcGIS/rest/services/" & "Demographics/USA_Unemployment_Rate/MapServer")
        Dim identifyTask2 As New IdentifyTask("http://services.arcgisonline.com/ArcGIS/rest/services/" & "Reference/ESRI_BoundariesPlaces_World_2D/MapServer")
        Dim identifyTask2 As New IdentifyTask("http://services.arcgisonline.com/ArcGIS/rest/services/" & "Demographics/USA_Median_Household_Income/MapServer")
0 Kudos
4 Replies
JenniferNery
Esri Regular Contributor
This is a related thread: http://forums.arcgis.com/threads/16609-do-I-have-to-change-spatial-reference-for-map-services-for-id...

The other services belong to a different spatial reference, you need to specify that in code when creating your IdentifyParameters. http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Tasks.Iden...
0 Kudos
JayKappy
Frequent Contributor
I thank you for your response....I am very new to this and am using code from an ESRI example (identify)

THis is the code that is fired when the user clicks on the map....
This is the code that I am using...this is where the Identify Params are being set right?
What needs to change?

    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 identifyTask2 As New IdentifyTask("http://services.arcgisonline.com/ArcGIS/rest/services/" & "Demographics/USA_Median_Household_Income/MapServer")
        AddHandler identifyTask2.ExecuteCompleted, AddressOf IdentifyTask2_ExecuteCompleted
        AddHandler identifyTask2.Failed, AddressOf IdentifyTask2_Failed
        identifyTask2.ExecuteAsync(identifyParams)

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

    End Sub



THANKS FOR YOUR HELP AND PATIENCE....VERY APPRECIATED
0 Kudos
JayKappy
Frequent Contributor
ahhhh

Looks like I am missign the spatial reference....going to put that in and see what happens....
0 Kudos
JayKappy
Frequent Contributor
THATS IT....THANKS FOR YOUR HELP...SO VERY APPRECIATED....

THIS IS MY total Identify code in VB...The addition to allow this is highlighted in RED....you will have to scroll to the right in the first sub "QueryPoint_MouseClick"

All from the ESRI example on Identify....This was the only addition to the code

    '===========================================================================================================================
    ' IDENTIFY START
    '===========================================================================================================================
    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, .SpatialReference = MyMap.SpatialReference, .Width = CInt(Fix(MyMap.ActualWidth)), .Height = CInt(Fix(MyMap.ActualHeight)), .LayerOption = LayerOption.visible}

        Dim identifyTask2 As New IdentifyTask("http://services.arcgisonline.com/ArcGIS/rest/services/" & "Demographics/USA_Median_Household_Income/MapServer")

        AddHandler identifyTask2.ExecuteCompleted, AddressOf IdentifyTask2_ExecuteCompleted
        AddHandler identifyTask2.Failed, AddressOf IdentifyTask2_Failed
        identifyTask2.ExecuteAsync(identifyParams)

        Dim graphicsLayer As GraphicsLayer = TryCast(MyMap.Layers("MyLayer"), GraphicsLayer)
        graphicsLayer.ClearGraphics()
        Dim graphic As New ESRI.ArcGIS.Client.Graphic() With {.Geometry = clickPoint, .Symbol = PushPinPictureSymbol}
        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

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

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

            If IdentifyResultsPanel.Visibility = Visibility.Visible Then
                IdentifyResultsPanel.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
0 Kudos