2. Case study: Custom command to enlarge the map proportional ratio
In this section, we customize a button through custom command. Each time a button is clicked, the map will be doubled. Through this simple case, let's get familiar with command usage.
The main step to implement this function is to implement your own listener class. The following is the definition of this class:
Import com. ESRI. ADF. Web. Data. webcontext;
Import com. ESRI. ADF. Web. util. webutil;
Import javax. Faces. event. abortprocessingexception;
Import javax. Faces. event. actionevent;
Import javax. Faces. event. actionlistener;
Public class zoominlistener implements actionlistener
{
Public static double zoom_factor = 0.5;
Public void processaction (actionevent event) throws abortprocessingexception
{
Webcontext = webutil. getwebcontext (event. getcomponent ());
Webcontext. getwebmap (). getcurrentextent (). Expand (zoom_factor );
Webcontext. Refresh ();
}
}
Of course, the usage on the JSF page is similar to the above, and it is also very simple:
This zoominlistener listener class mainly needs to implement the processaction method of actionlistener. When the user clicks the command with the ID "zoomin", the listener will be triggered, the processaction method is executed.
In this processaction method, we first obtain the webcontext object. Through webcontext, we can obtain the webmap object and then perform operations on its currentextent attribute (the MAP range is reduced by one time ), refresh the webcontext object. This process is very simple. There are two links to explain here.
One step is how to obtain the webcontext object. Processaction is a method of the JSF actionlistener interface. The parameter of this method is actionevent, so its attributes are basically irrelevant to the ADF. Therefore, the webutil tool class of the ADF is required to obtain the webcontext, ESRI engineers created the webutil tool class and its getwebcontext method in order to obtain a very important environment of webcontext in various environments. Through this method, we can easily obtain the webcontext object.
Another step is the refresh method of the webcontext object. After some operations are performed on the webmap object on the server, after the webcontext refresh method is called, the map in the browser will be refreshed into a new view, its Related components such as TOC and overview will also be refreshed. This is amazing.