ArcGIS.Server.9.2.DotNet在ElementGraphicsLayer画点、线、折线、面、圆、矩形的代码
ArcGIS.Server.9.2.DotNet在ElementGraphicsLayer画点、线、折线、面、圆、矩形的代码:
1
public class AddTool:IMapServerToolAction
2
{
3
4
5
public void ServerAction(ESRI.ArcGIS.ADF.Web.UI.WebControls.ToolEventArgs args)
6
{
7
//获取map控件
8
ESRI.ArcGIS.ADF.Web.UI.WebControls.Map adfMap = (ESRI.ArcGIS.ADF.Web.UI.WebControls.Map)args.Control;
9
ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality adfGraphicsMapFunctionality = null;
10
11
if (args is PointEventArgs)
12
{
13
//转成点
14
PointEventArgs pointEventArgs = (PointEventArgs)args;
15
//屏幕点
16
System.Drawing.Point screenPoint = pointEventArgs.ScreenPoint;
17
//屏幕坐标转成地理坐标
18
ESRI.ArcGIS.ADF.Web.Geometry.Point adfPoint = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(screenPoint.X, screenPoint.Y, adfMap.GetTransformationParams(ESRI.ArcGIS.ADF.Web.Geometry.TransformationDirection.ToMap));
19
20
//MapFunctionality
21
foreach (ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality mapFunctionality in adfMap.GetFunctionalities())
22
{
23
//当Resource为ADFGraphicsResource,ADFGraphicsResource为GraphicsLayer, 保存在内存中用显示临时图层
24
if (mapFunctionality.Resource.Name == "GraphicsResource")
25
{
26
adfGraphicsMapFunctionality = (ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality)mapFunctionality;
27
break;
28
}
29
}
30
//从adfGraphicsMapFunctionality获取名为Element Graphics的DataTable
31
//ElementGraphicsLayers通常用来显示图形元素,例如显示Map中被选择的图形元素。图层并不用来存储属性,而可以存储不同的图形类型。
32
ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer elementGraphicsLayer = null;
33
foreach (System.Data.DataTable dataTable in adfGraphicsMapFunctionality.GraphicsDataSet.Tables)
34
{
35
if (dataTable.TableName == "Element Graphics")
36
{
37
elementGraphicsLayer = (ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer)dataTable;
38
break;
39
}
40
}
41
//如果名为Element Graphics的DataTable为null,就新建Element Graphics DataTable添加到adfGraphicsMapFunctionality.GraphicsDataSet中,同时刷新Toc1显示
42
if (elementGraphicsLayer == null)
43
{
44
elementGraphicsLayer = new ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer();
45
elementGraphicsLayer.TableName = "Element Graphics";
46
adfGraphicsMapFunctionality.GraphicsDataSet.Tables.Add(elementGraphicsLayer);
47
}
48
49
//定义标点样式
50
ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol simpleMarkerSymbol = new ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol();
51
//simpleMarkerSymbol.Type = ESRI.ArcGIS.ADF.Web.Display.Symbol.MarkerSymbolType.Star;
52
simpleMarkerSymbol.Color = System.Drawing.Color.Green;
53
simpleMarkerSymbol.Width = 10;
54
55
//定义标点选中样式
56
ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol simpleSelectedMarkerSymbol = new ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol();
57
simpleSelectedMarkerSymbol.Color = System.Drawing.Color.Yellow;
58
simpleSelectedMarkerSymbol.Width = 12;
59
simpleSelectedMarkerSymbol.Type = ESRI.ArcGIS.ADF.Web.Display.Symbol.MarkerSymbolType.Star;
60
61
ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement graphicElement = new ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement(adfPoint, simpleMarkerSymbol, simpleSelectedMarkerSymbol);
62
//把标点添加到elementGraphicsLayer
63
elementGraphicsLayer.Add(graphicElement);
64
65
}
66
else if(args is LineEventArgs)
67
{
68
//转成点
69
LineEventArgs lineEventArgs = (LineEventArgs)args;
70
//屏幕点
71
//屏幕坐标转成地理坐标
72
ESRI.ArcGIS.ADF.Web.Geometry.Point adfPoint1 = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(lineEventArgs.BeginPoint.X, lineEventArgs.BeginPoint.Y, adfMap.GetTransformationParams(ESRI.ArcGIS.ADF.Web.Geometry.TransformationDirection.ToMap));
73
//屏幕坐标转成地理坐标
74
ESRI.ArcGIS.ADF.Web.Geometry.Point adfPoint2 = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(lineEventArgs.EndPoint.X, lineEventArgs.EndPoint.Y, adfMap.GetTransformationParams(ESRI.ArcGIS.ADF.Web.Geometry.TransformationDirection.ToMap));
75
ESRI.ArcGIS.ADF.Web.Geometry.Path pa=new ESRI.ArcGIS.ADF.Web.Geometry.Path();
76
pa.Points.Add(adfPoint1);
77
pa.Points.Add(adfPoint2);
78
ESRI.ArcGIS.ADF.Web.Geometry.Polyline Line = new ESRI.ArcGIS.ADF.Web.Geometry.Polyline();
79
Line.Paths.Add(pa);
80
81
//MapFunctionality
82
foreach (ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality mapFunctionality in adfMap.GetFunctionalities())
83
{
84
//当Resource为ADFGraphicsResource,ADFGraphicsResource为GraphicsLayer, 保存在内存中用显示临时图层
85
if (mapFunctionality.Resource.Name == "GraphicsResource")
86
{
87
adfGraphicsMapFunctionality = (ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality)mapFunctionality;
88
break;
89
}
90
}
91
//从adfGraphicsMapFunctionality获取名为Element Graphics的DataTable
92
//ElementGraphicsLayers通常用来显示图形元素,例如显示Map中被选择的图形元素。图层并不用来存储属性,而可以存储不同的图形类型。
93
ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer elementGraphicsLayer = null;
94
foreach (System.Data.DataTable dataTable in adfGraphicsMapFunctionality.GraphicsDataSet.Tables)
95
{
96
if (dataTable.TableName == "Element Graphics")
97
{
98
elementGraphicsLayer = (ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer)dataTable;
99
break;
100
}
101
}
102
//如果名为Element Graphics的DataTable为null,就新建Element Graphics DataTable添加到adfGraphicsMapFunctionality.GraphicsDataSet中,同时刷新Toc1显示
103
if (elementGraphicsLayer == null)
104
{
105
elementGraphicsLayer = new ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer();
106
elementGraphicsLayer.TableName = "Element Graphics";
107
adfGraphicsMapFunctionality.GraphicsDataSet.Tables.Add(elementGraphicsLayer);
108
}
109
110
//定义标点样式
111
ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleLineSymbol simpleMarkerSymbol = new ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleLineSymbol();
112
//simpleMarkerSymbol.Type = ESRI.ArcGIS.ADF.Web.Display.Symbol.MarkerSymbolType.Star;
113
simpleMarkerSymbol.Color = System.Drawing.Color.Red;
114
simpleMarkerSymbol.Width = 3;
115
simpleMarkerSymbol.Type = ESRI.ArcGIS.ADF.Web.Display.Symbol.LineType.Dash;
116
//定义标点选中样式
117
ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleLineSymbol simpleSelectedMarkerSymbol = new ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleLineSymbol();
118
simpleSelectedMarkerSymbol.Color = System.Drawing.Color.Yellow;
119
simpleSelectedMarkerSymbol.Width = 3;
120
//simpleSelectedMarkerSymbol.Type = ESRI.ArcGIS.ADF.Web.Display.Symbol.MarkerSymbolType.Star;
121
122
ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement graphicElement = new ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement(Line, simpleMarkerSymbol, simpleSelectedMarkerSymbol);
123
//把标点添加到elementGraphicsLayer
124
elementGraphicsLayer.Add(graphicElement);
125
126
}
127
else if (args is PolylineEventArgs)
128
{
129
PolylineEventArgs lineEventArgs = (PolylineEventArgs)args;
130
ESRI.ArcGIS.ADF.Web.Geometry.Path pa = new ESRI.ArcGIS.ADF.Web.Geometry.Path();
131
for (int i = 0; i <= lineEventArgs.Vectors.Length - 1; i++)
132
{
133
ESRI.ArcGIS.ADF.Web.Geometry.Point point = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(lineEventArgs.Vectors[i].X, lineEventArgs.Vectors[i].Y, adfMap.GetTransformationParams(ESRI.ArcGIS.ADF.Web.Geometry.TransformationDirection.ToMap));
134
pa.Points.Add(point);
135
}
136
ESRI.ArcGIS.ADF.Web.Geometry.Polyline Line = new ESRI.ArcGIS.ADF.Web.Geometry.Polyline();
137
Line.Paths.Add(pa);
138
139
//MapFunctionality
140
foreach (ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality mapFunctionality in adfMap.GetFunctionalities())
141
{
142
//当Resource为ADFGraphicsResource,ADFGraphicsResource为GraphicsLayer, 保存在内存中用显示临时图层
143
if (mapFunctionality.Resource.Name == "GraphicsResource")
144
{
145
adfGraphicsMapFunctionality = (ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality)mapFunctionality;
146
break;
147
}
148
}
149
//从adfGraphicsMapFunctionality获取名为Element Graphics的DataTable
150
//ElementGraphicsLayers通常用来显示图形元素,例如显示Map中被选择的图形元素。图层并不用来存储属性,而可以存储不同的图形类型。
151
ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer elementGraphicsLayer = null;
152
foreach (System.Data.DataTable dataTable in adfGraphicsMapFunctionality.GraphicsDataSet.Tables)
153
{
154
if (dataTable.TableName == "Element Graphics")
155
{
156
elementGraphicsLayer = (ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer)dataTable;
157
break;
158
}
159
}
160
//如果名为Element Graphics的DataTable为null,就新建Element Graphics DataTable添加到adfGraphicsMapFunctionality.GraphicsDataSet中,同时刷新Toc1显示
161
if (elementGraphicsLayer == null)
162
{
163
elementGraphicsLayer = new ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer();
164
elementGraphicsLayer.TableName = "Element Graphics";
165
adfGraphicsMapFunctionality.GraphicsDataSet.Tables.Add(elementGraphicsLayer);
166
}
167
168
//定义标点样式
169
ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleLineSymbol simpleMarkerSymbol = new ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleLineSymbol();
170
//simpleMarkerSymbol.Type = ESRI.ArcGIS.ADF.Web.Display.Symbol.MarkerSymbolType.Star;
171
simpleMarkerSymbol.Color = System.Drawing.Color.Red;
172
simpleMarkerSymbol.Width = 3;
173
simpleMarkerSymbol.Type = ESRI.ArcGIS.ADF.Web.Display.Symbol.LineType.Dash;
174
//定义标点选中样式
175
ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleLineSymbol simpleSelectedMarkerSymbol = new ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleLineSymbol();
176
simpleSelectedMarkerSymbol.Color = System.Drawing.Color.Yellow;
177
simpleSelectedMarkerSymbol.Width = 3;
178
//simpleSelectedMarkerSymbol.Type = ESRI.ArcGIS.ADF.Web.Display.Symbol.MarkerSymbolType.Star;
179
180
ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement graphicElement = new ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement(Line, simpleMarkerSymbol, simpleSelectedMarkerSymbol);
181
//把标点添加到elementGraphicsLayer
182
elementGraphicsLayer.Add(graphicElement);
183
}
184
else if (args is PolygonEventArgs)
185
{
186
PolygonEventArgs polygonEventArgs = (PolygonEventArgs)args;
187
ESRI.ArcGIS.ADF.Web.Geometry.Ring points = new ESRI.ArcGIS.ADF.Web.Geometry.Ring();
188
for (int i = 0; i <= polygonEventArgs.Vectors.Length - 1; i++)
189
{
190
ESRI.ArcGIS.ADF.Web.Geometry.Point point = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(polygonEventArgs.Vectors[i].X, polygonEventArgs.Vectors[i].Y, adfMap.GetTransformationParams(ESRI.ArcGIS.ADF.Web.Geometry.TransformationDirection.ToMap));
191
points.Points.Add(point);
192
}
193
ESRI.ArcGIS.ADF.Web.Geometry.Polygon polygon = new ESRI.ArcGIS.ADF.Web.Geometry.Polygon();
194
polygon.Rings.Add(points);
195
196
//MapFunctionality
197
foreach (ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality mapFunctionality in adfMap.GetFunctionalities())
198
{
199
//当Resource为ADFGraphicsResource,ADFGraphicsResource为GraphicsLayer, 保存在内存中用显示临时图层
200
if (mapFunctionality.Resource.Name == "GraphicsResource")
201
{
202
adfGraphicsMapFunctionality = (ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality)mapFunctionality;
203
break;
204
}
205
}
206
//从adfGraphicsMapFunctionality获取名为Element Graphics的DataTable
207
//ElementGraphicsLayers通常用来显示图形元素,例如显示Map中被选择的图形元素。图层并不用来存储属性,而可以存储不同的图形类型。
208
ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer elementGraphicsLayer = null;
209
foreach (System.Data.DataTable dataTable in adfGraphicsMapFunctionality.GraphicsDataSet.Tables)
210
{
211
if (dataTable.TableName == "Element Graphics")
212
{
213
elementGraphicsLayer = (ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer)dataTable;
214
break;
215
}
216
}
217
//如果名为Element Graphics的DataTable为null,就新建Element Graphics DataTable添加到adfGraphicsMapFunctionality.GraphicsDataSet中,同时刷新Toc1显示
218
if (elementGraphicsLayer == null)
219
{
220
elementGraphicsLayer = new ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer();
221
elementGraphicsLayer.TableName = "Element Graphics";
222
adfGraphicsMapFunctionality.GraphicsDataSet.Tables.Add(elementGraphicsLayer);
223
}
224
225
ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleFillSymbol simpleMarkerSymbol = new ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleFillSymbol();
226
simpleMarkerSymbol.Color = System.Drawing.Color.Yellow;
227
simpleMarkerSymbol.FillType= ESRI.ArcGIS.ADF.Web.Display.Symbol.PolygonFillType.DiagCross;
228
229
ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleFillSymbol simpleSelectedMarkerSymbol = new ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleFillSymbol();
230
ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement graphicElement = new ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement(polygon, simpleMarkerSymbol, simpleSelectedMarkerSymbol);
231
//把标点添加到elementGraphicsLayer
232
elementGraphicsLayer.Add(graphicElement);
233
234
}
235
else if (args is CircleEventArgs)
236
{
237
CircleEventArgs circleEventArgs = (CircleEventArgs)args;
238
239
ESRI.ArcGIS.ADF.Web.Geometry.PointCollection pc = new ESRI.ArcGIS.ADF.Web.Geometry.PointCollection();
240
double degree;
241
double rad = circleEventArgs.Radius;
242
for (int i = 0; i < 359; i++)
243
{
244
degree = i * (Math.PI / 180);
245
double x = circleEventArgs.CenterPoint.X + Math.Cos(degree) * rad;
246
double y = circleEventArgs.CenterPoint.Y + Math.Sin(degree) * rad;
247
ESRI.ArcGIS.ADF.Web.Geometry.Point nPoint = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint((int)Math.Round(x),(int)Math.Round(y), adfMap.GetTransformationParams(ESRI.ArcGIS.ADF.Web.Geometry.TransformationDirection.ToMap));
248
pc.Add(nPoint);
249
}
250
ESRI.ArcGIS.ADF.Web.Geometry.Ring ring = new ESRI.ArcGIS.ADF.Web.Geometry.Ring();
251
ring.Points = pc;
252
ESRI.ArcGIS.ADF.Web.Geometry.RingCollection rings = new ESRI.ArcGIS.ADF.Web.Geometry.RingCollection();
253
rings.Add(ring);
254
ESRI.ArcGIS.ADF.Web.Geometry.Polygon polygon = new ESRI.ArcGIS.ADF.Web.Geometry.Polygon();
255
polygon.Rings = rings;
256
257
//MapFunctionality
258
foreach (ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality mapFunctionality in adfMap.GetFunctionalities())
259
{
260
//当Resource为ADFGraphicsResource,ADFGraphicsResource为GraphicsLayer, 保存在内存中用显示临时图层
261
if (mapFunctionality.Resource.Name == "GraphicsResource")
262
{
263
adfGraphicsMapFunctionality = (ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality)mapFunctionality;
264
break;
265
}
266
}
267
//从adfGraphicsMapFunctionality获取名为Element Graphics的DataTable
268
//ElementGraphicsLayers通常用来显示图形元素,例如显示Map中被选择的图形元素。图层并不用来存储属性,而可以存储不同的图形类型。
269
ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer elementGraphicsLayer = null;
270
foreach (System.Data.DataTable dataTable in adfGraphicsMapFunctionality.GraphicsDataSet.Tables)
271
{
272
if (dataTable.TableName == "Element Graphics")
273
{
274
elementGraphicsLayer = (ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer)dataTable;
275
break;
276
}
277
}
278
//如果名为Element Graphics的DataTable为null,就新建Element Graphics DataTable添加到adfGraphicsMapFunctionality.GraphicsDataSet中,同时刷新Toc1显示
279
if (elementGraphicsLayer == null)
280
{
281
elementGraphicsLayer = new ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer();
282
elementGraphicsLayer.TableName = "Element Graphics";
283
adfGraphicsMapFunctionality.GraphicsDataSet.Tables.Add(elementGraphicsLayer);
284
}
285
286
ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleFillSymbol simpleMarkerSymbol = new ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleFillSymbol();
287
simpleMarkerSymbol.Color = System.Drawing.Color.Yellow;
288
simpleMarkerSymbol.FillType = ESRI.ArcGIS.ADF.Web.Display.Symbol.PolygonFillType.DiagCross;
289
290
ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleFillSymbol simpleSelectedMarkerSymbol = new ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleFillSymbol();
291
ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement graphicElement = new ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement(polygon, simpleMarkerSymbol, simpleSelectedMarkerSymbol);
292
//把标点添加到elementGraphicsLayer
293
elementGraphicsLayer.Add(graphicElement);
294
295
}
296
else if(args is RectangleEventArgs)
297
{
298
RectangleEventArgs rectargs = (RectangleEventArgs)args;
299
//矩形
300
System.Drawing.Rectangle myrect = rectargs.ScreenExtent;
301
//矩形左下定点坐标转换成地理坐标
302
ESRI.ArcGIS.ADF.Web.Geometry.Point minpnt = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(myrect.Left, myrect.Bottom, adfMap.GetTransformationParams(ESRI.ArcGIS.ADF.Web.Geometry.TransformationDirection.ToMap));
303
//矩形右上定点坐标转换成地理坐标
304
ESRI.ArcGIS.ADF.Web.Geometry.Point maxpnt = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(myrect.Right, myrect.Top, adfMap.GetTransformationParams(ESRI.ArcGIS.ADF.Web.Geometry.TransformationDirection.ToMap));
305
//
306
ESRI.ArcGIS.ADF.Web.Geometry.Envelope mappoly = new ESRI.ArcGIS.ADF.Web.Geometry.Envelope(minpnt, maxpnt);
307
308
//MapFunctionality
309
foreach (ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality mapFunctionality in adfMap.GetFunctionalities())
310
{
311
//当Resource为ADFGraphicsResource,ADFGraphicsResource为GraphicsLayer, 保存在内存中用显示临时图层
312
if (mapFunctionality.Resource.Name == "GraphicsResource")
313
{
314
adfGraphicsMapFunctionality = (ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality)mapFunctionality;
315
break;
316
}
317
}
318
//从adfGraphicsMapFunctionality获取名为Element Graphics的DataTable
319
//ElementGraphicsLayers通常用来显示图形元素,例如显示Map中被选择的图形元素。图层并不用来存储属性,而可以存储不同的图形类型。
320
ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer elementGraphicsLayer = null;
321
foreach (System.Data.DataTable dataTable in adfGraphicsMapFunctionality.GraphicsDataSet.Tables)
322
{
323
if (dataTable.TableName == "Element Graphics")
324
{
325
elementGraphicsLayer = (ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer)dataTable;
326
break;
327
}
328
}
329
//如果名为Element Graphics的DataTable为null,就新建Element Graphics DataTable添加到adfGraphicsMapFunctionality.GraphicsDataSet中,同时刷新Toc1显示
330
if (elementGraphicsLayer == null)
331
{
332
elementGraphicsLayer = new ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer();
333
elementGraphicsLayer.TableName = "Element Graphics";
334
adfGraphicsMapFunctionality.GraphicsDataSet.Tables.Add(elementGraphicsLayer);
335
}
336
337
ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleFillSymbol simpleMarkerSymbol = new ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleFillSymbol();
338
simpleMarkerSymbol.Color = System.Drawing.Color.Yellow;
339
simpleMarkerSymbol.FillType = ESRI.ArcGIS.ADF.Web.Display.Symbol.PolygonFillType.DiagCross;
340
341
ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleFillSymbol simpleSelectedMarkerSymbol = new ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleFillSymbol();
342
ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement graphicElement = new ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement(mappoly, simpleMarkerSymbol, simpleSelectedMarkerSymbol);
343
//把标点添加到elementGraphicsLayer
344
elementGraphicsLayer.Add(graphicElement);
345
346
}
347
348
//刷新显示
349
if (adfMap.ImageBlendingMode == ImageBlendingMode.WebTier)
350
{
351
//整个地图控件刷新
352
adfMap.Refresh();
353
}
354
else
355
{
356
//只刷新部分Resource
357
adfMap.RefreshResource(adfGraphicsMapFunctionality.Resource.Name);
358
}
359
}
360
361
}
public class AddTool:IMapServerToolAction 2
{3

4

5
public void ServerAction(ESRI.ArcGIS.ADF.Web.UI.WebControls.ToolEventArgs args)6
{7
//获取map控件8
ESRI.ArcGIS.ADF.Web.UI.WebControls.Map adfMap = (ESRI.ArcGIS.ADF.Web.UI.WebControls.Map)args.Control;9
ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality adfGraphicsMapFunctionality = null;10

11
if (args is PointEventArgs)12
{13
//转成点14
PointEventArgs pointEventArgs = (PointEventArgs)args;15
//屏幕点16
System.Drawing.Point screenPoint = pointEventArgs.ScreenPoint;17
//屏幕坐标转成地理坐标18
ESRI.ArcGIS.ADF.Web.Geometry.Point adfPoint = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(screenPoint.X, screenPoint.Y, adfMap.GetTransformationParams(ESRI.ArcGIS.ADF.Web.Geometry.TransformationDirection.ToMap));19
20
//MapFunctionality21
foreach (ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality mapFunctionality in adfMap.GetFunctionalities())22
{23
//当Resource为ADFGraphicsResource,ADFGraphicsResource为GraphicsLayer, 保存在内存中用显示临时图层24
if (mapFunctionality.Resource.Name == "GraphicsResource")25
{26
adfGraphicsMapFunctionality = (ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality)mapFunctionality;27
break;28
}29
}30
//从adfGraphicsMapFunctionality获取名为Element Graphics的DataTable31
//ElementGraphicsLayers通常用来显示图形元素,例如显示Map中被选择的图形元素。图层并不用来存储属性,而可以存储不同的图形类型。32
ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer elementGraphicsLayer = null;33
foreach (System.Data.DataTable dataTable in adfGraphicsMapFunctionality.GraphicsDataSet.Tables)34
{35
if (dataTable.TableName == "Element Graphics")36
{37
elementGraphicsLayer = (ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer)dataTable;38
break;39
}40
}41
//如果名为Element Graphics的DataTable为null,就新建Element Graphics DataTable添加到adfGraphicsMapFunctionality.GraphicsDataSet中,同时刷新Toc1显示42
if (elementGraphicsLayer == null)43
{44
elementGraphicsLayer = new ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer();45
elementGraphicsLayer.TableName = "Element Graphics";46
adfGraphicsMapFunctionality.GraphicsDataSet.Tables.Add(elementGraphicsLayer);47
}48

49
//定义标点样式50
ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol simpleMarkerSymbol = new ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol();51
//simpleMarkerSymbol.Type = ESRI.ArcGIS.ADF.Web.Display.Symbol.MarkerSymbolType.Star;52
simpleMarkerSymbol.Color = System.Drawing.Color.Green;53
simpleMarkerSymbol.Width = 10;54

55
//定义标点选中样式56
ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol simpleSelectedMarkerSymbol = new ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol();57
simpleSelectedMarkerSymbol.Color = System.Drawing.Color.Yellow;58
simpleSelectedMarkerSymbol.Width = 12;59
simpleSelectedMarkerSymbol.Type = ESRI.ArcGIS.ADF.Web.Display.Symbol.MarkerSymbolType.Star;60

61
ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement graphicElement = new ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement(adfPoint, simpleMarkerSymbol, simpleSelectedMarkerSymbol);62
//把标点添加到elementGraphicsLayer63
elementGraphicsLayer.Add(graphicElement);64
65
}66
else if(args is LineEventArgs)67
{68
//转成点69
LineEventArgs lineEventArgs = (LineEventArgs)args;70
//屏幕点71
//屏幕坐标转成地理坐标72
ESRI.ArcGIS.ADF.Web.Geometry.Point adfPoint1 = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(lineEventArgs.BeginPoint.X, lineEventArgs.BeginPoint.Y, adfMap.GetTransformationParams(ESRI.ArcGIS.ADF.Web.Geometry.TransformationDirection.ToMap));73
//屏幕坐标转成地理坐标74
ESRI.ArcGIS.ADF.Web.Geometry.Point adfPoint2 = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(lineEventArgs.EndPoint.X, lineEventArgs.EndPoint.Y, adfMap.GetTransformationParams(ESRI.ArcGIS.ADF.Web.Geometry.TransformationDirection.ToMap));75
ESRI.ArcGIS.ADF.Web.Geometry.Path pa=new ESRI.ArcGIS.ADF.Web.Geometry.Path();76
pa.Points.Add(adfPoint1);77
pa.Points.Add(adfPoint2);78
ESRI.ArcGIS.ADF.Web.Geometry.Polyline Line = new ESRI.ArcGIS.ADF.Web.Geometry.Polyline();79
Line.Paths.Add(pa);80

81
//MapFunctionality82
foreach (ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality mapFunctionality in adfMap.GetFunctionalities())83
{84
//当Resource为ADFGraphicsResource,ADFGraphicsResource为GraphicsLayer, 保存在内存中用显示临时图层85
if (mapFunctionality.Resource.Name == "GraphicsResource")86
{87
adfGraphicsMapFunctionality = (ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality)mapFunctionality;88
break;89
}90
}91
//从adfGraphicsMapFunctionality获取名为Element Graphics的DataTable92
//ElementGraphicsLayers通常用来显示图形元素,例如显示Map中被选择的图形元素。图层并不用来存储属性,而可以存储不同的图形类型。93
ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer elementGraphicsLayer = null;94
foreach (System.Data.DataTable dataTable in adfGraphicsMapFunctionality.GraphicsDataSet.Tables)95
{96
if (dataTable.TableName == "Element Graphics")97
{98
elementGraphicsLayer = (ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer)dataTable;99
break;100
}101
}102
//如果名为Element Graphics的DataTable为null,就新建Element Graphics DataTable添加到adfGraphicsMapFunctionality.GraphicsDataSet中,同时刷新Toc1显示103
if (elementGraphicsLayer == null)104
{105
elementGraphicsLayer = new ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer();106
elementGraphicsLayer.TableName = "Element Graphics";107
adfGraphicsMapFunctionality.GraphicsDataSet.Tables.Add(elementGraphicsLayer);108
}109

110
//定义标点样式111
ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleLineSymbol simpleMarkerSymbol = new ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleLineSymbol();112
//simpleMarkerSymbol.Type = ESRI.ArcGIS.ADF.Web.Display.Symbol.MarkerSymbolType.Star;113
simpleMarkerSymbol.Color = System.Drawing.Color.Red;114
simpleMarkerSymbol.Width = 3;115
simpleMarkerSymbol.Type = ESRI.ArcGIS.ADF.Web.Display.Symbol.LineType.Dash;116
//定义标点选中样式117
ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleLineSymbol simpleSelectedMarkerSymbol = new ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleLineSymbol();118
simpleSelectedMarkerSymbol.Color = System.Drawing.Color.Yellow;119
simpleSelectedMarkerSymbol.Width = 3;120
//simpleSelectedMarkerSymbol.Type = ESRI.ArcGIS.ADF.Web.Display.Symbol.MarkerSymbolType.Star;121

122
ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement graphicElement = new ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement(Line, simpleMarkerSymbol, simpleSelectedMarkerSymbol);123
//把标点添加到elementGraphicsLayer124
elementGraphicsLayer.Add(graphicElement);125
126
}127
else if (args is PolylineEventArgs)128
{129
PolylineEventArgs lineEventArgs = (PolylineEventArgs)args;130
ESRI.ArcGIS.ADF.Web.Geometry.Path pa = new ESRI.ArcGIS.ADF.Web.Geometry.Path();131
for (int i = 0; i <= lineEventArgs.Vectors.Length - 1; i++)132
{133
ESRI.ArcGIS.ADF.Web.Geometry.Point point = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(lineEventArgs.Vectors[i].X, lineEventArgs.Vectors[i].Y, adfMap.GetTransformationParams(ESRI.ArcGIS.ADF.Web.Geometry.TransformationDirection.ToMap));134
pa.Points.Add(point);135
}136
ESRI.ArcGIS.ADF.Web.Geometry.Polyline Line = new ESRI.ArcGIS.ADF.Web.Geometry.Polyline();137
Line.Paths.Add(pa);138

139
//MapFunctionality140
foreach (ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality mapFunctionality in adfMap.GetFunctionalities())141
{142
//当Resource为ADFGraphicsResource,ADFGraphicsResource为GraphicsLayer, 保存在内存中用显示临时图层143
if (mapFunctionality.Resource.Name == "GraphicsResource")144
{145
adfGraphicsMapFunctionality = (ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality)mapFunctionality;146
break;147
}148
}149
//从adfGraphicsMapFunctionality获取名为Element Graphics的DataTable150
//ElementGraphicsLayers通常用来显示图形元素,例如显示Map中被选择的图形元素。图层并不用来存储属性,而可以存储不同的图形类型。151
ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer elementGraphicsLayer = null;152
foreach (System.Data.DataTable dataTable in adfGraphicsMapFunctionality.GraphicsDataSet.Tables)153
{154
if (dataTable.TableName == "Element Graphics")155
{156
elementGraphicsLayer = (ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer)dataTable;157
break;158
}159
}160
//如果名为Element Graphics的DataTable为null,就新建Element Graphics DataTable添加到adfGraphicsMapFunctionality.GraphicsDataSet中,同时刷新Toc1显示161
if (elementGraphicsLayer == null)162
{163
elementGraphicsLayer = new ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer();164
elementGraphicsLayer.TableName = "Element Graphics";165
adfGraphicsMapFunctionality.GraphicsDataSet.Tables.Add(elementGraphicsLayer);166
}167

168
//定义标点样式169
ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleLineSymbol simpleMarkerSymbol = new ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleLineSymbol();170
//simpleMarkerSymbol.Type = ESRI.ArcGIS.ADF.Web.Display.Symbol.MarkerSymbolType.Star;171
simpleMarkerSymbol.Color = System.Drawing.Color.Red;172
simpleMarkerSymbol.Width = 3;173
simpleMarkerSymbol.Type = ESRI.ArcGIS.ADF.Web.Display.Symbol.LineType.Dash;174
//定义标点选中样式175
ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleLineSymbol simpleSelectedMarkerSymbol = new ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleLineSymbol();176
simpleSelectedMarkerSymbol.Color = System.Drawing.Color.Yellow;177
simpleSelectedMarkerSymbol.Width = 3;178
//simpleSelectedMarkerSymbol.Type = ESRI.ArcGIS.ADF.Web.Display.Symbol.MarkerSymbolType.Star;179

180
ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement graphicElement = new ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement(Line, simpleMarkerSymbol, simpleSelectedMarkerSymbol);181
//把标点添加到elementGraphicsLayer182
elementGraphicsLayer.Add(graphicElement);183
}184
else if (args is PolygonEventArgs)185
{186
PolygonEventArgs polygonEventArgs = (PolygonEventArgs)args;187
ESRI.ArcGIS.ADF.Web.Geometry.Ring points = new ESRI.ArcGIS.ADF.Web.Geometry.Ring();188
for (int i = 0; i <= polygonEventArgs.Vectors.Length - 1; i++)189
{190
ESRI.ArcGIS.ADF.Web.Geometry.Point point = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(polygonEventArgs.Vectors[i].X, polygonEventArgs.Vectors[i].Y, adfMap.GetTransformationParams(ESRI.ArcGIS.ADF.Web.Geometry.TransformationDirection.ToMap));191
points.Points.Add(point);192
}193
ESRI.ArcGIS.ADF.Web.Geometry.Polygon polygon = new ESRI.ArcGIS.ADF.Web.Geometry.Polygon();194
polygon.Rings.Add(points);195

196
//MapFunctionality197
foreach (ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality mapFunctionality in adfMap.GetFunctionalities())198
{199
//当Resource为ADFGraphicsResource,ADFGraphicsResource为GraphicsLayer, 保存在内存中用显示临时图层200
if (mapFunctionality.Resource.Name == "GraphicsResource")201
{202
adfGraphicsMapFunctionality = (ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality)mapFunctionality;203
break;204
}205
}206
//从adfGraphicsMapFunctionality获取名为Element Graphics的DataTable207
//ElementGraphicsLayers通常用来显示图形元素,例如显示Map中被选择的图形元素。图层并不用来存储属性,而可以存储不同的图形类型。208
ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer elementGraphicsLayer = null;209
foreach (System.Data.DataTable dataTable in adfGraphicsMapFunctionality.GraphicsDataSet.Tables)210
{211
if (dataTable.TableName == "Element Graphics")212
{213
elementGraphicsLayer = (ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer)dataTable;214
break;215
}216
}217
//如果名为Element Graphics的DataTable为null,就新建Element Graphics DataTable添加到adfGraphicsMapFunctionality.GraphicsDataSet中,同时刷新Toc1显示218
if (elementGraphicsLayer == null)219
{220
elementGraphicsLayer = new ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer();221
elementGraphicsLayer.TableName = "Element Graphics";222
adfGraphicsMapFunctionality.GraphicsDataSet.Tables.Add(elementGraphicsLayer);223
}224

225
ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleFillSymbol simpleMarkerSymbol = new ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleFillSymbol();226
simpleMarkerSymbol.Color = System.Drawing.Color.Yellow;227
simpleMarkerSymbol.FillType= ESRI.ArcGIS.ADF.Web.Display.Symbol.PolygonFillType.DiagCross;228

229
ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleFillSymbol simpleSelectedMarkerSymbol = new ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleFillSymbol();230
ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement graphicElement = new ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement(polygon, simpleMarkerSymbol, simpleSelectedMarkerSymbol);231
//把标点添加到elementGraphicsLayer232
elementGraphicsLayer.Add(graphicElement);233
234
}235
else if (args is CircleEventArgs)236
{237
CircleEventArgs circleEventArgs = (CircleEventArgs)args;238
239
ESRI.ArcGIS.ADF.Web.Geometry.PointCollection pc = new ESRI.ArcGIS.ADF.Web.Geometry.PointCollection();240
double degree;241
double rad = circleEventArgs.Radius;242
for (int i = 0; i < 359; i++)243
{ 244
degree = i * (Math.PI / 180);245
double x = circleEventArgs.CenterPoint.X + Math.Cos(degree) * rad;246
double y = circleEventArgs.CenterPoint.Y + Math.Sin(degree) * rad;247
ESRI.ArcGIS.ADF.Web.Geometry.Point nPoint = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint((int)Math.Round(x),(int)Math.Round(y), adfMap.GetTransformationParams(ESRI.ArcGIS.ADF.Web.Geometry.TransformationDirection.ToMap));248
pc.Add(nPoint);249
}250
ESRI.ArcGIS.ADF.Web.Geometry.Ring ring = new ESRI.ArcGIS.ADF.Web.Geometry.Ring();251
ring.Points = pc;252
ESRI.ArcGIS.ADF.Web.Geometry.RingCollection rings = new ESRI.ArcGIS.ADF.Web.Geometry.RingCollection();253
rings.Add(ring);254
ESRI.ArcGIS.ADF.Web.Geometry.Polygon polygon = new ESRI.ArcGIS.ADF.Web.Geometry.Polygon();255
polygon.Rings = rings;256

257
//MapFunctionality258
foreach (ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality mapFunctionality in adfMap.GetFunctionalities())259
{260
//当Resource为ADFGraphicsResource,ADFGraphicsResource为GraphicsLayer, 保存在内存中用显示临时图层261
if (mapFunctionality.Resource.Name == "GraphicsResource")262
{263
adfGraphicsMapFunctionality = (ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality)mapFunctionality;264
break;265
}266
}267
//从adfGraphicsMapFunctionality获取名为Element Graphics的DataTable268
//ElementGraphicsLayers通常用来显示图形元素,例如显示Map中被选择的图形元素。图层并不用来存储属性,而可以存储不同的图形类型。269
ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer elementGraphicsLayer = null;270
foreach (System.Data.DataTable dataTable in adfGraphicsMapFunctionality.GraphicsDataSet.Tables)271
{272
if (dataTable.TableName == "Element Graphics")273
{274
elementGraphicsLayer = (ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer)dataTable;275
break;276
}277
}278
//如果名为Element Graphics的DataTable为null,就新建Element Graphics DataTable添加到adfGraphicsMapFunctionality.GraphicsDataSet中,同时刷新Toc1显示279
if (elementGraphicsLayer == null)280
{281
elementGraphicsLayer = new ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer();282
elementGraphicsLayer.TableName = "Element Graphics";283
adfGraphicsMapFunctionality.GraphicsDataSet.Tables.Add(elementGraphicsLayer);284
}285

286
ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleFillSymbol simpleMarkerSymbol = new ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleFillSymbol();287
simpleMarkerSymbol.Color = System.Drawing.Color.Yellow;288
simpleMarkerSymbol.FillType = ESRI.ArcGIS.ADF.Web.Display.Symbol.PolygonFillType.DiagCross;289

290
ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleFillSymbol simpleSelectedMarkerSymbol = new ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleFillSymbol();291
ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement graphicElement = new ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement(polygon, simpleMarkerSymbol, simpleSelectedMarkerSymbol);292
//把标点添加到elementGraphicsLayer293
elementGraphicsLayer.Add(graphicElement);294

295
}296
else if(args is RectangleEventArgs)297
{298
RectangleEventArgs rectargs = (RectangleEventArgs)args;299
//矩形300
System.Drawing.Rectangle myrect = rectargs.ScreenExtent;301
//矩形左下定点坐标转换成地理坐标302
ESRI.ArcGIS.ADF.Web.Geometry.Point minpnt = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(myrect.Left, myrect.Bottom, adfMap.GetTransformationParams(ESRI.ArcGIS.ADF.Web.Geometry.TransformationDirection.ToMap));303
//矩形右上定点坐标转换成地理坐标304
ESRI.ArcGIS.ADF.Web.Geometry.Point maxpnt = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(myrect.Right, myrect.Top, adfMap.GetTransformationParams(ESRI.ArcGIS.ADF.Web.Geometry.TransformationDirection.ToMap));305
//306
ESRI.ArcGIS.ADF.Web.Geometry.Envelope mappoly = new ESRI.ArcGIS.ADF.Web.Geometry.Envelope(minpnt, maxpnt);307

308
//MapFunctionality309
foreach (ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality mapFunctionality in adfMap.GetFunctionalities())310
{311
//当Resource为ADFGraphicsResource,ADFGraphicsResource为GraphicsLayer, 保存在内存中用显示临时图层312
if (mapFunctionality.Resource.Name == "GraphicsResource")313
{314
adfGraphicsMapFunctionality = (ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality)mapFunctionality;315
break;316
}317
}318
//从adfGraphicsMapFunctionality获取名为Element Graphics的DataTable319
//ElementGraphicsLayers通常用来显示图形元素,例如显示Map中被选择的图形元素。图层并不用来存储属性,而可以存储不同的图形类型。320
ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer elementGraphicsLayer = null;321
foreach (System.Data.DataTable dataTable in adfGraphicsMapFunctionality.GraphicsDataSet.Tables)322
{323
if (dataTable.TableName == "Element Graphics")324
{325
elementGraphicsLayer = (ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer)dataTable;326
break;327
}328
}329
//如果名为Element Graphics的DataTable为null,就新建Element Graphics DataTable添加到adfGraphicsMapFunctionality.GraphicsDataSet中,同时刷新Toc1显示330
if (elementGraphicsLayer == null)331
{332
elementGraphicsLayer = new ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer();333
elementGraphicsLayer.TableName = "Element Graphics";334
adfGraphicsMapFunctionality.GraphicsDataSet.Tables.Add(elementGraphicsLayer);335
}336

337
ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleFillSymbol simpleMarkerSymbol = new ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleFillSymbol();338
simpleMarkerSymbol.Color = System.Drawing.Color.Yellow;339
simpleMarkerSymbol.FillType = ESRI.ArcGIS.ADF.Web.Display.Symbol.PolygonFillType.DiagCross;340

341
ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleFillSymbol simpleSelectedMarkerSymbol = new ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleFillSymbol();342
ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement graphicElement = new ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement(mappoly, simpleMarkerSymbol, simpleSelectedMarkerSymbol);343
//把标点添加到elementGraphicsLayer344
elementGraphicsLayer.Add(graphicElement);345

346
}347

348
//刷新显示349
if (adfMap.ImageBlendingMode == ImageBlendingMode.WebTier)350
{351
//整个地图控件刷新352
adfMap.Refresh();353
}354
else355
{356
//只刷新部分Resource357
adfMap.RefreshResource(adfGraphicsMapFunctionality.Resource.Name);358
}359
}360

361
}


浙公网安备 33010602011771号