[地理信息系统课程设计报告]
//获取鼠标点击位置 m_point =
m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); m_isMouseDown = true;
// TODO: Add ZoomIn.OnMouseDown implementation }
publicoverridevoid OnMouseMove(int Button, int Shift, int X, int Y) {
//MouseDown为发生时返回 if (!m_isMouseDown) return;
IActiveView pActiveView = m_hookHelper.ActiveView; //m_feedBack追踪鼠标移动 if (m_feedBack == null) {
m_feedBack = newNewEnvelopeFeedbackClass(); m_feedBack.Display = pActiveView.ScreenDisplay; //开始追踪
m_feedBack.Start(m_point); }
//追踪鼠标移动位置
m_feedBack.MoveTo(pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y));
}
publicoverridevoid OnMouseUp(int Button, int Shift, int X, int Y) {
//MouseDown为发生时返回 if (!m_isMouseDown) return;
IActiveView pActiveView = m_hookHelper.ActiveView; //获取MouseUp发生时的范围并放大 IEnvelope pEnvelope;
if (m_feedBack == null)//鼠标未拉框时进行固定比例尺放大 {
pEnvelope = pActiveView.Extent; pEnvelope.Expand(0.5, 0.5, true); pEnvelope.CenterAt(m_point); } else
{ //停止追踪
pEnvelope = m_feedBack.Stop();
//判断新的范围的高度和宽度是否为零
if (pEnvelope.Width == 0 || pEnvelope.Height == 0) {
[地理信息系统课程设计报告]33 / 38
[地理信息系统课程设计报告]
m_feedBack = null; m_isMouseDown = false; } } //获取新的范围
pActiveView.Extent = pEnvelope; //刷新视图
pActiveView.Refresh();
m_feedBack = null; m_isMouseDown = false;
// TODO: Add ZoomIn.OnMouseUp implementation }
#endregion } }
9、ZoomOut类源码
namespace MyMap.Classes {
///
/// Summary description for ZoomOut. ///
[Guid(\)] [ClassInterface(ClassInterfaceType.None)] [ProgId(\)] publicsealedclassZoomOut : BaseTool {
#region COM Registration Function(s) [ComRegisterFunction()] [ComVisible(false)]
staticvoid RegisterFunction(Type registerType) {
// Required for ArcGIS Component Category Registrar support ArcGISCategoryRegistration(registerType); }
[ComUnregisterFunction()] [ComVisible(false)]
staticvoid UnregisterFunction(Type registerType) {
// Required for ArcGIS Component Category Registrar support ArcGISCategoryUnregistration(registerType); }
#region ArcGIS Component Category Registrar generated code
[地理信息系统课程设计报告]34 / 38
[地理信息系统课程设计报告]
privatestaticvoid ArcGISCategoryRegistration(Type registerType) {
string regKey = string.Format(\, registerType.GUID);
ControlsCommands.Register(regKey);
}
privatestaticvoid ArcGISCategoryUnregistration(Type registerType) {
string regKey = string.Format(\, registerType.GUID);
ControlsCommands.Unregister(regKey); }
#endregion #endregion //记录鼠标位置
privateIPoint m_point; //标记MouseDown是否发生
privateBoolean m_isMouseDown; //追踪鼠标移动产生新的Envelope
privateINewEnvelopeFeedback m_feedBack;
privateIHookHelper m_hookHelper;
public ZoomOut() {
base.m_category = \; //localizable text base.m_caption = \缩小\; //localizable text base.m_message = \缩小\; //localizable text base.m_toolTip = \缩小\; //localizable text
base.m_name = \; //unique id, non-localizable (e.g. \ try
{
string bitmapResourceName = GetType().Name + \;
base.m_bitmap = newBitmap(GetType(), bitmapResourceName);
base.m_cursor = newSystem.Windows.Forms.Cursor(GetType(), GetType().Name + \); }
catch (Exception ex) {
System.Diagnostics.Trace.WriteLine(ex.Message, \); } }
#region Overridden Class Methods publicoverridevoid OnCreate(object hook) {
[地理信息系统课程设计报告]35 / 38
[地理信息系统课程设计报告]
if (m_hookHelper == null)
m_hookHelper = newHookHelperClass(); m_hookHelper.Hook = hook;
// TODO: Add ZoomOut.OnCreate implementation }
publicoverridevoid OnClick() {
// TODO: Add ZoomOut.OnClick implementation }
publicoverridevoid OnMouseDown(int Button, int Shift, int X, int Y) {
// TODO: Add ZoomOut.OnMouseDown implementation //当前地图视图为空时返回
if (m_hookHelper.ActiveView == null) return;
//获取鼠标点击位置 m_point =
m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); m_isMouseDown = true; }
publicoverridevoid OnMouseMove(int Button, int Shift, int X, int Y) {
// TODO: Add ZoomOut.OnMouseMove implementation //MouseDown为发生时返回 if (!m_isMouseDown) return;
IActiveView pActiveView = m_hookHelper.ActiveView; //m_feedBack追踪鼠标移动 if (m_feedBack == null) {
m_feedBack = newNewEnvelopeFeedbackClass(); m_feedBack.Display = pActiveView.ScreenDisplay; //开始追踪
m_feedBack.Start(m_point); }
//追踪鼠标移动位置
m_feedBack.MoveTo(pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y));
}
publicoverridevoid OnMouseUp(int Button, int Shift, int X, int Y) {
// TODO: Add ZoomOut.OnMouseUp implementation //MouseDown为发生时返回 if (!m_isMouseDown) return;
IActiveView pActiveView = m_hookHelper.ActiveView;
[地理信息系统课程设计报告]36 / 38
相关推荐: