首页 > 代码库 > 右键实现删除图层

右键实现删除图层

声明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 = http://www.mamicode.com/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();

 

右键实现删除图层