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

如何让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


相关文章:
GPP 3to2的使用说明
如果是“OFF” ,请用鼠 标单击该处让其变成“ON...后记:同一台电脑安装好 iTools 工具后,并且保持好...Baidu 使用百度前必读 | 文库协议 | 网站地图...
个人知识管理含试题与答案
虚拟知识地图 企业在进行知识管理时,要建立知识库、...使用个人知识管理工具 在进行个人知识管理时,也要...在读书学习的过程中,应用“阅读矩阵”可以让自己的...
视觉设计师如何运用“体验地图”工具
让一切可见–视觉设计师如何运用 “体验地图工具 2016-09 “服务设计”是近年设计转型的趋势,“体验地图”作为一 种好的体验设计工具,在业界被较多人学习运用...
西南交通大学软件开发考试重点
6、对于类或引用类型,必须使用关键字 new 来声明...要在窗体中加入工具栏,需要控件“ToolStrip”拖放...工具(Tool) :实现了 ICommand 接口和 ITool 接口,...
软件设计
下: 2)地图操作:实现数据的基本编辑功能,如改变显示范围,放大,缩小, 平移,...(axMapControl1.Object); //axMapControl1.CurrentTool = pCmd as ITool; m...
实验二 地图显示和图层控制
(2)添加选项卡 在“工具箱”的空白处单击鼠标右键...使用 ArcGIS Engine 中封装好的对象实现地图操作 ...(ITool)Cmd; ②通过 ControlsMapFullExtentCommand ...
更多相关标签:
cad鼠标中键不能平移 | cad鼠标滚轮不能平移 | 鼠标中键不能平移 | css3实现图片平移 | 苹果鼠标cad怎么平移 | matlab实现图像平移 | js实现图片平移 | 鼠标平移 |