Com. ESRI. ADF. web. data. webcontext is a core class bound to many other components. These components are divided into attributes and resources. Webcontext provides lifecycle management services for these components. These services are not free of charge. components must implement some specific interfaces and register them with webcontext. Related interfaces include: COM. ESRI. ADF. web. data. webcontextinitialize
+ -- Public void Init (webcontext context)
+ -- Public void destroy ()
Com. ESRI. ADF. Web. Data. weblifecycle
+ -- Public void activate ()
+ -- Public void passivate ()
Com. ESRI. ADF. Web. Data. webcontextobserver
+ -- Public void Update (webcontext context, java. Lang. Object Arg)
Here we only discuss attributes components, such as webmap, webtoc, and weboverview. Why does the rectangle of overview change as we zoom in the map? It is because both webmap and weboverview are in the territory of webcontext, while weboverview implements the webcontextobserver interface. Haha, this is equivalent to the service fee paid to webcontext. Every time the webcontext status changes, all send messages to weboverview to make synchronous adjustments.
For attributes registered in webcontext, when the first request of the session starts, execute the init () operation, and then passivate (); for the next request in this session, it always starts from activate () and ends with passivate (). When the session is terminated, the destroy () operation is executed. This is the life cycle of attribute. Of course, the above three interfaces do not require all to be implemented.
Now let's take a look at how to customize an attribute. There is a related example in the document, but it is not detailed enough. Here is an example: the basemap uses various countries in Asia to display the logo related to the country in the upper left corner of the map based on the country displayed on the current map, when the map stays in China, there is a tornado in the upper left corner and an ax warrior in Japan.
First, define a class to implement the above three interfaces. In the init method (), register this class as the webcontext listener to listen to the extent changes of webmap: public class picselector
Implements webcontextobserver, weblifecycle, webcontextinitialize {
Public void Init (webcontext CTX ){
CTX. addobserver (this );
}
Public void destroy (){
System. Out. println ("picselector destroyed .");
}
The activate () and passivate () methods are executed for each request. Therefore, these two methods are suitable for obtaining and releasing resources, in this example, I/O interfaces are used to read image files:
Public void activate (){
String pic_1 = "E:/images/token.png ";
String pic_2 = "E: // images/wushi .png ";
Try {
Input_1 = new bufferedinputstream (New fileinputstream (pic_1 ));
Input_2 = new bufferedinputstream (New fileinputstream (pic_2 ));
} Catch (ioexception e ){
E. printstacktrace ();
}
}
Public void passivate (){
Try {
Input_1.close ();
Input_2.close ();
} Catch (ioexception e ){
E. printstacktrace ();
}
}
Next, Dynamically Retrieve the logo image based on the map display content and display it in the upper left corner of the MAP:
Public void Update (webcontext CTX, object arg1 ){
Webextent currentextent = CTX. getwebmap (). getcurrentextent ();
CTX. getwebgraphics (). cleargraphics ();
This. updatepic (currentextent, CTX );
}
Private void updatepic (webextent Ext, webcontext CTX ){
If () {// determine from extent whether the main region is China
Webpicturemarkersymbol PIC = new webpicturemarkersymbol ();
Try {
Byte [] bpic_1 = new byte [input_1.available ()];
Input_1.read (bpic_1 );
PIC. setpicture (bpic_1 );
} Catch (ioexception e ){
System. Out. println (E. getmessage ());
Return;
}
Webgraphics graphics = CTX. getwebgraphics ();
Graphicelement element = new graphicelement ();
Element. setsymbol (PIC );
Element. setgeometry (New webpoint (extent. getminx (), extent. getmaxy ()));
Graphics. addgraphics (element );
}
Else if () // Similarly, below
}
Finally, register this custom attribute in the faces-config.xml:
<Managed-property>
<Property-Name> attributes </property-Name>
<Map-entries>
<Map-entry>
<Key> myattr </key>
<Value >#{ myattr} </value>
</Map-entry>
</Map-entries>
</Managed-property>
<Managed-bean>
<Managed-bean-Name> myattr </managed-bean-Name>
<Managed-bean-class> com. WJ. Test. Data. picselector </managed-bean-class>
<Managed-bean-scope> none </managed-bean-scope>
</Managed-bean>
The Update () method is called in bcontext. If the update () method meets the requirements, the "enumeration" method will be called. See -->
CTRL + scroll wheel zoom in or out "src =" http://bbs.esrichina-bj.cn/esri/attachments/forumid_25/zcK78MH6_P2kIgZATcxy6.jpg "width =" 716 "border =" 0 "resized =" true ">
Samurai. jpg (59.59 KB)
CTRL + scroll wheel zoom in or out "src =" http://bbs.esrichina-bj.cn/esri/attachments/forumid_25/zuTKvw==_snxmqcv4LVdG.jpg "width =" 716 "border =" 0 "resized =" true ">