这里常用的功能主要指地图的基本操作,如放大、缩小、全局显示、框选、圆选什么的。是我们在系统中最常用到的功能。分析下demo可以看出这些基本操作supermap都将其封装为了一个SuperMap.IS.Action.js这个文件,里面的基类就是SuperMap.IS.Action这个类了。主要包括Init,Destroy,OnClick,OnDoubleClick,OnmouseMove 等鼠标事件,就不详细列了。当我们编程时使用MapControl1.SetAction(action)时,就会调用action中的init函数,并将地图上的操作监听起来,通过鼠标的与地图的交互来完成我们的一些操作。所以我们可以根据其SuperMap.IS.Action这个基类来写我们自己的一些action。
下面来自己封装下对应的一些常用功能函数,便于以后的重用。
先贴代码,^_^。
![]()
Code
1
///<summary>常用功能(工具栏功能)</summary>
2![]()
3
HJMapUtils.CommonUtils = Class(object,
4![]()
5![]()
![]()
{
6![]()
7
zoomInAction: null,
8![]()
9
panAction: null,
10![]()
11
drawLineAction: null,
12![]()
13
measureAreaAction: null,
14![]()
15
measureDistanceAction: null,
16![]()
17
18![]()
19
20![]()
21
rectQueryAction: null,
22![]()
23![]()
Create: function(mapControl, divResult)
{
24![]()
25
///<summary>常用功能构造函数</summary>
26![]()
27
///<param name="mapControl">地图控件</param>
28![]()
29
///<param name="divResult">查询结果信息容器</param>
30![]()
31
this.MapControl1 = mapControl;
32![]()
33
object.divResult = divResult;
34![]()
35
},
36![]()
37![]()
ViewEntire: function()
{
38![]()
39
///<summary>全局显示</summary>
40![]()
41
this.MapControl1.ViewEntire();
42![]()
43
},
44![]()
45![]()
SetZoomInAction: function()
{
46![]()
47
///<summary>放大</summary>
48![]()
49![]()
if (!this.zoomInAction)
{
50![]()
51
this.zoomInAction = new SuperMap.IS.ZoomInAction();
52![]()
53
};
54![]()
55
this.MapControl1.SetAction(this.zoomInAction);
56![]()
57
},
58![]()
59
60![]()
61![]()
SetPanAction: function()
{
62![]()
63
///<summary>平移</summary>
64![]()
65![]()
if (!this.panAction)
{
66![]()
67
this.panAction = new SuperMap.IS.PanAction();
68![]()
69
};
70![]()
71
this.MapControl1.SetAction(this.panAction);
72![]()
73
},
74![]()
75![]()
SetDrawLineAction: function()
{
76![]()
77
///<summary>画线</summary>
78![]()
79![]()
if (!this.drawLineAction)
{
80![]()
81
this.drawLineAction = new SuperMap.IS.DrawLineAction();
82![]()
83
}
84![]()
85
this.MapControl1.SetAction(this.drawLineAction);
86![]()
87
},
88![]()
89![]()
SetPointQueryAction: function(queryLayer, returnFields, whereClause)
{
90![]()
91
///<summary>点查询</summary>
92![]()
93
///<param name="queryLayer">查询图层(多个图层用','隔开)</param>
94![]()
95
///<param name="returnFields">返回字段(多个使用','隔开)</param>
96![]()
97
///<param name="whereClause">图层限制条件(多个用','隔开,没有设置为'')</param>
98![]()
99
100![]()
101![]()
if (!this.pointQueryAction)
{
102![]()
103
var layers = this.SetQueryLayers(queryLayer);
104![]()
105
var fields = this.SetReturnFields(returnFields);
106![]()
107
var whereclause = this.SetWhereClause(whereClause);
108![]()
109
this.pointQueryAction = new SuperMap.IS.PointQueryAction(layers, fields, 200, whereclause, this.onQueryComplete, this.onError);
110![]()
111
}
112![]()
113
this.MapControl1.SetAction(this.pointQueryAction);
114![]()
115
}
116![]()
117
}
通过编程我们发现常用的功能还是很容易实现的,supermap已经将常用的功能封装好供我们简单的调用,只用new 出一个对应的action,并绑定到mapctrol中就可以使用。就关于点查询等需要处理查询结果的需要写相关查询结果处理函数,如上面的onQueryComplete函数,它会返回一个result的参数,即结果数据集(不知道为什么,好像圆选会有些问题......)。相比AGS来说,会感觉实现这些功能比较简单多,不像ADF中得写相关实现ImapServerToolAction的类及相关代码。有兴趣的可以试试自己写写自定义的action,如过去点击点的坐标等。^_^