资源预览内容
第1页 / 共12页
第2页 / 共12页
第3页 / 共12页
第4页 / 共12页
第5页 / 共12页
第6页 / 共12页
第7页 / 共12页
第8页 / 共12页
第9页 / 共12页
第10页 / 共12页
亲,该文档总共12页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
1Display1Display 1.1 如何实现在 ArcMap 中放大缩小地图 用户点击按钮后,可以在地图上进行点击或者拖放矩形框来放大缩小地图 要点 因为考虑到用户可以单击放大缩小,也可以拖放矩形框来放大缩小,所以不可以直接 使用 IRubberBand 接口,而是采用 INewEnvelopeFeedback 接口 程序说明 主要通过 InewEnvelopeFeedback.StartPoint 和 MoveTo 方法来绘制矩形框,然后赋值 给 IActiveView.Extend 属性,达到地图的放大缩小 代码 Private m_pFeedbackEnv As INewEnvelopeFeedback Private m_pPoint As IPoint Private m_bIsMouseDown As Boolean Private m_pActiveView As IActiveViewPrivate Sub UIToolControl1_MouseDown(ByVal button As Long, ByVal shift As Long, ByVal x As Long, _ ByVal y As Long)Dim pMxDocument As IMxDocument On Error GoTo ErrorHandler:Left Button CheckIf button 1 Then Exit SubIf (m_pFeedbackEnv Is Nothing) ThenUser Only Click Map with left buttonSet pEnv = m_pActiveView.Extent如果是缩小的话,将这里的两个 0.5 都改成 1.5pEnv.Expand 0.5, 0.5, TrueElseUser Draw a EnvelopeSet pEnv = m_pFeedbackEnv.StopEnd Ifm_pActiveView.Extent = pEnvm_bIsMouseDown = FalseSet m_pPoint = NothingSet m_pFeedbackEnv = Nothingm_pActiveView.RefreshExit Sub ErrorHandler:MsgBox Err.Description End Sub1.2 如何实现在 ArcMap 中移动地图 用户点击按钮后,可以拖动地图显示 要点 采用 IActiveView.ScreenDisplay.PanStart 和 PanStop 方法使地图移动。 程序说明 通过 IActiveView.ScreenDisplay 的 PanStart 和 PanStop 方法在 ITool 的 MouseDown,MouseUp 和 MouseMove 事件的响应实现移动效果,将移动结果得到 IEnvelope 赋值给 IActiveView.Extent,实现地图的刷新 代码 Option Explicit Private m_pMxApp As IMxApplication Private m_pMxDocument As IMxDocument Private m_pScreenDisplay As IScreenDisplay Private m_pMapInsetWindow As IMapInsetWindow Private m_bMouseDown As BooleanPrivate Sub UIToolControl1_MouseDown(ByVal button As Long, ByVal shift As Long, _ ByVal x As Long, ByVal y As Long)Dim pStartPoint As IPointIf Not button = 1 Then Exit SubSet m_pScreenDisplay = GetFocusDisplaySet m_pMapInsetWindow = GetMapInset(m_pScreenDisplay)If Not m_pMapInsetWindow Is Nothing ThenIf m_pMapInsetWindow.IsLive Then Exit SubEnd Ifm_bMouseDown = TrueSet pStartPoint = m_pScreenDisplay.DisplayTransformation.ToMapPoint(x, y)得到起始点,开始移动m_pScreenDisplay.PanStart pStartPoint End SubPrivate Sub UIToolControl1_MouseMove(ByVal button As Long, ByVal shift As Long, _ ByVal x As Long, ByVal y As Long)Dim pMoveToPoint As IPointIf Not m_bMouseDown Then Exit SubSet pMoveToPoint = m_pScreenDisplay.DisplayTransformation.ToMapPoint(x, y)根据鼠标移动,移动地图m_pScreenDisplay.PanMoveTo pMoveToPoint End SubPrivate Sub UIToolControl1_MouseUp(ByVal button As Long, ByVal shift As Long, _ ByVal x As Long, ByVal y As Long)Dim pEnvelope As IEnvelopeDim pActiveView As IActiveViewDim pMapInset As IMapInsetDim pMapInsetWindow As IMapInsetWindow If Not m_bMouseDown Then Exit Subm_bMouseDown = FalseSet pEnvelope = m_pScreenDisplay.PanStopIf pEnvelope Is Nothing Then Exit Sub窗口判断If Not m_pMapInsetWindow Is Nothing ThenSet pMapInset = m_pMapInsetWindow.MapInsetpMapInset.VisibleBounds = pEnvelopem_pMapInsetWindow.RefreshExit SubElseSet pActiveView = m_pMxDocument.ActiveView地图刷新If TypeOf pActiveView Is IMap ThenpActiveView.Extent = pEnvelopepActiveView.RefreshElseSet pActiveView = pActiveView.FocusMappActiveView.Extent = pEnvelopepActiveView.RefreshEnd IfEnd If End SubPrivate Sub UIToolControl1_Select()初始化接口m_bMouseDown = FalseSet m_pMxApp = ApplicationSet m_pMxDocument = Application.Document End SubPrivate Function GetFocusDisplay() As IScreenDisplayDim pActiveView As IActiveViewDim pActiveMap As IMapSet pActiveView = m_pMxDocument.ActiveViewIf TypeOf pActiveView Is IMap ThenSet GetFocusDisplay = m_pMxApp.Display.FocusScreenElseSet pActiveView = pActiveView.FocusMapSet GetFocusDisplay = pActiveView.ScreenDisplayEnd If End FunctionPrivate Function GetMapInset(pScreenDisplay As IScreenDisplay) As IMapInsetWindowDim pAppWindows As IApplicationWindowsDim pWindowsSet As ISetDim pDataWindow As IDataWindowDim pLensWindow As ILensWindowSet pAppWindows = m_pMxApp QISet pWindowsSet = pAppWindows.DataWindowspWindowsSet.ResetSet pDataWindow = pWindowsSet.NextDo While Not pDataWindow Is NothingIf TypeOf pDataWindow Is ILensWindow ThenSet pLensWindow = pDataWindowIf pLensWindow.ScreenDisplay Is m_pScreenDisplay ThenIf TypeOf pLensWindow Is IMapInsetWindow ThenSet GetMapInset = pLensWindowExit FunctionEnd IfEnd IfEnd IfSet pDataWindow = pWindowsSet.NextLoopSet GetMapInset = Nothing End Function1.3 如何实现在 ArcMap 上画 Polygon 用户点击按钮后,在地图上任意点击生成 Polygon,双击 Polygon 生成完成要点 IRubberBand.TrackNew 方法, IActiveview.ScreenDisplay.StartDrawing,DrawPolygon 和 EndDrawing 方法 程序说明 通过 IRubberBand.TrackNew 方法实现 Polygon 的作成, 通过 IActiveview.ScreenDisplay.StartDrawing,DrawPolygon 和 EndDrawing 方法来 绘制 Polygon 通过 Map 事件的重载,使绘制的 Polygon 不会因为 Map 的刷新而消失 代码Private m_pPolygon As IPolygon Private m_pFillSymbol As IFillSymbol Private m_pScreenDisplay As IscreenDisplay 事件重载 Private WithEvents ActiveViewEvents As Map重新绘制 Polygon Private Sub ActiveViewEvents_AfterDraw(ByVal Display As IDisplay, ByVal phase As esriViewDrawPhase)If Not phase = esriDPGeography Then Exit SubIf m_pPolygon Is Nothing
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号