Wednesday, August 25, 2010

Skapat verktyg med IDisplayFeedback.

Vi har problem med standard mätverktyget i ArcGIS engine. Bug in ControlMapMeasureTool? “Measure An Area” creates a duplicate dialog in ArcGIS Engine 10 Så jag har suttit efter tips från Kirk och labbat lite hur man kan skapa egna verktyg med IDisplayFeedback. Hittade ett bra exempel Sample: Custom subtyped command and tool som visade hur man ska göra. Skapar man en ny verktygsklass, så kan man överlagra på det här sättet för att få ett verktyg som mäter areal:

 Private m_polygonFeedback As INewPolygonFeedback  
Private m_screenDisplay As IScreenDisplay

Private m_hookHelper As IHookHelper


Public Overrides Sub OnCreate(ByVal hook As Object)
If (m_hookHelper Is Nothing) Then m_hookHelper = New HookHelperClass

If Not hook Is Nothing Then
m_hookHelper.Hook = hook
End If
End Sub

Public Overrides Sub OnClick()
m_screenDisplay = m_hookHelper.ActiveView.ScreenDisplay
End Sub

Public Overrides Sub OnDblClick()
Dim polygon As IPolygon = m_polygonFeedback.Stop()
MsgBox("Area: " & CType(polygon, IArea).Area)
m_polygonFeedback = Nothing
End Sub

Public Overrides Sub OnMouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Integer, ByVal Y As Integer)
If Button = 1 Then
Dim cursorPoint As ESRI.ArcGIS.Geometry.IPoint = m_screenDisplay.DisplayTransformation.ToMapPoint(X, Y)

If m_polygonFeedback Is Nothing Then
m_polygonFeedback = New NewPolygonFeedbackClass()
m_polygonFeedback.Display = m_screenDisplay

m_polygonFeedback.Start(cursorPoint)
Else
m_polygonFeedback.AddPoint(cursorPoint)
End If

End If
End Sub

Public Overrides Sub OnMouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Integer, ByVal Y As Integer)
If Not m_polygonFeedback Is Nothing Then
Dim cursorPoint As ESRI.ArcGIS.Geometry.IPoint = m_screenDisplay.DisplayTransformation.ToMapPoint(X, Y)
m_polygonFeedback.MoveTo(cursorPoint)
End If
End Sub