Select to view content in your preferred language

Identify Task into InfoWindow

513
2
11-29-2011 10:59 AM
JayForstner
Emerging Contributor
I am trying to get the results of  an IdentifyTask to populate a InfoWindow from a DynamicMapService in VB.  I used the snippets from the C# post on this same topic, but could not get it to run in VB.  The IdentifyTask works and gets results, but I am not able to have the InfoWindow display.  Any help would be appreciated, thanks in advance!

        <!--MAP-->
        <esri:Map x:Name="MainMap" Extent="417000, 191300, 609400, 322300" Loaded="MainMap_Loaded" IsLogoVisible="False" MouseClick="QueryPoint_MouseClick">
            <esri:ArcGISDynamicMapServiceLayer x:Name="BaseURL" ID="BaseMap" Visible="True" 
         Url="http://gis2/ArcGIS/rest/services/BaseData/MapServer" />
            <esri:ArcGISDynamicMapServiceLayer x:Name="CulvertURL" ID="CulvertMap" Visible="True" 
         Url="http://gis2/ArcGIS/rest/services/Culverts/MapServer" />
        </esri:Map>


    Private Sub QueryPoint_MouseClick(ByVal sender As Object, ByVal e As ESRI.ArcGIS.Client.Map.MouseEventArgs)
        Dim featureLayer As ArcGISDynamicMapServiceLayer = TryCast(MainMap.Layers("CulvertMap"), ArcGISDynamicMapServiceLayer)

        Dim identifyparams As New IdentifyParameters With {.Geometry = e.MapPoint, .MapExtent = MainMap.Extent, .Width = CInt(Fix(MainMap.ActualWidth)), .Height = CInt(Fix(MainMap.ActualHeight)), .LayerOption = LayerOption.visible, .SpatialReference = MainMap.SpatialReference}
        Dim identifyTask As New IdentifyTask(featureLayer.Url)
        AddHandler identifyTask.ExecuteCompleted, AddressOf IdentifyTask_ExecuteCompleted
        AddHandler identifyTask.Failed, AddressOf IdentifyTask_Failed
        identifyTask.ExecuteAsync(identifyparams)
    End Sub

    Private Sub IdentifyTask_ExecuteCompleted(ByVal sender As Object, ByVal args As IdentifyEventArgs)
        If args.IdentifyResults IsNot Nothing AndAlso args.IdentifyResults.Count > 0 Then
            Dim clickPoint As MapPoint = TryCast(args.UserState, MapPoint)

            For Each result As IdentifyResult In args.IdentifyResults
                MyInfoWindow.Anchor = clickPoint
                MyInfoWindow.IsOpen = True
                'Since a ContentTemplate is defined, Content will define the DataContext for the ContentTemplate
                MyInfoWindow.Content = result.Feature.Attributes
                Return
            Next
        End If
    End Sub
0 Kudos
2 Replies
DominiqueBroux
Esri Frequent Contributor
Your clickPoint is probably null.

You use : Dim clickPoint As MapPoint = TryCast(args.UserState, MapPoint)

but you never set the userState.

identifyTask.ExecuteAsync(identifyparams, e.MapPoint) should do it.
0 Kudos
JayForstner
Emerging Contributor
That worked!  Missed that simple error after staring at the screen all day.  Thanks a lot Dominique your help on these forums has been instrumental!
0 Kudos