Select to view content in your preferred language

MapTip's graphic

463
2
01-24-2013 07:07 AM
LanceCrumbliss
Frequent Contributor
What is an easy way to get a reference to the geometry of the graphic associated with a maptip?  When interacting with the maptip, I need a reference to the geometry of the graphic but the maptip mouseover event only passess the attributes to the handler.

Lance
0 Kudos
2 Replies
DominiqueBroux
Esri Frequent Contributor
Unfortunately, I don't figure out any easy way except looping on all graphics and looking for the graphic having the attributes equals to the datacontext of the maptip.
0 Kudos
LanceCrumbliss
Frequent Contributor
looping on every graphic, and in every TypeOf graphicslayer with maptips.....yuck.

Well, i think i found another way: I modified the OnDemand maptip control code to ReturnGeometry = True during the ondemand query that runs during the RequestData method.  In the delegate return handler method, add the geometry as an attribute to the returned features attributes.


    Private Sub RequestData(attributes As IDictionary(Of String, Object))
        If attributes IsNot Nothing AndAlso Not String.IsNullOrEmpty(ObjectIDField) AndAlso
            attributes.ContainsKey(ObjectIDField) AndAlso TypeOf attributes(ObjectIDField) Is Integer Then
            Dim objectId As Integer = CInt(attributes(ObjectIDField))
            If objectId = _currentId OrElse _cachedItems.Contains(objectId) Then
                'Item has already been requested
                Return
            End If


            Dim qt As New QueryTask() With {.Url = QueryUrl}
            Dim q As New Query()
            q.ReturnGeometry = True
            If QueryOutFields IsNot Nothing Then
                For Each outfield As String In QueryOutFields
                    If Not attributes.ContainsKey(outfield) Then
                        q.OutFields.Add(outfield)
                    End If
                Next
            Else
                q.OutFields.Add("*")
            End If
            If q.OutFields.Count > 0 Then
                _cachedItems.Add(objectId)
                q.Where = String.Format("{0}={1}", ObjectIDField, objectId)
                AddHandler qt.ExecuteCompleted, AddressOf qt_ExecuteCompleted
                AddHandler qt.Failed, AddressOf qt_Failed
                qt.ExecuteAsync(q, New Object() {attributes, objectId})
                _currentId = objectId
                _dataRequestInProcess = True
                ChangeVisualState(True)
            End If
        End If
    End Sub

    Private Sub qt_ExecuteCompleted(sender As Object, e As QueryEventArgs)
        Dim state() As Object = CType(e.UserState, Object())
        Dim attr As IDictionary(Of String, Object) = TryCast(state(0), IDictionary(Of String, Object))
        Dim oid As Integer = CInt(state(1))
        If e.FeatureSet.Features.Count > 0 Then
            'Copy the attributes over to the attribute collection for the feature we requested for
            For Each item As KeyValuePair(Of String, Object) In e.FeatureSet.Features(0).Attributes
                attr(item.Key) = item.Value
            Next
            attr.Add(New KeyValuePair(Of String, Object)("_geometry", e.FeatureSet.Features(0).Geometry))
            If _currentId = oid Then
                'False if a new element got opened before request returned
                _dataRequestInProcess = False
                ChangeVisualState(True)
            End If
        End If
    End Sub

0 Kudos