随笔-18  评论-20  文章-0  trackbacks-0
ArcGIS Server 开发初步 -- 自定义工具

 

ArcGIS 9.2 Server Enterprise for Windows自定义工具

在Server生成的Web App中,页面的工具按钮可以分为两类:

l命令(Command):A command is an element on a JSP page that triggers a server side action without any further interaction on the client. An example of a command in the sample application is the "zoom to full extent" button. Once the user clicks the button, a method is called on the server。不与用户通过界面交互。
l工具(Tool):A tool has further client side interaction before calling a method on the server. An example of a tool in this application is "zoom to rectangle". Once the user clicks the button, drags a rectangle over the map indicating the area they want to zoom to, and then a method is called on the server。与用户通过界面交互。

自定义工具

一、继承接口
public Interface com.esri.adf.web.faces.event.MapToolAction{
             void execute(MapEvent event);
}
lMapToolAction 接口代表由MapControl控件事件所激活的服务器端工具,系统已预设继承此接口的类:
PanToolAction(平移),
ZoomInToolAction(放大),
ZoomOutToolAction(缩小)
lMapControl 创建MapEvent 事件并将其传给继承接口的工具类的 execute(MapEvent) 函数,The business logic for the tool should be implemented in this method according to the event。

二、工具在JSP页面上的tag表达如下:


[Copy to clipboard]CODE:
<ags:tool
serverAction="com.esri.adf.web.faces.event.ZoomInToolAction"  
clientAction="EsriMapRectangle"
clientPostBack="true"
/>


三、注册managed-bean将所写的类作为一个managed-bean注册到faces-config.xml,并用WebContext实例作为其初始化参数:



[Copy to clipboard]CODE:
<managed-bean>
<managed-bean-name>ToolClass</managed-bean-name>
<managed-bean-class>com.brsc.MyToolClass</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
       <property-name>webContext</property-name>
       <value>#{mapContext}</value>
</managed-property>
</managed-bean>


四、注释:
1.  JSP的Tag中serverAction写入继承MapToolAction接口的类(全称),代表对于此工具服务器端要进行的操作[ execute(MapEvent event)]
用户也可以使用任何Managed Bean的函数作为工具对应的方法,只要这个函数使用如下声明:
public void anyMethodName(MapEvent event)
JSP标签使用serverMethod ,如下:
<ags:tool serverMethod="#{bean.anyMethodName}" ... />
这样,MapControl也会将适当的MapEvent 事件传入此函数。

2.  JSP的Tag中clientAction写入客户端鼠标选择的方式:



[Copy to clipboard]CODE:
EsriMapPoint          点选
EsriMapLine           线
EsriMapRectangle    四边形
EsriMapCircle         圆
EsriMapOval           椭圆
EsriMapPolyline      多线
EsriMapPolygon      多边形
EsriMapPan            移动




对应Server端的几何形状(附图)

3.  MapEvent代表客户端进行操作产生的事件,一般会用到MapEvent的
public WebGeometry getWebGeometry()函数来得到客户端输入的几何形状
//Returns the WebGeometry in screen coordinates corresponding to
//the client action performed by the user.
来获得客户端产生的形状,这些Geomentry一般都是screen坐标,需要用toMapGeometry(WebMap)转换为 地图坐标 。
一般操作如下:



[Copy to clipboard]CODE:
public void myToolMethod(MapEvent event) {
  WebContext ctx = event.getWebContext();
  WebGeometry screenGeom = event.getWebGeometry();
  WebGeometry mapGeom = screen.toMapGeometry(ctx.getWebMap());
  ...
}



4.  JSP的Tag中clientPostBack
  l 设置为false,刷新地图,并且刷新页面;
  l 设置为true,只刷新地图,不刷新页面;
posted on 2007-08-16 11:15 JavaPoint 阅读(1592) 评论(0)  编辑  收藏 所属分类: ArcGis

只有注册用户登录后才能发表评论。


网站导航: