zoukankan      html  css  js  c++  java
  • arcgis engine 监听element的添加、更新和删除事件(使用IMovePointFeedback)

    VB代码:

    复制进程序稍作修改变量名和事件逻辑即可使用。

    Members

     AllPropertiesMethodsInheritedNon-inheritedDescription
    Write-on<wbr>ly property Display The display the feedback object will use.
    Method MoveTo Move to the new point.
    Method Refresh Call this after a refresh to show feedback again.
    Method Start Begins a move feedback of the given shape.
    Method Stop Stops the feedback and returns the shape.
    Read/write property Symbol The symbol the feedback object will use.

    Moving Feedbacks Example

    This example shows how to create a tool which allows the user to move various geometry types using the appropriate feedback interfaces. The example requires there to be at least one of the following in the current document's BasicGraphicsLayer: MarkerElement, LineElement, RectangleElement, or PolygonElement. When the mouse button is pressed a search is made for any elements which intersect the mouse location. If any are found, then the first of these is taken. If the element's geometry is a Point, Polyline, Envelope or Polygon, then a Feedback object of that type is created, otherwise nothing is created and the routine will exit. Once the feedback has been created, any subsequent mouse movements cause this feedback to be moved on the screen. Releasing the mouse button will stop the feedback and update the element with the new geometry. The ActiveView is then refreshed.

     

    How to use:

    In ArcMap, select Tools | Customize... 

    Select the Commands tab and scroll down to UIControls in the left pane. 

    Click NewUIControl... 

    In the dialog which appears select UIToolControl and then click Create. 

    Drag the new tool which appears in the right pane onto a toolbar of your choosing. 

    Right-click over your tool on the toolbar and select View Source. 

    Copy and paste the code below into the VBA code pane which appears. 

    Close the VBA Window and return to the ArcMap Window. 

    Now select your tool from the toolbar and click on a graphic element (Marker, Line, Rectangle, Polygon) and move the mouse until the desired location is reached. Releasing the mouse button to finish. 

    Private m_pDoc As IMxDocument
    
    Private m_pAV As IActiveView
    
    Private m_pScrD As IScreenDisplay
    
    Private m_pDispFeed As IDisplayFeedback
    
    Private m_pHitElem As IElement
    
    Private m_pGraCont As IGraphicsContainer
    
     
    
    Private Function UIToolControl1_Enabled() As Boolean
    
      'Set the ToolControl to enabled (disabled by default)
    
      UIToolControl1_Enabled = True
    
    End Function
    
     
    
    Private Sub UIToolControl1_MouseDown(ByVal button As Long, ByVal shift As Long, ByVal x As Long, ByVal y As Long)
    
      Dim pPnt As IPoint
    
      Dim pGeomElem As IGeometry
    
      
    
      ' Get the current mouse location in Map Units
    
      Set pPnt = m_pScrD.DisplayTransformation.ToMapPoint(x, y)
    
      ' Use a function to return the first element at this point (if any)
    
      Set m_pHitElem = GetHitElement(pPnt)
    
      
    
      ' If an element was returned then check what type of geometry it has (Point, Polyline, Envelope or Polygon)
    
      If Not m_pHitElem Is Nothing Then
    
        Set pGeomElem = m_pHitElem.Geometry
    
        'Point geometry
    
        If TypeOf pGeomElem Is IPoint Then
    
          ' Create a MovePointFeedback object and set its display property (to the ActiveView's ScreenDisplay)
    
          Set m_pDispFeed = New MovePointFeedback
    
          Set m_pDispFeed.Display = m_pScrD
    
          ' QI for the IMovePointFeedback interface
    
          Dim pMvPtFeed As IMovePointFeedback
    
          Set pMvPtFeed = m_pDispFeed
    
          'Start the feedback using the input (Point) geometry at the current mouse location
    
          pMvPtFeed.Start pGeomElem, pPnt
    
      
    
        ' Polyline geometry
    
        ElseIf TypeOf pGeomElem Is esriCore.IPolyline Then
    
          ' Create a MoveLineFeedback object and set its display property (to the ActiveView's ScreenDisplay)
    
          Set m_pDispFeed = New MoveLineFeedback
    
          Set m_pDispFeed.Display = m_pScrD
    
          ' QI for the IMoveLineFeedback interface
    
          Dim pMvLnFeed As IMoveLineFeedback
    
          Set pMvLnFeed = m_pDispFeed
    
          'Start the feedback using the input (Polyline) geometry at the current mouse location
    
          pMvLnFeed.Start pGeomElem, pPnt
    
        
    
        ' Rectangle (Envelope) geometry
    
        ElseIf TypeOf pGeomElem Is IEnvelope Then
    
          ' Create a MoveEnvelopeFeedback object and set its display property (to the ActiveView's ScreenDisplay)
    
          Set m_pDispFeed = New MoveEnvelopeFeedback
    
          Set m_pDispFeed.Display = m_pScrD
    
          ' QI for the IMoveEnvelopeFeedback interface
    
          Dim pMvEnvFeed As IMoveEnvelopeFeedback
    
          Set pMvEnvFeed = m_pDispFeed
    
          'Start the feedback using the input (Rectangle) geometry at the current mouse location
    
          pMvEnvFeed.Start pGeomElem, pPnt
    
        
    
        ' Polygon geometry
    
        ElseIf TypeOf pGeomElem Is IPolygon Then
    
          ' Create a MovePolygonFeedback object and set its display property (to the ActiveView's ScreenDisplay)
    
          Set m_pDispFeed = New MovePolygonFeedback
    
          Set m_pDispFeed.Display = m_pScrD
    
          ' QI for the IMovePolygonFeedback interface
    
          Dim pMvPolyFeed As IMovePolygonFeedback
    
          Set pMvPolyFeed = m_pDispFeed
    
          'Start the feedback using the input (Polygon) geometry at the current mouse location
    
          pMvPolyFeed.Start pGeomElem, pPnt
    
        End If
    
      End If
    
    End Sub
    
     
    
    Private Sub UIToolControl1_MouseMove(ByVal button As Long, ByVal shift As Long, ByVal x As Long, ByVal y As Long)
    
      If Not m_pDispFeed Is Nothing Then
    
        
    
        Dim pPnt As IPoint
    
        ' Get the current mouse location in Map Units and move the feedback
    
        Set pPnt = m_pScrD.DisplayTransformation.ToMapPoint(x, y)
    
        m_pDispFeed.MoveTo pPnt
    
      End If
    
    End Sub
    
     
    
    Private Sub UIToolControl1_MouseUp(ByVal button As Long, ByVal shift As Long, ByVal x As Long, ByVal y As Long)
    
      Dim GeomResult As IGeometry
    
      Dim pGeomElem As IGeometry
    
      
    
      ' Check that the user is using the feedback
    
      If Not m_pHitElem Is Nothing Then
    
        ' Get the geometry type for our element again
    
        Set pGeomElem = m_pHitElem.Geometry
    
        
    
        ' Check what type of geometry the element has  (again)
    
        ' Point geometry
    
        If TypeOf pGeomElem Is IPoint Then
    
          ' QI for the IMovePointFeedback interface and get the finished geometry
    
          Dim pMvPtFeed As IMovePointFeedback
    
          Set pMvPtFeed = m_pDispFeed
    
          Set GeomResult = pMvPtFeed.Stop
    
        ElseIf TypeOf pGeomElem Is IPolyline Then
    
          ' QI for the IMoveLineFeedback interface and get the finished geometry
    
          Dim pMvLnFeed As IMoveLineFeedback
    
          Set pMvLnFeed = m_pDispFeed
    
          Set GeomResult = pMvLnFeed.Stop
    
        ElseIf TypeOf pGeomElem Is IEnvelope Then
    
          ' QI for the IMoveEnvelopeFeedback interface and get the finished geometry
    
          Dim pMvEnvFeed As IMoveEnvelopeFeedback
    
          Set pMvEnvFeed = m_pDispFeed
    
          Set GeomResult = pMvEnvFeed.Stop
    
          
    
        ElseIf TypeOf pGeomElem Is IPolygon Then
    
          ' QI for the IMovePolygonFeedback interface and get the finished geometry
    
          Dim pMvPolyFeed As IMovePolygonFeedback
    
          Set pMvPolyFeed = m_pDispFeed
    
          Set GeomResult = pMvPolyFeed.Stop
    
            
    
        End If
    
      
    
        ' Set the geometry of the element and call update
    
        m_pHitElem.Geometry = GeomResult
    
        m_pGraCont.UpdateElement m_pHitElem
    
        
    
        ' Clear out the objects
    
        Set m_pDispFeed = Nothing
    
        Set m_pHitElem = Nothing
    
        
    
        ' Refresh the ActiveView
    
        m_pAV.Refresh
    
      End If
    
    End Sub
    
     
    
    Private Sub UIToolControl1_Refresh(ByVal hDC As Long)
    
      'Get a reference to the ActiveView and ScreenDisplay
    
      Set m_pDoc = Application.Document
    
      Set m_pAV = m_pDoc.ActiveView
    
      Set m_pScrD = m_pAV.ScreenDisplay
    
    End Sub
    
     
    
    Private Sub UIToolControl1_Select()
    
      'Get a reference to the ActiveView and ScreenDisplay
    
      Set m_pDoc = Application.Document
    
      Set m_pAV = m_pDoc.ActiveView
    
      Set m_pScrD = m_pAV.ScreenDisplay
    
    End Sub
    
     
    
    Private Function GetHitElement(pInPt As IPoint) As IElement
    
    ' Takes an IPoint and returns the first element that is hit (if any) in the ActiveView's BasicGraphicsLayer
    
      Dim pEnumElem As IEnumElement
    
      Dim DblSrchDis As Double
    
      
    
      ' QI for the IGraphicsContainer interface from the IActiveView, allows access to the BasicGraphicsLayer
    
      Set m_pGraCont = m_pAV
    
      
    
      ' Calculate the Search Distance (in MapUnits) based upon a portion of the ActiveView's width
    
      DblSrchDis = m_pAV.Extent.Width / 200
    
      
    
      ' Return an enumerator for those elements found within the search distance (in mapunits)
    
      Set pEnumElem = m_pGraCont.LocateElements(pInPt, DblSrchDis)
    
      
    
      ' If the enumerator is not empty then return the FIRST element found
    
      If Not pEnumElem Is Nothing Then
    
        Set GetHitElement = pEnumElem.Next
    
      End If
    
     
    
    End Function
  • 相关阅读:
    print流
    java数据流
    java转换流
    爬虫(二):urllib库文件的基础和进阶(python2.7)
    爬虫实例(二):多线程,多进程对网页的爬取
    Java多线程分析 (二)---- 高并发内存模型和线程安全
    Java多线程分析 (五)---高并发线程池
    Java 多线程分析 (四) ---高并发基础知识)
    Java(生产者与消费者方法)
    Java 多线程分析 (三) --- synchronize 同步
  • 原文地址:https://www.cnblogs.com/jhlong/p/5394545.html
Copyright © 2011-2022 走看看