原文:http://bbs.esrichina-bj.cn/ESRI/viewthread.php?tid=5590&extra=page%3D1

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表达如下:
  • <ags:tool
  • serverAction="com.esri.adf.web.faces.event.ZoomInToolAction"  
  • clientAction="EsriMapRectangle"
  • clientPostBack="true"
  • />
  • 复制代码

    三、注册managed-bean将所写的类作为一个managed-bean注册到faces-config.xml,并用WebContext实例作为其初始化参数:
  • <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.  JSPTagserverAction写入继承MapToolAction接口的类(全称),代表对于此工具服务器端要进行的操作[ execute(MapEvent event)]
    用户也可以使用任何Managed Bean的函数作为工具对应的方法,只要这个函数使用如下声明:
    public void anyMethodName(MapEvent event)
    JSP标签使用serverMethod ,如下:
    <ags:tool serverMethod="#{bean.anyMethodName}" ... />
    这样,MapControl也会将适当的MapEvent 事件传入此函数。

    2.  JSPTagclientAction写入客户端鼠标选择的方式:
  • 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)转换为 地图坐标
    一般操作如下:

  • public void myToolMethod(MapEvent event) {
  •    WebContext ctx = event.getWebContext();
  •    WebGeometry screenGeom = event.getWebGeometry();
  •    WebGeometry mapGeom = screen.toMapGeometry(ctx.getWebMap());
  •    ...
  • }
  • 复制代码


    4.  JSPTagclientPostBack
       l 设置为false,刷新地图,并且刷新页面;
       l 设置为true,只刷新地图,不刷新页面;

    对应Server端的几何形状


    相关文章: