Complete ArcGIS custom tools tutorial 1/2 complete ArcGIS custom tools tutorial 1/2

Source: Internet
Author: User
[Go to] complete ArcGIS custom tool tutorial 1/2

I. Client -- Tag on the page:
<Ags: tool
ClientAction = "EsriMapRectangle"
ServerAction = "com. esri. adf. web. faces. event. ZoomInToolAction"
ClientPostBack = "true"
/>
Ii. Client-clientAction
ClientAction refers to a javascript class, which must inherit EsriMapToolItem and overload several functions:
Appendix 1
1. The first is: Object. inheritsFrom (Object parent), which is a function extension added by Esri to all js objects and used to inherit the parent class.
2. EsriMapToolItem functions include:
EsriMapToolItem constructor:
EsriMapToolItem (String id, // <a: id attribute of tool
String toolName, // Tool Name
EsriAction action, // actions that the tool should perform
Boolean isMarker )//
Here, EsriAction specifies the client map operation class (Action) that should be performed after the tool button is pressed, such as EsriDrawPointAction and EsriDrawRectangleAction.
EsriAction has functions:
Void activate () is used to register the functions triggered by mouse and keyboard events. parameters vary with the EsriAction subclass.
Void deactivate () cancel event registration
The following inherited functions may be rewritten:
Void activate () indicates the event processing triggered when the tool button is pressed;
This function has been implemented by EsriMapToolItem. Unless customized, it is generally not overwritten.
Void deactivate () refers to the event processing triggered when this button is not active when another button is selected;
This function has been implemented by EsriMapToolItem. Unless customized, it is generally not overwritten.
After the void postAction () map operation is completed, the map operation parameters are generally submitted to the server;
This function is generally registered in the EsriAction. activate parameter of the implementation class (implemented by EsriMapToolItem );
3. attributes inherited from EsriMapToolItem:
EsriAction action the EsriAction defined by MapToolItem
Whether the MapToolItem of bool isActive is in the active state
EsriControl controls the controls used by MapToolItem, such as map)
4. You can add the following code on the page:
</Head>
<Script type = "text/javascript">
Function MyClientAction (id, toolName, isMarker ){
This. inheritsFrom (new EsriMapToolItem (id, toolName, new EsriDrawPointAction (), isMarker ));
This. activate = function (){
If (this. action) {// if action exists, register this. postAction as the callback function after clicking the map.
This. action. activate (this. element, this. postAction );
}
This. isActive = true;
Alert ("activated ");
}
This. deactivate = function (){
If (this. action ){
This. action. deactivate ();
}
This. isActive = false;
Alert ("deactivated ");
}
This. postAction = function (point ){
Alert ("postAction x =" + point. x + ";" + point. y );
}
}
</Script>
<Body...
...
<A: tool id = "mytool" defaultImage = "images/tasks/maptools/point.gif"
ClientAction = "MyClientAction"
ServerAction = "com. brsc. MyServerAction"
ClientPostBack = "false"
/>
-------------------------------------------------------
The compiled javascript code is roughly as follows:
....
Var mytool = new MyClientAction ("mytool", "", false );
Mytool. clientPostBack = true;
Mytool. defaultImage = "images/tasks/maptools/point.gif ";
Mytool. isDisabled = false;
Mytool. showLoading = true;
Toolbar. addToolItem (mytool );
....
3. client -- send request and callback function in postAction to process return parameters
To obtain parameters submitted in the void postAction () function, you must first write the parameters to Void addFormElement (String formId, String name, String value)
Then submit it to the server:
Void EsriUtils. submitForm (String formId //
[, Boolean async, // <a: clientPostBack attribute in tool,
// If it is false, the entire form will be submitted and the entire page will be refreshed;
// If this parameter is set to true, Ajax is used for data transmission. The entire page is not refreshed.
Function callback]) // receives the callback function returned by the Servlet (note that only the callback function name is written here)
<A: If the clientPostBack attribute in tool is set to false, the entire page is refreshed, that is, the map is refreshed. Otherwise, only data is returned and the map does not move.
To have a response from the server, you must add the following data format to postAction:
Var map = self. control;
EsriUtils. addFormElement (map. formId, map. id, map. id );
EsriUtils. addFormElement (map. formId, map. id + "_ mode", self. id );
... // Add Custom Data
EsriUtils. submitForm (...)
Example:
Function MyClientAction (id, toolName, isMarker ){
Var self = this;
This. inheritsFrom (new EsriMapToolItem (id, toolName, new EsriDrawPointAction (), isMarker ));
This. activate = function (){
If (this. action ){
This. action. activate (this. element, this. postAction );
}
This. isActive = true;
}
This. deactivate = function (){
If (this. action ){
This. action. deactivate ();
}
This. isActive = false;
}
This. update = function () {self = this ;}
This. postAction = function (point ){
Self. update ();
Var map = self. control;
EsriUtils. addFormElement (map. formId, map. id, map. id );
EsriUtils. addFormElement (map. formId, map. id + "_ mode", self. id );
EsriUtils. addFormElement (map. formId, "x", point. x );
EsriUtils. addFormElement (map. formId, "y", point. y );
EsriUtils. submitForm (map. formId, self. clientPostBack, mycallback );
}
}
Function mycallback (xh ){
If (xh. readyState = 4 ){
Alert (xh. responseText );
}
}
</Script>
When a request is sent, if you want to draw a picture on the interface, after the map is obtained in postAction, EsriMap contains an attribute.
EsriGraphicsElement graphics
It can be used for graph creation.

I. Client -- Tag on the page:
<Ags: tool
ClientAction = "EsriMapRectangle"
ServerAction = "com. esri. adf. web. faces. event. ZoomInToolAction"
ClientPostBack = "true"
/>
Ii. Client-clientAction
ClientAction refers to a javascript class, which must inherit EsriMapToolItem and overload several functions:
Appendix 1
1. The first is: Object. inheritsFrom (Object parent), which is a function extension added by Esri to all js objects and used to inherit the parent class.
2. EsriMapToolItem functions include:
EsriMapToolItem constructor:
EsriMapToolItem (String id, // <a: id attribute of tool
String toolName, // Tool Name
EsriAction action, // actions that the tool should perform
Boolean isMarker )//
Here, EsriAction specifies the client map operation class (Action) that should be performed after the tool button is pressed, such as EsriDrawPointAction and EsriDrawRectangleAction.
EsriAction has functions:
Void activate () is used to register the functions triggered by mouse and keyboard events. parameters vary with the EsriAction subclass.
Void deactivate () cancel event registration
The following inherited functions may be rewritten:
Void activate () indicates the event processing triggered when the tool button is pressed;
This function has been implemented by EsriMapToolItem. Unless customized, it is generally not overwritten.
Void deactivate () refers to the event processing triggered when this button is not active when another button is selected;
This function has been implemented by EsriMapToolItem. Unless customized, it is generally not overwritten.
After the void postAction () map operation is completed, the map operation parameters are generally submitted to the server;
This function is generally registered in the EsriAction. activate parameter of the implementation class (implemented by EsriMapToolItem );
3. attributes inherited from EsriMapToolItem:
EsriAction action the EsriAction defined by MapToolItem
Whether the MapToolItem of bool isActive is in the active state
EsriControl controls the controls used by MapToolItem, such as map)
4. You can add the following code on the page:
</Head>
<Script type = "text/javascript">
Function MyClientAction (id, toolName, isMarker ){
This. inheritsFrom (new EsriMapToolItem (id, toolName, new EsriDrawPointAction (), isMarker ));
This. activate = function (){
If (this. action) {// if action exists, register this. postAction as the callback function after clicking the map.
This. action. activate (this. element, this. postAction );
}
This. isActive = true;
Alert ("activated ");
}
This. deactivate = function (){
If (this. action ){
This. action. deactivate ();
}
This. isActive = false;
Alert ("deactivated ");
}
This. postAction = function (point ){
Alert ("postAction x =" + point. x + ";" + point. y );
}
}
</Script>
<Body...
...
<A: tool id = "mytool" defaultImage = "images/tasks/maptools/point.gif"
ClientAction = "MyClientAction"
ServerAction = "com. brsc. MyServerAction"
ClientPostBack = "false"
/>
-------------------------------------------------------
The compiled javascript code is roughly as follows:
....
Var mytool = new MyClientAction ("mytool", "", false );
Mytool. clientPostBack = true;
Mytool. defaultImage = "images/tasks/maptools/point.gif ";
Mytool. isDisabled = false;
Mytool. showLoading = true;
Toolbar. addToolItem (mytool );
....
3. client -- send request and callback function in postAction to process return parameters
To obtain parameters submitted in the void postAction () function, you must first write the parameters to Void addFormElement (String formId, String name, String value)
Then submit it to the server:
Void EsriUtils. submitForm (String formId //
[, Boolean async, // <a: clientPostBack attribute in tool,
// If it is false, the entire form will be submitted and the entire page will be refreshed;
// If this parameter is set to true, Ajax is used for data transmission. The entire page is not refreshed.
Function callback]) // receives the callback function returned by the Servlet (note that only the callback function name is written here)
<A: If the clientPostBack attribute in tool is set to false, the entire page is refreshed, that is, the map is refreshed. Otherwise, only data is returned and the map does not move.
To have a response from the server, you must add the following data format to postAction:
Var map = self. control;
EsriUtils. addFormElement (map. formId, map. id, map. id );
EsriUtils. addFormElement (map. formId, map. id + "_ mode", self. id );
... // Add Custom Data
EsriUtils. submitForm (...)
Example:
Function MyClientAction (id, toolName, isMarker ){
Var self = this;
This. inheritsFrom (new EsriMapToolItem (id, toolName, new EsriDrawPointAction (), isMarker ));
This. activate = function (){
If (this. action ){
This. action. activate (this. element, this. postAction );
}
This. isActive = true;
}
This. deactivate = function (){
If (this. action ){
This. action. deactivate ();
}
This. isActive = false;
}
This. update = function () {self = this ;}
This. postAction = function (point ){
Self. update ();
Var map = self. control;
EsriUtils. addFormElement (map. formId, map. id, map. id );
EsriUtils. addFormElement (map. formId, map. id + "_ mode", self. id );
EsriUtils. addFormElement (map. formId, "x", point. x );
EsriUtils. addFormElement (map. formId, "y", point. y );
EsriUtils. submitForm (map. formId, self. clientPostBack, mycallback );
}
}
Function mycallback (xh ){
If (xh. readyState = 4 ){
Alert (xh. responseText );
}
}
</Script>
When a request is sent, if you want to draw a picture on the interface, after the map is obtained in postAction, EsriMap contains an attribute.
EsriGraphicsElement graphics
It can be used for graph creation.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.