AO+C#鹰眼功能实现——(一) (拖动功能未实现)
实现关键两点:
1.保持两个显示控件的一致性。
2.绘制鹰眼窗口显示方框。
窗体包括两个Mapcontrol,几个按钮
源代码如下:(部分代码参考ESRI中国论坛相关帖子)

Code
1
using System;
2
using System.Collections.Generic;
3
using System.ComponentModel;
4
using System.Data;
5
using System.Drawing;
6
using System.Text;
7
using System.Windows.Forms;
8
using ESRI.ArcGIS.Carto;
9
using ESRI.ArcGIS.Controls;
10
using ESRI.ArcGIS.Geometry;
11
using ESRI.ArcGIS.Display;
12
13
namespace WindowsApplication1
14

{
15
public partial class Form1 : Form
16
{
17
public Form1()
18
{
19
InitializeComponent();
20
21
}
22
23
private void buttonOpen_Click(object sender, EventArgs e)
24
{
25
//加载MXD文件
26
27
IMapDocument pMapDocument = new MapDocumentClass();
28
OpenFileDialog Open = new OpenFileDialog();
29
30
Open.Title = "Select File";
31
Open.Filter = "Document File(.mxd)|*.mxd";
32
33
Open.ShowDialog();
34
35
string strFullPath = Open.FileName;
36
if (strFullPath == "") return;
37
38
pMapDocument.Open(strFullPath, "");
39
for (int i = 0; i <= pMapDocument.MapCount - 1; i++)
40
{
41
//一个IMapDocument对象中可能有多个Map对象,遍历每个map对象
42
axMapControl1.Map = pMapDocument.get_Map(i);
43
44
}
45
axMapControl1.Refresh();
46
47
}
48
49
private void buttonExit_Click(object sender, EventArgs e)
50
{
51
Application.Exit();
52
}
53
54
private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
55
{
56
if (e.button == 2)
57
{
58
//右键局部放大,后面应该有个局部刷新CtlRefresh,未搞定
59
axMapControl1.MousePointer = esriControlsMousePointer.esriPointerPageZoomIn;
60
axMapControl1.Extent = axMapControl1.TrackRectangle();
61
}
62
else if (e.button == 1)
63
{
64
//左键移动,也应有局部刷新
65
axMapControl1.MousePointer = esriControlsMousePointer.esriPointerPan;
66
axMapControl1.Pan();
67
}
68
}
69
70
private void buttonResize_Click(object sender, EventArgs e)
71
{
72
//还原初始大小
73
axMapControl1.Extent = axMapControl1.FullExtent;
74
}
75
76
private void axMapControl1_OnMapReplaced(object sender, IMapControlEvents2_OnMapReplacedEvent e)
77
{
78
IMap pMap;
79
pMap = this.axMapControl1.Map;
80
int i;
81
this.axMapControl2.Map.ClearLayers();
82
this.axMapControl2.ActiveView.Refresh();
83
84
for (i = 0; i <= pMap.LayerCount - 1; i++)
85
{
86
this.axMapControl2.Map.AddLayer(pMap.get_Layer(pMap.LayerCount - 1 - i));
87
}
88
}
89
90
private void axMapControl1_OnExtentUpdated(object sender, IMapControlEvents2_OnExtentUpdatedEvent e)
91
{
92
// 得到新范围
93
94
IEnvelope pEnv = (IEnvelope)e.newEnvelope;
95
96
97
IGraphicsContainer pGra = axMapControl2.Map as IGraphicsContainer;
98
99
IActiveView pAv = pGra as IActiveView;
100
101
//在绘制前,清除axMapControl2中的任何图形元素
102
103
pGra.DeleteAllElements();
104
105
106
IRectangleElement pRectangleEle = new RectangleElementClass();
107
108
IElement pEle = pRectangleEle as IElement;
109
110
pEle.Geometry = pEnv;
111
112
113
//设置鹰眼图中的红线框
114
115
IRgbColor pColor = new RgbColorClass();
116
117
pColor.Red = 255;
118
119
pColor.Green = 0;
120
121
pColor.Blue = 0;
122
123
pColor.Transparency = 255;
124
125
//产生一个线符号对象
126
127
ILineSymbol pOutline = new SimpleLineSymbolClass();
128
129
pOutline.Width = 2;
130
131
pOutline.Color = pColor;
132
133
134
//设置颜色属性
135
136
pColor = new RgbColorClass();
137
138
pColor.Red = 255;
139
140
pColor.Green = 0;
141
142
pColor.Blue = 0;
143
144
pColor.Transparency = 0;
145
146
//设置填充符号的属性
147
148
IFillSymbol pFillSymbol = new SimpleFillSymbolClass();
149
150
pFillSymbol.Color = pColor;
151
152
pFillSymbol.Outline = pOutline;
153
154
155
IFillShapeElement pFillShapeEle = pEle as IFillShapeElement;
156
157
pFillShapeEle.Symbol = pFillSymbol;
158
159
pGra.AddElement((IElement)pFillShapeEle, 0);
160
161
pAv.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
162
163
164
}
165
166
}
167
}
168
1.保持两个显示控件的一致性。
2.绘制鹰眼窗口显示方框。
窗体包括两个Mapcontrol,几个按钮
源代码如下:(部分代码参考ESRI中国论坛相关帖子)


1

2

3

4

5

6

7

8

9

10

11

12

13

14



15

16



17

18



19

20

21

22

23

24



25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40



41

42

43

44

45

46

47

48

49

50



51

52

53

54

55



56

57



58

59

60

61

62

63



64

65

66

67

68

69

70

71



72

73

74

75

76

77



78

79

80

81

82

83

84

85



86

87

88

89

90

91



92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168
