The tool execution process needs to interact with the map, and then execute the command, as shown in the following call statement.
<A: tool id = "countfeature" defaultimage = "images/selection.gif"
Hoverimage = "images/selection.gif"
Selectedimage = "images/selectiond.gif"
Clientaction = "esrimaprectangle"
Serveraction = "com. Demo. mycountfeaturetool"
Clientpostback = "true"/>
For more information about clientaction, see COM. ESRI. ADF. web. faces. clientactions interface in event. The client supports map_circle, map_continuous_pan, map_line, map_oval, map_pan, map_point, map_polygon, map_polyline, map_rectangle
After specifying clientaction, We need to compile the operation class corresponding to serveraction. You can obtain the number of elements selected in the selected area.
Mycountfeaturetool
Import java. RMI. RemoteException;
Import com. ESRI. ADF. Web. AGS. adfagsexception;
Import com. ESRI. ADF. Web. AGS. Data. agsmapresource;
Import com. ESRI. ADF. Web. Data. webcontext;
Import com. ESRI. ADF. Web. Data. Geometry. webextent;
Import com. ESRI. ADF. Web. Faces. event. mapevent;
Import com. ESRI. ADF. Web. Faces. event. maptoolaction;
Import com. ESRI. arcgisws. envelopen;
Import com. ESRI. arcgisws. esrisearchorder;
Import com. ESRI. arcgisws. esrispatialrelenum;
Import com. ESRI. arcgisws. mapserverport;
Import com. ESRI. arcgisws. spatialfilter;
/**
* Calculate the number of selected elements in the selected area.
* Use axis to call a remote WebService to call the method on the server.
*/
Public class mycountfeaturetool implements maptoolaction {
Webcontext context = NULL;
Int countedfeatures;
Private void countfeatures (webextent extent ){
Agsmapresource agsmap = (agsmapresource) Context. getresources (). Get ("agsws1 "));
Mapserverport mapserver = agsmap. getmapserver ();
// Make a new envelope from the Web extent
Envelopen Env = new envelopen (extent. getminx (), extent. getminy (),
Extent. getmaxx (), extent. getmaxy (), null, null );
// Setup a spatial filter for an intersection relationship
Spatialfilter = new spatialfilter ();
Spatialfilter. setspatialrel (esrispatialrelenum. esrispatialrelintersects );
Spatialfilter. setwhereclause ("");
Spatialfilter. setsearchorder (esrisearchorder. esrisearchorderspatial );
Spatialfilter. setspatialreldescription ("");
Spatialfilter. setgeometryfieldname ("");
// Set the envelope as the geometry
Spatialfilter. setfiltergeometry (ENV );
// Mapserver: queryfeaturecount () executes on the server and can throw
// RemoteException
Try {
// Count features in 4th layer which intersect with the envelope
Int layerid = 1;
This. countedfeatures = mapserver. queryfeaturecount (mapserver
. Getdefamapmapname (), layerid, spatialfilter );
System. Out. println ("You selected" + countedfeatures + "element ");
} Catch (RemoteException RME ){
Throw new adfagsexception (
"Cocould not execute mapserver: queryfeaturecount ()", RME );
}
}
Public void execute (mapevent arg0) throws exception {
Try {
This. Context = arg0.getwebcontext ();
Webextent EX = (webextent) arg0.getwebgeometry ();
Ex = (webextent) EX. tomapgeometry (arg0.getwebcontext (). getwebmap ());
This. countfeatures (Ex );
} Catch (exception ex ){
Ex. printstacktrace ();
}
}
}
Mycountfeaturetool2
Import java. util. List;
Import com. ESRI. ADF. Web. Data. webcontext;
Import com. ESRI. ADF. Web. Data. Geometry. webgeometry;
Import com. ESRI. ADF. Web. Data. query. identifycriteria;
Import com. ESRI. ADF. Web. Data. query. queryresult;
Import com. ESRI. ADF. Web. Data. query. webquery;
Import com. ESRI. ADF. Web. Faces. event. mapevent;
Import com. ESRI. ADF. Web. Faces. event. maptoolaction;
/**
* Query using webquery
*/
Public class mycountfeaturetool2 implements maptoolaction {
Private Static final long serialversionuid = 1l;
Public void execute (mapevent event ){
// Obtain the client-side drawing
Webcontext CTX = event. getwebcontext ();
Webgeometry screengeo = event. getwebgeometry ();
Webgeometry mapgeo = screengeo. tomapgeometry (CTX. getwebmap ());
Identifycriteria Ic = new identifycriteria (mapgeo );
Webquery query = (webquery) CTX. getattribute ("query ");
List <queryresult> Results = query. Query (IC, query. getquerylayers ());
System. Out. println (results. Size ());
}
}
Webquery is a webcontextattribute class used in a webcontext for querying attribute data and displaying related geometry objects spatially.
It is generally defined in the faces-config.xml of Web applications. The following shows how it can be added as an attribute of the webcontext.
<managed-bean> <managed-bean-name>mapContext</managed-bean-name> <managed-bean-class>com.esri.adf.web.data.WebContext</managed-bean-class> <managed-bean-scope>request</managed-bean-scope> <managed-property> <property-name>attributes</property-name> <map-entries> <map-entry> <key>query</key> <value>#{webappQuery}</value> </map-entry> ...
Below is the declaration of a webquery managed bean. Note the layerdefinition managed beans being referenced below.
<managed-bean> <managed-bean-name>webappQuery</managed-bean-name> <managed-bean-class>com.esri.adf.web.data.query.WebQuery</managed-bean-class> <managed-bean-scope>none</managed-bean-scope> <managed-property> <property-name>layerDefinitions</property-name> <list-entries> <value>#{arcgis_localmapgrid2_usa_2d_v_layer1}</value> .... </list-entries> </managed-property> </managed-bean>
Reference: Server Java lecture -- custom tools development
ArcGIS Server Java lecture-space query and highlighting implementation