AE基础知识之地图浏览

时间:2021-02-16 10:55:02

地图浏览:(放大缩小平移全图)

//全局变量

public enum enumToolFlag

{

None

ZoomOut,

ZoomIn,

Pan,

}

enumToolFlag flag = enumToolFlag.None;

添加按钮事件函数并编辑

private void btnZoomIn_Click(object sender, EventArgs e)    //放大

{

axMapControlMain.MousePointer= esriControlsMousePointer.esriPointerZoomIn;

flag = enumToolFlag.ZoomIn;

}

private void btnZoomOut_Click(object sender, EventArgs e)    //缩小

{

axMapControlMain.MousePointer= esriControlsMousePointer.esriPointerZoomOut;

flag = enumToolFlag.ZoomOut;

}

private void btnPan_Click(object sender, EventArgs e)    //平移

{

axMapControlMain.MousePointer= esriControlsMousePointer.esriPointerPan;

flag = enumToolFlag.Pan;

}

在axMapControl1_OnMouseDown中添加下列代码:

(下列代码中的axMapControlMain 为默认的axMapControl1)

IEnvelope ipEnv;

if (e.button == 1)

{

switch (flag)

{

case enumToolFlag.ZoomOut:     //ZoomOut

{

ipEnv = axMapControlMain.TrackRectangle();

ipEnv = axMapControlMain.Extent;

ipEnv.Expand(2, 2, true);

axMapControlMain.Extent = ipEnv;

}

break;

case enumToolFlag.ZoomIn:     //ZoomIn

{

ipEnv = axMapControlMain.TrackRectangle();

ipEnv = axMapControlMain.Extent;

ipEnv.Expand(0.5, 0.5, true);

axMapControlMain.Extent = ipEnv;

}

break;

case enumToolFlag.Pan:    //Pan

{

axMapControlMain.Pan();

}

break;

}

全图:  (代码如下)

private void btnFullExtent_Click(object sender, EventArgs e)

{

axMapControlMain.Extent = axMapControlMain.FullExtent;

}