以下两个类对MapXtrme2004 asp.net鹰眼功能进行了完全的封装。
用法:
1
private void Page_Load(object sender, System.EventArgs e)
2
{
3
// 在此处放置用户代码以初始化页面
4
Overview oc = new Overview(MapControl1,MapControl2);
5
6
if(!IsPostBack)
7
{
8
9
10
}
11
}

2

3

4

5

6

7

8

9

10

11

1
/* 作者:xiexiaokui
2
* 时间:2005-10-18
3
* 功能:asp.net鹰眼
4
*/
5
using System;
6
using MapInfo.Web.UI.WebControls;
7
using MapInfo.Geometry;
8
using MapInfo.Styles;
9
using System.Drawing;
10
using MapInfo.Data;
11
12
/// <summary>
13
/// OverviewTool 的摘要说明。
14
/// </summary>
15
public class OverviewMapToolEventArgs:System.EventArgs
16
{
17
System.Drawing.Point[] m_points;
18
public OverviewMapToolEventArgs(System.Drawing.Point[] points)
19
{
20
this.m_points = points;
21
}
22
23
public System.Drawing.Point[] Points
24
{
25
get
26
{
27
return m_points;
28
}
29
set
30
{
31
m_points = value;
32
}
33
}
34
35
}
36
37
public delegate void OverviewMapToolEventHandler(object sender,OverviewMapToolEventArgs e);
38
39
40
public class OverviewMapTool:MapTool
41
{
42
public static readonly string Toolname = "MapInfoWebOverview";
43
// public DPoint Point1,Point2;
44
45
string m_clientCodeSource;
46
string m_clientStartMethod;
47
string m_clientStopMethod;
48
string m_cursorUrl;
49
string m_name;
50
51
52
public event OverviewMapToolEventHandler OverviewMapToolStop;
53
54
protected void OnOverviewMapToolStop(OverviewMapToolEventArgs e)
55
{
56
if(this.OverviewMapToolStop != null)
57
this.OverviewMapToolStop(this,e);
58
}
59
60
public OverviewMapTool()
61
{
62
this.ClientStartMethod = "MapInfoWebRectangleStart";
63
this.ClientStopMethod = "MapInfoWebRectangleStop";
64
this.Name = Toolname;
65
}
66
public override string ClientCodeSource
67
{
68
get
69
{
70
return m_clientCodeSource;
71
}
72
set
73
{
74
m_clientCodeSource = value;
75
}
76
}
77
78
public override string ClientStartMethod
79
{
80
get
81
{
82
return m_clientStartMethod;
83
}
84
set
85
{
86
m_clientStartMethod = value;
87
}
88
}
89
public override string ClientStopMethod
90
{
91
get
92
{
93
return m_clientStopMethod;
94
}
95
set
96
{
97
m_clientStopMethod = value;
98
}
99
}
100
public override string CursorUrl
101
{
102
get
103
{
104
return m_cursorUrl;
105
}
106
set
107
{
108
m_cursorUrl = value;
109
}
110
}
111
public override string Name
112
{
113
get
114
{
115
return m_name;
116
}
117
set
118
{
119
m_name = value;
120
}
121
}
122
123
124
public override void Execute(string dataString, System.Collections.ArrayList selLayers, MapInfo.Mapping.Map map)
125
{
126
127
// DPoint dp1,dp2;
128
System.Drawing.Point[] points = base.ExtractPoints(dataString);
129
// map.DisplayTransform.FromDisplay(points[0],out dp1);
130
// map.DisplayTransform.FromDisplay(points[1],out dp2);
131
132
133
this.OnOverviewMapToolStop(new OverviewMapToolEventArgs(points));
134
// OverviewMapTool omt = (OverviewMapTool)this.MapControl2.MapTools[MapControl2.MapTools.Count-1];
135
// MapInfo.Geometry.DPoint dp1 = omt.Point1;
136
// MapInfo.Geometry.DPoint dp2 = omt.Point2;
137
// System.Drawing.Point p1,p2;
138
139
// MapControl2.Map.DisplayTransform.ToDisplay(dp1,out p1);
140
// MapControl2.Map.DisplayTransform.ToDisplay(dp2,out p2);
141
// if(Math.Min(Math.Abs(points[0].X-points[1].X),Math.Abs(points[0].Y-points[1].Y))<5)
142
// {
143
// m_mainMapControl.Map.Center = dp1;
144
// }
145
// else
146
// {
147
// MapInfo.Geometry.DRect rect = new DRect(dp1,dp2);
148
// m_mainMapControl.Map.SetView(rect,m_mainMapControl.Map.GetDisplayCoordSys());
149
// }
150
151
}
152
153
154
}
155
class Overview
156
{
157
158
MapInfo.Web.UI.WebControls.MapControl m_mainMapControl;
159
MapInfo.Web.UI.WebControls.MapControl m_overviewMapControl;
160
public Overview(MapInfo.Web.UI.WebControls.MapControl mainMapControl,MapInfo.Web.UI.WebControls.MapControl overviewMapControl)
161
{
162
MainMapControl = mainMapControl;
163
OverviewMapControl = overviewMapControl;
164
}
165
166
public MapInfo.Web.UI.WebControls.MapControl MainMapControl
167
{
168
get
169
{
170
return m_mainMapControl;
171
}
172
set
173
{
174
m_mainMapControl = value;
175
m_mainMapControl.PreRender += new EventHandler(MainMapControl_PreRender);
176
}
177
}
178
public MapInfo.Web.UI.WebControls.MapControl OverviewMapControl
179
{
180
get
181
{
182
return m_overviewMapControl;
183
}
184
set
185
{
186
187
188
MapInfo.Data.Table table = MapInfo.Engine.Session.Current.Catalog.GetTable("temp_overview");
189
m_overviewMapControl = value;
190
OverviewMapTool omt = new OverviewMapTool();
191
omt.OverviewMapToolStop += new OverviewMapToolEventHandler(omt_OverviewMapToolStop);
192
this.m_overviewMapControl.MapTools.Add(omt);
193
this.m_overviewMapControl.MapTools.CurrentTool = omt.Name;
194
if(table == null)
195
{
196
197
198
this.m_overviewMapControl.Map.Load(new MapInfo.Mapping.MapTableLoader(m_mainMapControl.Map.Layers.GetTableEnumerator()));
199
200
MapInfo.Data.TableInfo ti = MapInfo.Data.TableInfoFactory.CreateTemp("temp_overview");
201
MapInfo.Data.TableSessionInfo tsi = new MapInfo.Data.TableSessionInfo();
202
203
table = MapInfo.Engine.Session.Current.Catalog.CreateTable(ti);
204
205
MapInfo.Mapping.FeatureLayer fl = new MapInfo.Mapping.FeatureLayer(table);
206
m_overviewMapControl.Map.Layers.Insert(0,fl);
207
}
208
209
}
210
}
211
protected void MainMapControl_PreRender(object sender, EventArgs e)
212
{
213
214
DRect dr = this.m_mainMapControl.Map.Bounds;
215
FeatureGeometry fg = new MapInfo.Geometry.Rectangle(m_mainMapControl.Map.GetDisplayCoordSys(),dr);
216
MapInfo.Styles.SimpleLineStyle sls = new MapInfo.Styles.SimpleLineStyle(new LineWidth(1,LineWidthUnit.Pixel),2,Color.Red);
217
MapInfo.Styles.SimpleInterior si = new MapInfo.Styles.SimpleInterior(1);
218
MapInfo.Styles.AreaStyle arst = new MapInfo.Styles.AreaStyle(sls,si);
219
// MapInfo.Styles.CompositeStyle cs = new MapInfo.Styles.CompositeStyle(arst,null,null,null);
220
MapInfo.Styles.CompositeStyle cs = new MapInfo.Styles.CompositeStyle(arst);
221
MapInfo.Data.Feature f = new Feature(fg,arst);
222
223
MapInfo.Data.Table table = MapInfo.Engine.Session.Current.Catalog.GetTable("temp_overview");
224
(table as ITableFeatureCollection).Clear();
225
table.InsertFeature(f);
226
227
m_overviewMapControl.Map.Layers["temp_overview"].Invalidate();
228
//table.Refresh();
229
230
}
231
232
private void omt_OverviewMapToolStop(object sender, OverviewMapToolEventArgs e)
233
{
234
DPoint dp1,dp2;
235
System.Drawing.Point[] points = e.Points;
236
m_overviewMapControl.Map.DisplayTransform.FromDisplay(points[0],out dp1);
237
m_overviewMapControl.Map.DisplayTransform.FromDisplay(points[1],out dp2);
238
// OverviewMapTool omt = (OverviewMapTool)this.MapControl2.MapTools[MapControl2.MapTools.Count-1];
239
// MapInfo.Geometry.DPoint dp1 = omt.Point1;
240
// MapInfo.Geometry.DPoint dp2 = omt.Point2;
241
// System.Drawing.Point p1,p2;
242
243
// MapControl2.Map.DisplayTransform.ToDisplay(dp1,out p1);
244
// MapControl2.Map.DisplayTransform.ToDisplay(dp2,out p2);
245
if(Math.Min(Math.Abs(points[0].X-points[1].X),Math.Abs(points[0].Y-points[1].Y))<5)
246
{
247
m_mainMapControl.Map.Center = dp1;
248
}
249
else
250
{
251
MapInfo.Geometry.DRect rect = new DRect(dp1,dp2);
252
m_mainMapControl.Map.SetView(rect,m_mainMapControl.Map.GetDisplayCoordSys());
253
}
254
}
255
256
}
257
258

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

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258
