INewFeedBack接口--ArcGlobe

'该函数可以在二维和三维中使用

Private Function DrawLineUseDisplay(ByVal pActiveView As IActiveView, ByVal point1 As IPoint, ByVal point2 As IPoint, ByVal pLinesym As ILineSymbol) As IElement
        '使用iNewLineFeedback接口来画,涉及到Display
        Dim pNewLineFeedback As INewLineFeedback = New NewLineFeedback
        pNewLineFeedback.Display = pActiveView.ScreenDisplay
        pNewLineFeedback.Symbol = pLinesym

        Dim pElement As IElement = New LineElement
        Dim pLineElement As ILineElement
        pLineElement = pElement
        Dim feedbackLine As IGeometry = New Polyline

        pNewLineFeedback.Start(point1)

        pNewLineFeedback.AddPoint(point1)
        pNewLineFeedback.MoveTo(point1)
        pNewLineFeedback.AddPoint(point2)
        pNewLineFeedback.MoveTo(point2)

        '把图形保存下来

        feedbackLine = pNewLineFeedback.Stop()

        pLineElement = pElement
        pLineElement.Symbol = pLinesym

        pElement.Geometry = feedbackLine '把生成的polyline赋予element

        Return pElement
    End Function

'-----------------------
'三维中调用示例
 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        '与显示有关的设置
        Dim pGL As IGlobeGraphicsLayer
        pGL = New GlobeGraphicsLayer

        Dim pGEP As IGlobeGraphicsElementProperties

        '显示
        Dim pScene As IScene
        Dim pGlobeDisplay As IGlobeDisplay

        pGlobeDisplay = m_globe.GlobeDisplay
        pScene = pGlobeDisplay.Scene

        '图层属性设置
        pGEP = New GlobeGraphicsElementProperties
        pGEP.DrapeElement = True
        pGEP.DrapeZOffset = 500000
        '创建layer
        Dim pLayer As ILayer
        pLayer = pGL
        'pLayer = pGC3D
        pLayer.Name = "Layer1"
        m_globe.AddLayerType(pLayer, esriGlobeLayerType.esriGlobeLayerTypeDraped)
        pScene.ActiveGraphicsLayer = pLayer
        pGL = pLayer

        Dim pelement As IElement
        Dim pActiveView As IActiveView

        Dim pRedColor As IColor = New RgbColor
        Dim pLineSym As ISimpleLineSymbol = New SimpleLineSymbol

        pRedColor.RGB = RGB(230, 0, 0)
        pLineSym.Color = pRedColor
        pLineSym.Style = esriSimpleLineStyle.esriSLSSolid
        pLineSym.Width = 2

        Dim p1 As IPoint = New Point
        Dim p2 As IPoint = New Point

        p1.PutCoords(0, 0)
        p1.Z = 100000

        p2.PutCoords(50, 50)
        p2.Z = 100000

        pActiveView = m_globeControl.Globe

        pelement = DrawLineUseDisplay(pActiveView, p1, p2, pLineSym)
        'pelement = DrawLineWithPoints3D(p1, p2, True, pLineSym)

        pGL.AddElement(pelement, pGEP, 0)

        pActiveView.Refresh()

    End Sub

'----------------------
'二维中调用示例
 Dim pActiveView As IActiveView
 pActiveView = pMap
 Dim pGraphicsContainer as IGraphicsContainer
 pGraphicsContianer =pMap

 pElement = DrawLineUseDisplay(pActiveView, StartPoint, EndPoint, pLineSymbol)
 pGraphicsContainer.AddElement(pElement, 0) '修改后的属性加入到画好线的element里面

转载于:https://www.cnblogs.com/wangzihao/archive/2010/12/10/1902149.html

客户最近打电话过来,说我们的软件在距离的时候不能平移地图。我们的软件是使用ArcEngine来开发的,在网上输入关键字“arcengine 距离测量”,可以搜索到一大堆内容基本相似的文章或代码,基本上都是采用INewLineFeedback来实现的,我们的软件也是使用此种方法。方法大致如下:写一个距离测量工具,继承自BaseTool,在该类中使用INewLineFeedback动态绘制多段折线,最后转化为Element添加到地图上。如果要增加平移功能,我们仿造ArcMap使用鼠标中键平移,在OnMouseDown、OnMouseMove、OnMouseUp事件中增加判断鼠标中键的语句,然后分别使用PanStart、PanMoveTo、PanStop实现地图的平移。 此时,出现了一个新问题,一旦移动地图后,之前使用INewLineFeedback绘制的线完全乱了方寸,有一部分线丢失了。之后又发现一个更可笑的问题,在绘制的过程中,如果使用alt+tab键切换到其它窗口,然后再切换回地图窗口的时候,会多出一条线,INewLineFeedback把切换窗口前的鼠标位置记录了下来。 对于这个问题,我使用ArcMap的测量工具检查了一下,发现不存在上述问题。但是INewLineFeedback为什么会产生这个bug,难道是本人的使用方法不对。在网上搜了一下其他类似代码进行测试,都存在这个bug。ArcEngine的SDK文档上也没有特别强调INewLineFeedback的使用细节。 本来打算用gdi进行解决,最后发现INewLineFeedback有一个Refresh函数,那么应该在什么地方使用它呢?在ArcMapControl的诸多事件中,尝试了OnAfterDraw、OnAfterScreenDraw、OnViewRefresh等,发现OnAfterScreenDraw是OK的。具体是在OnAfterScreenDraw事件中使用Refresh函数刷新INewLineFeedback,完美解决问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值