项目中使用ToolItem很方便,将ToolManager放在隐藏的div里面,然后通过页面生成的JavaScript函数来调用对应的ToolItem,这样可以有更大的*度,方便布局和程序编程。不过貌似需要放在onmousedown这个事件中来调用,如果是onclick事件,调用后处理参数中e不会是1而返回。选择ToolItem很简单,在地图上的clientjs来画圆 多边形 点 线来返回对应的屏幕坐标,然后通过参数转换成对对应的图上坐标,然后通过查询functionality来进行查询显示。这里做个marker,方便以后查询。点选偷懒了,^_^。
Code
1 ESRI.ArcGIS.ADF.Web.Geometry.Envelope maprect=null;
2
3
4 //框选查询
5 if (args is RectangleEventArgs)
6 {
7 RectangleEventArgs rectargs = (RectangleEventArgs)args;
8 System.Drawing.Rectangle rect = rectargs.ScreenExtent;
9 //矩形框left-bottom(最小值)
10 ESRI.ArcGIS.ADF.Web.Geometry.Point minpoint = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(rect.Left, rect.Bottom, mapctrl.Extent, (int)mapctrl.Width.Value, (int)mapctrl.Height.Value);
11 //矩形框right-top(最大值)
12 ESRI.ArcGIS.ADF.Web.Geometry.Point maxpoint = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(rect.Right, rect.Top, mapctrl.Extent, (int)mapctrl.Width.Value, (int)mapctrl.Height.Value);
13 //生成对应的地图范围(envelope)
14 maprect = new ESRI.ArcGIS.ADF.Web.Geometry.Envelope(minpoint, maxpoint);
15
16 }
17 //点选查询
18 else if(args is PointEventArgs)
19 {
20 PointEventArgs pea = (PointEventArgs)args;
21 ESRI.ArcGIS.ADF.Web.Geometry.Point point = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(pea.ScreenPoint.X,pea.ScreenPoint.Y, mapctrl.Extent, (int)mapctrl.Width.Value, (int)mapctrl.Height.Value);
22 ESRI.ArcGIS.ADF.Web.Geometry.Point point2=new ESRI.ArcGIS.ADF.Web.Geometry.Point(point.X+1,point.Y+1);
23 maprect = new ESRI.ArcGIS.ADF.Web.Geometry.Envelope(point, point2);
24 }
25
26 //多边形查询
27 else if (args is PolygonEventArgs)
28 {
29 PolygonEventArgs polygonEventArgs = args as PolygonEventArgs;
30 ESRI.ArcGIS.ADF.Web.Geometry.Ring points = new ESRI.ArcGIS.ADF.Web.Geometry.Ring();
31 for (int i = 0; i < polygonEventArgs.Vectors.Length; i++)
32 {
33 ESRI.ArcGIS.ADF.Web.Geometry.Point point = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(polygonEventArgs.Vectors[i].X, polygonEventArgs.Vectors[i].Y, mapctrl.Extent, (int)mapctrl.Width.Value, (int)mapctrl.Height.Value);
34 points.Points.Add(point);
35 }
36 maprect = ESRI.ArcGIS.ADF.Web.Geometry.Envelope.GetMinimumEnclosingEnvelope(points.Points);
37 }
38
39 //圆选查询
40 else if(args is CircleEventArgs)
41 {
42 CircleEventArgs circleEventArgs = args as CircleEventArgs;
43 ESRI.ArcGIS.ADF.Web.Geometry.PointCollection points = new ESRI.ArcGIS.ADF.Web.Geometry.PointCollection();
44 double degree;
45 double rad = circleEventArgs.Radius;
46 for (int i = 0; i < 359; i++)
47 {
48 degree = i * (Math.PI / 180);
49 double x = circleEventArgs.CenterPoint.X + Math.Cos(degree) * rad;
50 double y = circleEventArgs.CenterPoint.Y + Math.Sin(degree) * rad;
51 ESRI.ArcGIS.ADF.Web.Geometry.Point nPoint = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint((int)Math.Round(x),(int)Math.Round(y),mapctrl.Extent, (int)mapctrl.Width.Value, (int)mapctrl.Height.Value);
52 points.Add(nPoint);
53 }
54 maprect = ESRI.ArcGIS.ADF.Web.Geometry.Envelope.GetMinimumEnclosingEnvelope(points);
55
56 }
57
58 //开始查询
59 ESRI.ArcGIS.ADF.Web.SpatialFilter spatialFilter = new SpatialFilter();
60 spatialFilter.ReturnADFGeometries = false;
61 spatialFilter.MaxRecords = 1000;
62 spatialFilter.Geometry = maprect;
63
64
65 int resourceindex = 2;//这里是查询的resourceid,写死了,可以更具session来保存
66 System.Data.DataTable dt = null;
67 ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality mapFunction = mapctrl.GetFunctionality(resourceindex);
68 ESRI.ArcGIS.ADF.Web.DataSources.IGISResource gissource = mapFunction.Resource;
69 if (gissource.SupportsFunctionality(typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality)))
70 {
71 ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality queryFunction = (ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality)gissource.CreateFunctionality(typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality), null);
72 string[] lids = null;
73 string[] lnames = null;
74 queryFunction.GetQueryableLayers(null, out lids, out lnames);
75 int i = 0;
76 for (int k = 0; k < lnames.Length; k++)
77 {
78 if (lnames[k].CompareTo(targetLayer) == 0)
79 { i = k; break; }
80 }
81 //dt=queryFunction.Query(null,lids[i],spatialFilter);//查询出的结果信息
82 dt = queryFunction.Query(null, lids[i], spatialFilter);//查询出的结果信息
83
84 }
1 ESRI.ArcGIS.ADF.Web.Geometry.Envelope maprect=null;
2
3
4 //框选查询
5 if (args is RectangleEventArgs)
6 {
7 RectangleEventArgs rectargs = (RectangleEventArgs)args;
8 System.Drawing.Rectangle rect = rectargs.ScreenExtent;
9 //矩形框left-bottom(最小值)
10 ESRI.ArcGIS.ADF.Web.Geometry.Point minpoint = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(rect.Left, rect.Bottom, mapctrl.Extent, (int)mapctrl.Width.Value, (int)mapctrl.Height.Value);
11 //矩形框right-top(最大值)
12 ESRI.ArcGIS.ADF.Web.Geometry.Point maxpoint = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(rect.Right, rect.Top, mapctrl.Extent, (int)mapctrl.Width.Value, (int)mapctrl.Height.Value);
13 //生成对应的地图范围(envelope)
14 maprect = new ESRI.ArcGIS.ADF.Web.Geometry.Envelope(minpoint, maxpoint);
15
16 }
17 //点选查询
18 else if(args is PointEventArgs)
19 {
20 PointEventArgs pea = (PointEventArgs)args;
21 ESRI.ArcGIS.ADF.Web.Geometry.Point point = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(pea.ScreenPoint.X,pea.ScreenPoint.Y, mapctrl.Extent, (int)mapctrl.Width.Value, (int)mapctrl.Height.Value);
22 ESRI.ArcGIS.ADF.Web.Geometry.Point point2=new ESRI.ArcGIS.ADF.Web.Geometry.Point(point.X+1,point.Y+1);
23 maprect = new ESRI.ArcGIS.ADF.Web.Geometry.Envelope(point, point2);
24 }
25
26 //多边形查询
27 else if (args is PolygonEventArgs)
28 {
29 PolygonEventArgs polygonEventArgs = args as PolygonEventArgs;
30 ESRI.ArcGIS.ADF.Web.Geometry.Ring points = new ESRI.ArcGIS.ADF.Web.Geometry.Ring();
31 for (int i = 0; i < polygonEventArgs.Vectors.Length; i++)
32 {
33 ESRI.ArcGIS.ADF.Web.Geometry.Point point = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(polygonEventArgs.Vectors[i].X, polygonEventArgs.Vectors[i].Y, mapctrl.Extent, (int)mapctrl.Width.Value, (int)mapctrl.Height.Value);
34 points.Points.Add(point);
35 }
36 maprect = ESRI.ArcGIS.ADF.Web.Geometry.Envelope.GetMinimumEnclosingEnvelope(points.Points);
37 }
38
39 //圆选查询
40 else if(args is CircleEventArgs)
41 {
42 CircleEventArgs circleEventArgs = args as CircleEventArgs;
43 ESRI.ArcGIS.ADF.Web.Geometry.PointCollection points = new ESRI.ArcGIS.ADF.Web.Geometry.PointCollection();
44 double degree;
45 double rad = circleEventArgs.Radius;
46 for (int i = 0; i < 359; i++)
47 {
48 degree = i * (Math.PI / 180);
49 double x = circleEventArgs.CenterPoint.X + Math.Cos(degree) * rad;
50 double y = circleEventArgs.CenterPoint.Y + Math.Sin(degree) * rad;
51 ESRI.ArcGIS.ADF.Web.Geometry.Point nPoint = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint((int)Math.Round(x),(int)Math.Round(y),mapctrl.Extent, (int)mapctrl.Width.Value, (int)mapctrl.Height.Value);
52 points.Add(nPoint);
53 }
54 maprect = ESRI.ArcGIS.ADF.Web.Geometry.Envelope.GetMinimumEnclosingEnvelope(points);
55
56 }
57
58 //开始查询
59 ESRI.ArcGIS.ADF.Web.SpatialFilter spatialFilter = new SpatialFilter();
60 spatialFilter.ReturnADFGeometries = false;
61 spatialFilter.MaxRecords = 1000;
62 spatialFilter.Geometry = maprect;
63
64
65 int resourceindex = 2;//这里是查询的resourceid,写死了,可以更具session来保存
66 System.Data.DataTable dt = null;
67 ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality mapFunction = mapctrl.GetFunctionality(resourceindex);
68 ESRI.ArcGIS.ADF.Web.DataSources.IGISResource gissource = mapFunction.Resource;
69 if (gissource.SupportsFunctionality(typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality)))
70 {
71 ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality queryFunction = (ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality)gissource.CreateFunctionality(typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality), null);
72 string[] lids = null;
73 string[] lnames = null;
74 queryFunction.GetQueryableLayers(null, out lids, out lnames);
75 int i = 0;
76 for (int k = 0; k < lnames.Length; k++)
77 {
78 if (lnames[k].CompareTo(targetLayer) == 0)
79 { i = k; break; }
80 }
81 //dt=queryFunction.Query(null,lids[i],spatialFilter);//查询出的结果信息
82 dt = queryFunction.Query(null, lids[i], spatialFilter);//查询出的结果信息
83
84 }