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);
}
}
}
- 缩放至图层
if (pTocFeatureLayer == null) return;
(axMapControl1.Map as IActiveView).Extent = pTocFeatureLayer.AreaOfInterest;
(axMapControl1.Map as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
- 移除图层
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();
- 图层不可选
if (pTocFeatureLayer != null)
{
pTocFeatureLayer.Selectable = true;//false
}