当前位置:首页 >> 建筑/土木 >>

如何让ITool类工具在使用过程中实现鼠标中键平移地图


如何让 ITool 类工具在使用过程中实现鼠标中键平移地图

private IScreenDisplay m_focusScreenDisplay; private bool m_PanOperation; public esriMapViewer() { InitializeComponent(); } private { switch (e.button) { case 4: IPoint point = new PointClass(); point.PutCoords(e.mapX, e.mapY); m_focusScreenDisplay = axMapControl.ActiveView.ScreenDisplay; m_focusScreenDisplay.PanStart(point); m_PanOperation = true; if (axMapControl.CurrentTool == null) axMapControl.MousePointer esriControlsMousePointer.esriPointerHand; break; default: break; } } private { if (e.button == 4) { if (!m_PanOperation) return; IPoint point = new PointClass(); point.PutCoords(e.mapX, e.mapY); m_focusScreenDisplay.PanMoveTo(point); } } private { if (e.button == 4) void axMapControl_OnMouseUp(object sender, IMapControlEvents2_OnMouseUpEvent e) void axMapControl_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e) = void axMapControl_OnMouseDown(object sender,

IMapControlEvents2_OnMouseDownEvent e)

{ if (!m_PanOperation) return; IEnvelope extent = m_focusScreenDisplay.PanStop(); if (extent != null) { m_focusScreenDisplay.DisplayTransformation.VisibleBounds = extent; m_focusScreenDisplay.Invalidate(null, (short)esriScreenCache.esriAllScreenCaches); } m_PanOperation = false; if (axMapControl.CurrentTool == null) axMapControl.MousePointer esriControlsMousePointer.esriPointerDefault; } } = true,

言归正传,在 ArcMap 中,在使用工具如编辑工具进行点线面绘制时,也是可以通过中键来实现平移 的,这个需要一点点小技巧来实现,其实也简单,就是截获住中键事件,停止使用当前工具的相关操 作,并把当前鼠标样式变换到平移用的那只“小手”,下面以官方例子的 ZoomInTool 工具的实现代码为 例子,稍稍作了点修改,以达到本文的目的。继续贴代码: public sealed class esriMapZoomInToolClass : BaseTool { private IHookHelper m_hookHelper; private INewEnvelopeFeedback m_feedBack; private IPoint m_point; private Boolean m_isMouseDown; private bool m_changeCursor; public esriMapZoomInToolClass() { // // TODO: Define values for the public properties // base.m_category = ""; //localizable text base.m_caption = ""; base.m_message = ""; base.m_toolTip = ""; base.m_name "MyCategory_MyTool") try { // // TODO: change resource name if necessary = //localizable text //localizable text //localizable text ""; //unique id, non-localizable (e.g.

// //string bitmapResourceName = GetType().Name + ".bmp"; //base.m_bitmap = new Bitmap(GetType(), bitmapResourceName); base.m_cursor = new System.Windows.Forms.Cursor(GetType(), "Cursor.ZoomIn.cur"); } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap"); } } #region Overriden Class Methods /// <summary> /// Occurs when this tool is created /// </summary> /// <param name="hook">Instance of the application</param> public override void OnCreate(object hook) { if (m_hookHelper == null) m_hookHelper = new HookHelperClass(); m_hookHelper.Hook = hook; // TODO: } /// <summary> /// Occurs when this tool is clicked /// </summary> public override void OnClick() { // TODO: Add esriMapZoomInToolClass.OnClick implementation } public override void OnMouseDown(int Button, int Shift, int X, int Y) { if (Button == 4) { base.m_cursor = new System.Windows.Forms.Cursor(GetType(), "Cursor.Hand.cur"); m_changeCursor = true; return; } if (m_changeCursor) { base.m_cursor = new System.Windows.Forms.Cursor(GetType(), "Cursor.ZoomIn.cur"); m_changeCursor = false; Add esriMapZoomInToolClass.OnCreate implementation

} if (Button != 1) return; // TODO: Add esriMapZoomInToolClass.OnMouseDown implementation m_point m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); m_isMouseDown = true; } public override void OnMouseMove(int Button, int Shift, int X, int Y) { if (Button == 4) { base.m_cursor = new System.Windows.Forms.Cursor(GetType(), "Cursor.Hand.cur"); m_changeCursor = true; return; } if (m_changeCursor) { base.m_cursor = new System.Windows.Forms.Cursor(GetType(), "Cursor.ZoomIn.cur"); m_changeCursor = false; } // TODO: Add esriMapZoomInToolClass.OnMouseMove implementation if (!m_isMouseDown) return; //Start an envelope feedback if (m_feedBack == null) { m_feedBack = new NewEnvelopeFeedbackClass(); m_feedBack.Display = m_hookHelper.ActiveView.ScreenDisplay; m_feedBack.Start(m_point); } //Move the envelope feedback IPoint m_feedBack.MoveTo(point); } public override void OnMouseUp(int Button, int Shift, int X, int Y) { if (Button == 4) { base.m_cursor = new System.Windows.Forms.Cursor(GetType(), "Cursor.Hand.cur"); m_changeCursor = true; return; point = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); =

} if (m_changeCursor) { base.m_cursor = new System.Windows.Forms.Cursor(GetType(), "Cursor.ZoomIn.cur"); m_changeCursor = false; } // TODO: Add esriMapZoomInToolClass.OnMouseUp implementation if (!m_isMouseDown) return; //Get the focus map IActiveView pActiveView = (IActiveView)m_hookHelper.FocusMap; //If an envelope has not been tracked IEnvelope pEnvelope; if (m_feedBack == null) { //Zoom in from mouse click pEnvelope = pActiveView.Extent; pEnvelope.Expand(0.5, 0.5, true); pEnvelope.CenterAt(m_point); } else { //Stop the envelope feedback pEnvelope = m_feedBack.Stop(); //Exit if the envelope height or width is 0 if (pEnvelope.Width == 0 || pEnvelope.Height == 0) { m_feedBack = null; m_isMouseDown = false; } } //Set the new extent pActiveView.Extent = pEnvelope; //Refresh the active view pActiveView.Refresh(); m_feedBack = null; m_isMouseDown = false; } public override void Refresh(int hDC) { if (m_feedBack != null) m_feedBack.Refresh(hDC); base.Refresh(hDC); } #endregion


相关文章:
百度地图API的使用方法
地图 API 中提供的控件有: · Control:控件的抽象基类,所有控件均继承此类的方法、属性。通过此类您可实现自定义控件。 · NavigationControl:地图平移缩放控件,...
ArcGIS Engine常用接口
包含 ICommand、 IToolIToolControl 接口。 开发...这个类 库中包含的对象是一些使用工具对象, 开发...可以许多不同类型的图层加载到地图中。不同 的...
更多相关标签: