//中心放大
IClone pIClone = (IClone)mcView.ActiveView.Extent;
IEnvelope pIEnvelope = (IEnvelope)pIClone.Clone();
pIEnvelope.Expand(0.5, 0.5, true);
mcView.ActiveView.Extent = pIEnvelope;
右击图层,实现缩放至图层
//下面代码在可在初始化后load方法中写
private ITOCControl2 tocControl;
private IMapControl3 mapControl;
private IToolbarMenu toolMenuMap;
private IToolbarMenu toolMenuLayer;
tocControl = (ITOCControl2)toc.Object;
mapControl = (IMapControl3)mcView.Object;
//创建菜单
toolMenuMap = new ToolbarMenuClass();
toolMenuLayer = new ToolbarMenuClass();
toolMenuLayer.AddItem(new ZoomToLayer(), -1, 0, true, esriCommandStyles.esriCommandStyleTextOnly);
toolMenuLayer.SetHook(mapControl);
/// <summary>
/// 缩放至图层事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void toc_OnMouseDown(object sender, ITOCControlEvents_OnMouseDownEvent e)
{
esriTOCControlItem tocItem = esriTOCControlItem.esriTOCControlItemNone;
IBasicMap basicMap = null; ;
ILayer layer = null;
object legendGroup = null;
object index = null;
//获取鼠标点击信息
toc.HitTest(e.x, e.y, ref tocItem, ref basicMap, ref layer, ref legendGroup, ref index);
if (e.button == 2)
{
if (tocItem == esriTOCControlItem.esriTOCControlItemMap)
{
toc.SelectItem(basicMap, null);
}
else
{
toc.SelectItem(layer, null);
}
//设置CustomProperty为layer (用于自定义的Layer命令)
mcView.CustomProperty = layer;
//弹出右键菜单
if (tocItem == esriTOCControlItem.esriTOCControlItemMap)
{
toolMenuMap.PopupMenu(e.x, e.y, toc.hWnd);
}
else
{
toolMenuLayer.PopupMenu(e.x, e.y, toc.hWnd);
}
}
}
public class ZoomToLayer : BaseCommand
{
private IMapControl3 mapControl;
public ZoomToLayer()
{
base.m_caption = "缩放至该图层";
}
//重写BaseCommand基类的虚拟方法OnClick()
public override void OnClick()
{
ILayer layer = (ILayer)mapControl.CustomProperty;
mapControl.Extent = layer.AreaOfInterest;
//IGeoDataset geoDataset = layer as IGeoDataset;
//IEnvelope envelope = geoDataset.Extent;
//mapControl.Extent = envelope;
}
//重写BaseCommand基类的抽象方法OnCreate(object hook)
public override void OnCreate(object hook)
{
mapControl = (IMapControl3)hook;
}
}
private void tlXZQ_MouseDoubleClick(object sender, MouseEventArgs e)
{
try
{
TreeListHitInfo hInfo = this.tlXZQ.CalcHitInfo(new Point(e.X, e.Y));
DataRowView drv = (DataRowView)this.bdscXZQ.Current;
if (hInfo.Node == null || drv == null ) return;
//获取当前选择的行政代码及名称
string xzqdm = drv["XZQDM"] == DBNull.Value ? "" : drv["XZQDM"].ToString();
}
}
private void tlXZQ_FocusedNodeChanged(object sender, FocusedNodeChangedEventArgs e)
{
try
{
DataRowView drv = (DataRowView)this.bdscXZQ.Current;
if (e.Node == null || drv == null) return;
//获取当前选择的行政代码及名称
string xzqdm = drv["XZQDM"] == DBNull.Value ? "" : drv["XZQDM"].ToString();
}
}
//AE二次开中修改AxMapControl控件的名称代码
this.axMapControl1.Map.Name = "Layers of Map";
this.axTOCControl1.Update();