ArcGIS JSF Ajax implementation return Real-Time Scale

Source: Internet
Author: User

1. The map control of ArcGIS directly supports Ajax.

To use Ajax for map operations, perform the following operations:

Call the init method during body onload.

 

Function Init ()
{
VaR map = esricontrols. Maps ["map0"];
Map. addupdatelistener ("request", updateinforequest );
}

 

In this way, we will call the updateinforequest method when performing operations on the map.

 

Function updateinforequest (){
VaR url = esriutils. getserverurl ("frmmap ");
VaR map = esricontrols. Maps ["map0"];
VaR Params = "ajaxdemo = ajaxdemo & mapid = map0 &" + esriutils. buildrequestparams (Map. formid );

VaR XMLHTTP = esriutils. sendajaxrequest (URL, Params, true, function ()
{Updateinforesponse (XMLHTTP );});
}

 

Updateinforesponse is the callback function called when Ajax sends a request.

 

This function can be used to update our interface.

 

Function updateinforesponse (XMLHTTP ){

If (XMLHTTP! = NULL & XMLHTTP. readystate = 4 & XMLHTTP. Status = 200 ){
VaR xml = XMLHTTP. responsexml;
VaR scale = xml. getelementsbytagname ("scale"). Item (0). firstchild. nodevalue;
Document. getelementbyid ("scale"). value = "1:" + scale
}
}

 

Client calls

 

What does the server do?

 

We can use a class on the server to implement the phaselistener interface.

 

 

The Ajax lifecycle is executed independently on the server. This means that the browser sends a request with certain parameters and expects an XML response in a specific format. This response can be composed of any type of JSF phaselisteners, Servlet, or even static XML files. Now let's take a look at how to use phaselistener to process a request and return a response to the browser.

When the browser uses the XMLHTTPRequest object to send a request to the server, this request follows the standard JSF request processing lifecycle. These components are rebuilt in the restore view phase and their statuses are updated in the apply request values phase. Because we need to update the components on the page, we will skip the processing of the phaselistener. beforephase () method. In the phaselistener. afterphase method, we process the request and render the response to the client.

 

CodeAs follows:

 

 

Public class ajaxdemophaselistener implements phaselistener {
 
Public phaseid getphaseid (){
// Todo auto-generated method stub

// This indicates processing the application request Value
Return phaseid. apply_request_values;
}
Public void afterphase (phaseevent ){

Facescontext = phaseevent. getfacescontext ();
Externalcontext = facescontext. getexternalcontext ();
Map parammap = externalcontext. getrequestparametermap ();

String formid = (string) parammap. Get ("formid ");

String mapid = (string) parammap. Get ("mapid ");

// Determine whether the request is required. If not, return directly.
String ajaxdemo = (string) parammap. Get ("ajaxdemo ");
If (ajaxdemo = NULL |! Ajaxdemo. Equals ("ajaxdemo "))
Return;





Uicomponent form = facescontext. getviewroot (). findcomponent (formid );
Mapcontrol MC = (mapcontrol) form. findcomponent (mapid );
Webmap WM = mc. getwebmap ();
String scale = string. valueof (WM. getmapscale ());

Document Doc = xmlutil. newdocument ();
Element responseelement = xmlutil. createelement (Doc, "response", null, null );
Xmlutil. createelement ("scale", scale, responseelement );
Try {
Ajaxutil. writeresponse (facescontext, DOC );

//

Facescontext. responsecomplete ();
} Catch (ioexception E1 ){
// Todo auto-generated Catch Block
E1.printstacktrace ();
}

}
 
 

Public void beforephase (phaseevent ){

}

 

}

 

Finally, we register the listener in <lifecycle>.

 

In this way, the whole process of using ArcGIS Ajax is completed.

 

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.