VB代码:

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

Members

  AllPropertiesMethodsInheritedNon-inherited Description
Display The display the feedback object will use.
MoveTo Move to the new point.
Refresh Call this after a refresh to show feedback again.
Start Begins a move feedback of the given shape.
Stop Stops the feedback and returns the shape.
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 / 

  ' 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

arcgis engine 监听element的添加、更新和删除事件(使用IMovePointFeedback)的更多相关文章

  1. arcgis engine 监听element的添加、更新和删除事件(使用IGraphicsContainerEvents)

    IGraphicsContainerEvents Interface 如何监听 element事件? 如,当我们在Mapcontrol上添加.删除.更新了一个Element后,如何捕捉到这个事件?   ...

  2. 如何监听Element组件<el-input>标签的回车事件

    一.现象 表单提交时需要处理输入框的回车事件,一般的原生input标签可以用@keyup.enter="onSubmit"(tips:onSubmit为定义的方法) 二.解决 1. ...

  3. ArcGIS Engine效率探究——要素的添加和删除、属性的读取和更新

    ArcGIS Engine效率探究——要素的添加和删除.属性的读取和更新 来自:http://blog.csdn.net/freewaywalker/article/details/23703863 ...

  4. [转] ArcGIS engine中气泡标注的添加、修改

    小生 原文 ArcGIS engine中气泡标注的添加.修改! 你微微地笑着,不同我说什么话.而我觉得,为了这个,我已等待得久了.                                   ...

  5. Android 另类方法监听软键盘的弹出收起事件

    http://www.cnblogs.com/csonezp/p/5065624.html 最近做的项目碰到个问题,a界面是fragment+recyclerview,b界面带个edittext,并且 ...

  6. Canal 实战 | 第一篇:SpringBoot 整合 Canal + RabbitMQ 实现监听 MySQL 数据库同步更新 Redis 缓存

    一. Canal 简介 canal [kə'næl],译意为水道/管道/沟渠,主要用途是基于 MySQL 数据库增量日志解析,提供增量数据订阅和消费 早期阿里巴巴因为杭州和美国双机房部署,存在跨机房同 ...

  7. vue watch 监听element upload组件上传成功返回的url列表

    因为 on-success 上传成功返回的是一个异步的结果....如果父组件需要这个结果的话 必须用watch 监听 然后里面建立一个 save()方法 save方法里面再调用接口 传需要的上传之后的 ...

  8. angular指令监听ng-repeat渲染完成后执行自定义事件方法

    今天工作中遇到需要用到ng-repeat遍历渲染完后执行某个操作,angular本身并没有提供监听ng-repeat渲染完成的指令,所以需要自己创建自定义指令. 在ng-repeat模板实例内部会暴露 ...

  9. 监听文本框输入oninput和onpropertychange事件

    前端页面开发的很多情况下都需要实时监听文本框输入,比如腾讯微博编写140字的微博时输入框动态显示还可以输入的字数.过去一般都使用onchange/onkeyup/onkeypress/onkeydow ...

随机推荐

  1. java弱引用之WeakHashMap相关资料

    本人博客中有一篇文章对java中的引用有详细的介绍[http://www.cnblogs.com/javaee6/p/4763190.html],java中WeakHashMap这个类就是java弱引 ...

  2. android 项目中出现红色感叹号的解决方法

    问题原因]:工程中classpath中指向的包路径错误 [解决办法]:右键项目名称 BuildPath ---> Configure Build Paht...中,然后上面有几个选项卡找到 Li ...

  3. Hadoop op 1)

    设置yarn.scheduler.fair.user-as-default-queue =fasle, 就会阻止每一个用户使用自己默认的队列. 设置yarn.scheduler.fair.allow- ...

  4. MMORPG大型游戏设计与开发(服务器 游戏场景 掉落与网络连接)

    时间一点点的消逝,伴着自己空闲日子将要结束的时候我尽量的学习和分享场景和AI的知识给朋友们,不过很遗憾的是这些文章还有不足的地方,就是有的难点没有完全的分析到.掉落在游戏中必不可少的,同时网络连接也是 ...

  5. HDU 4622 Reincarnation (查询一段字符串的不同子串个数,后缀自动机)

    Reincarnation Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)To ...

  6. java线程池(newSingleThreadExecutor())小应用

    创建单个线程,用来操作一个无界的队列任务,不会使用额外的线程.如果线程崩溃会重新创建一个,直到任务完成. 代码: import java.util.concurrent.ExecutorService ...

  7. iOS Photos.framework框架

    链接: iOS8.0 使用Photos.framework对相册的常用操作 iOS AssetsLibrary和Photos的使用总结: 权限及相册的获取 iOS 开发之照片框架详解 iOS Asse ...

  8. 监控jvm的一个坑

    监控jvm的一个坑 1,遇到的问题 我按照以往文档,在catalina.sh里追加jvm的监控api,如下 紧接着我启动 tomcat. 未报任何错误. 发现 lsof –i:12000, 12000 ...

  9. Linux 进程间通讯详解七

    上图的一台主机服务器架构的重大缺陷是容易死锁 因为客户端,服务器都往同一消息队列中发送接收消息,假设消息队列已经满了,此时客户端无法向队列中发送消息,阻塞了,而服务器接收完一条消息后,想向消息队列发送 ...

  10. Python-13-堡垒机开发

    今天主要是熟悉堡垒机开发流程.