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;

namespace Chn.SpatialDataProcessing.Command {
    /// <summary>
    /// 移除图层
    /// </summary>
    [Guid("91dc2719-f181-4c3f-bc16-5486c88057fa")]
    [ClassInterface(ClassInterfaceType.None)]
    [ProgId("Chn.SpatialDataProcessing.Command.RemoveLayerCmd")]
    public sealed class RemoveLayerCmd : 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;
        private IMapControl3 m_mapcontrol = null;
        private ILayer currentLayer = null;
        private IActiveView m_activeView = null;
        private IMap m_map = null;
        /// <summary>
        /// 构造函数
        /// </summary>
        public RemoveLayerCmd() {
            m_category = "通用工具";
            m_caption = "移除当前图层";
            m_message = "移除当前图层";
            m_toolTip = "移除当前图层";
            m_name = "RemoveLayerCmd";

            try {
                m_bitmap = Properties.Resources.RemoveLayerCmd;
            } catch (Exception ex) {
                System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap");
            }
        }

        #region Overridden Class Methods

        /// <summary>
        /// 移除命令被创建时
        /// </summary>
        /// <param name="hook"></param>
        public override void OnCreate(object hook) {
            if (hook == null)
                return;
            if (m_hookHelper == null)
                m_hookHelper = new HookHelperClass();
            m_hookHelper.Hook = hook;
        }

        /// <summary>
        /// 移除命令被创建时
        /// </summary>
        public override void OnClick() {
            if (m_hookHelper.Hook is IMapControl3) {
                m_mapcontrol = m_hookHelper.Hook as IMapControl3;
                currentLayer = m_mapcontrol.CustomProperty as ILayer;
                m_map = m_mapcontrol.Map;
                m_activeView = m_map as IActiveView;
            }

            if (m_map == null || currentLayer == null) return;
            m_map.DeleteLayer(currentLayer);
            m_activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, m_activeView.Extent);
        }
        #endregion
    }
}

 

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值