操作TOC控件

  • 获取点击的图层
        IFeatureLayer pTocFeatureLayer = null;            //点击的要素图层
        private void axTOCControl1_OnMouseDown(object sender, ITOCControlEvents_OnMouseDownEvent e)
        {
            esriTOCControlItem pItem = esriTOCControlItem.esriTOCControlItemNone;
            IBasicMap pMap = null;
            ILayer pLayer = null;
            object unk = null;
            object data = null;
            axTOCControl1.HitTest(e.x, e.y, ref pItem, ref pMap, ref pLayer, ref unk, ref data);
            pTocFeatureLayer = pLayer as IFeatureLayer;
            if (e.button == 2)
            {
                if (pItem == esriTOCControlItem.esriTOCControlItemLayer)
                {
                    可选择ToolStripMenuItem.Checked = pTocFeatureLayer.Selectable;
                    contextMenuStrip1.Show(Control.MousePosition);
                }
            }
        }
  1. 缩放至图层
                if (pTocFeatureLayer == null) return;
                (axMapControl1.Map as IActiveView).Extent = pTocFeatureLayer.AreaOfInterest;
                (axMapControl1.Map as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
  2. 移除图层
                    if (pTocFeatureLayer == null)
                    {
                        DialogResult result = MessageBox.Show("是否移除[" + pRasterLayer.Name + "]图层", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                        if (result == DialogResult.OK)
                        {
                            axMapControl1.Map.DeleteLayer(pRasterLayer);
                        }
                    }
                    else {
                        DialogResult result2 = MessageBox.Show("是否移除[" + pTocFeatureLayer.Name + "]图层", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                        if (result2 == DialogResult.OK)
                        {
                            axMapControl1.Map.DeleteLayer(pTocFeatureLayer);
                        }
                    }
                    axMapControl1.ActiveView.Refresh();
  3. 图层不可选
                if (pTocFeatureLayer != null)
                {
                    pTocFeatureLayer.Selectable = true;//false
                }

     

猜你喜欢

转载自blog.csdn.net/fangyu723/article/details/79445191
toc
今日推荐