/***************************
Write by Chn gzGISer Tst
CSDN blog Ricardo.M.Tan
**************************/
using System;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.ADF.CATIDs;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geodatabase;
namespace Chn.SpatialDataProcessing.Command {
/// <summary>
/// 缩放至图层Cmd命令
/// </summary>
[Guid("abcfec82-c217-46b8-9210-ead1694833f6")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("Chn.SpatialDataProcessing.Command.ZoomToLayerCmd")]
public sealed class ZoomToLayerCmd : BaseCommand {
#region COM Registration Function(s)
[ComRegisterFunction()]
[ComVisible(false)]
static void RegisterFunction(Type registerType) {
// Required for ArcGIS Component Category Registrar support
ArcGISCategoryRegistration(registerType);
//
// TODO: Add any COM registration code here
//
}
[ComUnregisterFunction()]
[ComVisible(false)]
static void UnregisterFunction(Type registerType) {
// Required for ArcGIS Component Category Registrar support
ArcGISCategoryUnregistration(registerType);
//
// TODO: Add any COM unregistration code here
//
}
#region ArcGIS Component Category Registrar generated code
/// <summary>
/// Required method for ArcGIS Component Category registration -
/// Do not modify the contents of this method with the code editor.
/// </summary>
private static void ArcGISCategoryRegistration(Type registerType) {
string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
MxCommands.Register(regKey);
ControlsCommands.Register(regKey);
}
/// <summary>
/// Required method for ArcGIS Component Category unregistration -
/// Do not modify the contents of this method with the code editor.
/// </summary>
private static void ArcGISCategoryUnregistration(Type registerType) {
string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
MxCommands.Unregister(regKey);
ControlsCommands.Unregister(regKey);
}
#endregion
#endregion
private IHookHelper m_HookHelper = null;
IMapControl3 m_Mapcontrol3 = null;
ILayer currentLayer = null;
IActiveView m_ActiveView = null;
/// <summary>
/// 构造函数
/// </summary>
public ZoomToLayerCmd() {
base.m_category = "通用工具";
base.m_caption = "缩放到当前图层范围";
base.m_message = "缩放到当前图层范围";
base.m_toolTip = "缩放到当前图层范围";
base.m_name = "ZoomToLayerCmd";
try {
base.m_bitmap = Properties.Resources.ZoomToLayerCmd;
} catch (Exception ex) {
System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap");
}
}
#region Overridden Class Methods
/// <summary>
/// Occurs when this command is created
/// </summary>
/// <param name="hook">Instance of the application</param>
public override void OnCreate(object hook) {
if (hook == null)
return;
m_HookHelper = new HookHelperClass {
Hook = hook
};
}
/// <summary>
/// Occurs when this command is clicked
/// </summary>
public override void OnClick() {
if (m_HookHelper.Hook is IMapControl3) {
m_Mapcontrol3 = m_HookHelper.Hook as IMapControl3;
currentLayer = m_Mapcontrol3.CustomProperty as ILayer;
m_ActiveView = m_Mapcontrol3.ActiveView;
}
if (m_ActiveView == null) return;
m_ActiveView.Extent = ((IGeoDataset)currentLayer).Extent;
m_ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, currentLayer, m_ActiveView.Extent);
}
#endregion
}
}