1 using ESRI.ArcGIS.Controls;
2 using System;
3 using System.Collections.Generic;
4 using System.ComponentModel;
5 using System.Data;
6 using System.Drawing;
7 using System.Linq;
8 using System.Text;
9 using System.Threading.Tasks;
10 using System.Windows.Forms;
11
12 namespace Ch02Ex04
13 {
14 public partial class Form1 : Form
15 {
16 int flag = 0;
17 public Form1()
18 {
19 InitializeComponent();
20 }
21
22 private void btnZoomIn_Click(object sender, EventArgs e)
23 {
24 axMapControl1.MousePointer = esriControlsMousePointer.esriPointerZoomIn;
25 flag = 2;
26 }
27 //加载地图文档
28 private void loadMapDocument()
29 {
30 System.Windows.Forms.OpenFileDialog openFileDialog;
31 openFileDialog = new OpenFileDialog();
32 openFileDialog.Title = "打开地图文档";
33 openFileDialog.Filter = "map documents(*.mxd)|*.mxd";
34 openFileDialog.ShowDialog();
35 string filePath = openFileDialog.FileName;
36 if (axMapControl1.CheckMxFile(filePath))
37 {
38 axMapControl1.MousePointer = esriControlsMousePointer.esriPointerHourglass;
39 axMapControl1.LoadMxFile(filePath, 0, Type.Missing);
40 axMapControl1.MousePointer = esriControlsMousePointer.esriPointerDefault;
41 }
42 else
43 {
44 MessageBox.Show(filePath + "不是有效的地图文档");
45 }
46 }
47 private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
48 {
49 ESRI.ArcGIS.Geometry.IEnvelope ipEnv;
50 if (flag == 2)
51 {
52 ipEnv = axMapControl1.TrackRectangle();
53 axMapControl1.Extent = ipEnv;
54 }
55 else if (flag == 1)
56 {
57 //ipEnv = axMapControl1.TrackRectangle();
58 ipEnv = axMapControl1.Extent;
59 ipEnv.Expand(2, 2, true);
60 axMapControl1.Extent = ipEnv;
61 }
62 else if (flag == 3)
63 {
64 ipEnv = axMapControl1.Extent;
65 axMapControl1.Pan();
66 }
67
68 }
69
70 private void btnZoomOut_Click(object sender, EventArgs e)
71 {
72 axMapControl1.MousePointer = esriControlsMousePointer.esriPointerZoomOut;
73 flag = 1;
74 }
75
76 private void btnWalk_Click(object sender, EventArgs e)
77 {
78
79 axMapControl1.MousePointer = esriControlsMousePointer.esriPointerPan;
80 flag = 3;
81 }
82
83 private void btnFullextebt_Click(object sender, EventArgs e)
84 {
85 axMapControl1.Extent = axMapControl1.FullExtent;
86 }
87
88 private void Form1_Click(object sender, EventArgs e)
89 {
90 loadMapDocument();
91 }
92
93
94 }
95 }