首页 > 代码库 > 右键实现删除图层
右键实现删除图层
声明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();
右键实现删除图层
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。