码迷,mamicode.com
首页 > 其他好文 > 详细

右键实现删除图层

时间:2014-11-26 16:09:20      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:style   blog   ar   color   sp   on   div   log   bs   

声明toolbarmenu:

 IToolbarMenu pToolBarMenu = new ToolbarMenuClass();

在窗体load事件中初始化:

 pToolBarMenu.AddItem(new RemoveSelectedLayer1(), 0, -1, false, esriCommandStyles.esriCommandStyleTextOnly);
            pToolBarMenu.SetHook(axMapControl1.Object);

在toccontrol的onmousedown中获取选择项,主要用到customproperty属性:

 IBasicMap pBasicMap = null;
            ILayer pLayer = null;
            esriTOCControlItem pItem = esriTOCControlItem.esriTOCControlItemNone;
            object pUnk = null;
            object pData = null;
            if (e.button == 2)
            {
                
                
                axTOCControl1.HitTest(e.x, e.y, ref pItem, ref pBasicMap, ref pLayer, ref  pUnk, ref  pData);
               
            }
            if (pItem == esriTOCControlItem.esriTOCControlItemLayer)
            {
                axMapControl1.CustomProperty = pLayer;
                pToolBarMenu.PopupMenu(e.x, e.y, axTOCControl1.hWnd);
            }

在自定义的命令的click中操作:

   IMapControlDefault pMapControl = m_hookHelper.Hook as IMapControlDefault;
            IMap pMap = pMapControl.Map;
            ILayer pLayer = null;
            if (pMapControl.CustomProperty is ILayer)
            {
                pLayer = pMapControl.CustomProperty as ILayer;
            }
            pMap.DeleteLayer(pLayer);
            pMapControl.Refresh();

 

右键实现删除图层

标签:style   blog   ar   color   sp   on   div   log   bs   

原文地址:http://www.cnblogs.com/wangzianan/p/4123341.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!