📄 pan.cs
字号:
using System;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.MapControl;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geometry;
namespace Cstest1
{
/// <summary>
/// Pan 的摘要说明。
/// </summary>
public class Pan: ITool,ICommand //从ITool,ICommand继承
{
// [DllImport("gdi32.dll")]
ESRI.ArcGIS.MapControl.AxMapControl m_MapControl; //设置地图控件对象
ESRI.ArcGIS.Display.IScreenDisplay m_ScreenDisplay; //设置屏幕显示对象
private bool m_PanOperation; //光标显示的控制变量
private System.Windows.Forms.Cursor m_cursor; //平移手掌光标
private System.Windows.Forms.Cursor m_cursorMove; //鼠标拖动时的光标
public Pan()
{
//
// TODO: 在此处添加构造函数逻辑
}
#region ITool 成员
public void OnMouseDown(int button, int shift, int x, int y)
{
// TODO: 添加 Pan.OnMouseDown 实现
if(button==1)
{
IPoint m_StartPoint; //平移起始点
m_ScreenDisplay=m_MapControl.ActiveView.ScreenDisplay;
m_StartPoint= m_ScreenDisplay.DisplayTransformation.ToMapPoint(x, y); //获得起始点,开始移动
m_ScreenDisplay.PanStart(m_StartPoint);
m_PanOperation = true;
}
}
public void OnMouseMove(int button, int shift, int x, int y)
{
// TODO: 添加 Pan.OnMouseMove 实现
if(button==1)
{
IPoint m_MoveToPoint;
m_MoveToPoint=m_ScreenDisplay.DisplayTransformation.ToMapPoint(x,y);
m_ScreenDisplay.PanMoveTo(m_MoveToPoint); //平移过程
}
}
public void OnMouseUp(int button, int shift, int x, int y)
{
// TODO: 添加 Pan.OnMouseUp 实现
IEnvelope m_Env;
if(button==1)
{
m_Env=m_ScreenDisplay.PanStop(); //平移完毕,返回移动后的范围
m_MapControl.ActiveView.Extent=m_Env;
m_MapControl.ActiveView.Refresh();
m_PanOperation = false;
}
}
public void OnKeyDown(int keyCode, int shift)
{
// TODO: 添加 Pan.OnKeyDown 实现
}
public void OnKeyUp(int keyCode, int shift)
{
// TODO: 添加 Pan.OnKeyUp 实现
}
public int Cursor
{
// TODO: 添加 Pan.Cursor getter 实现
get
{
if(m_PanOperation)
return m_cursorMove.Handle.ToInt32();
else
return m_cursor.Handle.ToInt32();
}
}
public bool OnContextMenu(int x, int y)
{
// TODO: 添加 Pan.OnContextMenu 实现
return false;
}
public bool Deactivate()
{
// TODO: 添加 Pan.Deactivate 实现
return true; //返回true,保证对象注销时不报错
}
public void Refresh(int hdc)
{
// TODO: 添加 Pan.Refresh 实现
}
public void OnDblClick()
{
// TODO: 添加 Pan.OnDblClick 实现
}
#endregion
#region ICommand 成员
public void OnClick()
{
// TODO: 添加 Pan.OnClick 实现
}
public string Message
{
get
{
// TODO: 添加 Pan.Message getter 实现
return null;
}
}
public int Bitmap
{
// TODO: 添加 Pan.Bitmap getter 实现
get
{
return 0;
}
}
public void OnCreate(object hook)
{
// TODO: 添加 Pan.OnCreate 实现
m_MapControl=hook as AxMapControl; //工具创建时,设置地图控件对象
m_cursor = new System.Windows.Forms.Cursor
(GetType().Assembly.GetManifestResourceStream (GetType(), "Res.Hand.cur"));
m_cursorMove = new System.Windows.Forms.Cursor
(GetType().Assembly.GetManifestResourceStream(GetType(),"Res.MoveHand.cur"));
}
public string Caption
{
get
{
// TODO: 添加 Pan.Caption getter 实现
return null;
}
}
public string Tooltip
{
get
{
// TODO: 添加 Pan.Tooltip getter 实现
return null;
}
}
public int HelpContextID
{
get
{
// TODO: 添加 Pan.HelpContextID getter 实现
return 0;
}
}
public string Name
{
get
{
// TODO: 添加 Pan.Name getter 实现
return null;
}
}
public bool Checked
{
// TODO: 添加 Pan.Checked getter 实现
get
{
return false;
}
}
public bool Enabled
{
get
{
// TODO: 添加 Pan.Enabled getter 实现
return false;
}
}
public string HelpFile
{
get
{
// TODO: 添加 Pan.HelpFile getter 实现
return null;
}
}
public string Category
{
get
{
// TODO: 添加 Pan.Category getter 实现
return null;
}
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -