ArcEngine——缩放至当前图层范围

/***************************
 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
    }
}

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值