#region 地图漫游工具栏代码
//缩小2倍
private void ZoomInfxdButton_Click(object sender, EventArgs e)
{
IActiveView actView = axMapControl1.ActiveView;
IPoint centerPoint = new PointClass();
centerPoint.PutCoords((actView.Extent.XMin + actView.Extent.XMax) / 2, (actView.Extent.YMax + actView.Extent.YMin) / 2);
IEnvelope envlope = actView.Extent;
envlope.Expand(1.5, 1.5, true);
actView.Extent.CenterAt(centerPoint);
actView.Extent = envlope;
actView.Refresh();
}
//放大2倍
private void ZoomOutfxdButton_Click(object sender, EventArgs e)
{
IActiveView actView = axMapControl1.ActiveView;
IPoint centerPoint = new PointClass();
centerPoint.PutCoords((actView.Extent.XMin + actView.Extent.XMax) / 2, (actView.Extent.YMax + actView.Extent.YMin) / 2);
IEnvelope envlope = actView.Extent;
envlope.Expand(0.5, 0.5, true);
actView.Extent.CenterAt(centerPoint);
actView.Extent = envlope;
actView.Refresh();
}
//拉框放大
private void ZoomInButton_Click(object sender, EventArgs e)
{
strMouseOperate = "ZoomIn";
axMapControl1.MousePointer = esriControlsMousePointer.esriPointerZoomIn;
}
//拉框缩小
private void ZoomOutButton_Click(object sender, EventArgs e)
{
strMouseOperate = "ZoomOut";
axMapControl1.MousePointer = esriControlsMousePointer.esriPointerZoomOut;
}
//全图工具
private void FullExtentButton_Click(object sender, EventArgs e)
{
axMapControl1.Extent = axMapControl1.FullExtent;
}
//移动工具
private void PanButton_Click(object sender, EventArgs e)
{
strMouseOperate = "Pan";
axMapControl1.MousePointer = esriControlsMousePointer.esriPointerPan;
}
#endregion
private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
{
if(e.button==1)
{
IActiveView actView = axMapControl1.ActiveView; //(IActiveView)axMapControl1.Map;
IEnvelope pEnv = new EnvelopeClass();
switch (strMouseOperate)
{
case "ZoomIn":
pEnv = axMapControl1.TrackRectangle();
actView.Extent = pEnv;
actView.Refresh();
break;
case "ZoomOut":
pEnv = axMapControl1.TrackRectangle();
IPoint pt = new PointClass();
pt.X = (actView.Extent.XMax + actView.Extent.XMin)/2;//(pEnv.XMin + pEnv.XMax) / 2;
pt.Y = (actView.Extent.YMax + actView.Extent.YMin)/2;//(pEnv.XMin + pEnv.YMax) / 2;
pEnv.Width = actView.Extent.Width * (actView.Extent.Width / pEnv.Width);
pEnv.Height = actView.Extent.Height * (actView.Extent.Height / pEnv.Height);
pEnv.CenterAt(pt);
actView.Extent = pEnv;
actView.Refresh();
break;
case "Pan":
axMapControl1.Pan();
break;
default:
break;
}
else if (e.button == 2)
{
strMouseOperate = "";
axMapControl1.MousePointer = esriControlsMousePointer.esriPointerDefault;
}
}