ArcGIS Server ADF Ajax frontend and backend interaction (Memo)

Source: Internet
Author: User
Before using arcgis server adf, I thought using ajax was so easy, but I felt quite depressed before using it. OK.

Scenario: I want to obtain the MAP range in the current field of view from the background and return it to the user through xml.

Steps:

1. Write a MapExtentListener class to implement the PhaseListener interface. The Code is as follows:

Package COM. ESRI. ADF. web. templates; import Java. io. ioexception; import Java. util. map; import javax. faces. context. facescontext; import javax. faces. event. phaseevent; import javax. faces. event. phaseid; import javax. faces. event. phaselistener; import Org. w3C. dom. document; import Org. w3C. dom. element; import COM. ESRI. ADF. web. data. webcontext; import COM. ESRI. ADF. web. data. webmap; import COM. ESRI. ADF. web. data. geometry. W Ebextent; import COM. ESRI. ADF. web. faces. renderkit. XML. ajax. ajaxutil; import COM. ESRI. ADF. web. util. webutil; import COM. ESRI. ADF. web. util. xmlutil;/*** get map field of view * @ author likehua **/public class mapextentlistener implements phaselistener {Private Static final long serialversionuid = 1l; @ overridepublic void afterphase) {facescontext context = arg0.getfacescontext (); map Params = context. getex Ternalcontext (). getrequestparametermap (); webcontext = webutil. getwebcontext (context. getviewroot (); webmap map = webcontext. getwebmap (); If (Params. get ("getmapextent ")! = NULL & Params. get ("getmapextent "). equals ("true") {webextent extent = map. getcurrentextent (); double Minx = extent. getminx (); double miny = extent. getminy (); double Maxx = extent. getmaxx (); double Maxy = extent. getmaxy (); document respone = xmlutil. newdocument (); element mapextent = xmlutil. createelement (respone, "mapextent", "", null); xmlutil. createelement (respone, "Maxx", String. valueof (Maxx), mapextent); xmlutil. createelement (respone, "Minx", String. valueof (Minx), mapextent); xmlutil. createelement (respone, "Maxy", String. valueof (Maxy), mapextent); xmlutil. createelement (respone, "miny", String. valueof (miny), mapextent); try {ajaxutil. writeresponse (context, respone);} catch (ioexception e) {// todo auto-generated catch blocke. printstacktrace ();} finally {context. responsecomplete () ;}}@ overridepublic void beforephase (phaseevent arg0) {// todo auto-generated method stub} @ overridepublic phaseid getphaseid () {// todo auto-generated method stubreturn phaseid. apply_request_values ;}}

2. Configure the class in jsf, the configuration file (WebContent/WEB-INF/faces-config.xml) is as follows:

  <lifecycle>    <phase-listener>com.esri.adf.web.templates.MapExtentListener</phase-listener>  </lifecycle>

3. Write a piece of js Code on the front end and send a request to the background. When I mention the js Code, I want to scold the day-killing dojo framework + arcgis js api. The capacity is very large and your IDE will be suspended accidentally. The Code is as follows:

 function requestMapExtent(){       var formId = map.formId;        var url = adf.Utils.getServerUrl(formId);        var params = "getMapExtent=true&" + adf.Utils.buildRequestParams(formId);        adf.Utils.sendAjaxRequest(url, params, true, processMapInfo);      }      function processMapInfo(res){      alert(res.responseText);      }      function  getExtent(){           map=adf.Controls.maps['map1'];           requestMapExtent();      }

HTML entry: <a href = "javascript: void (0)" onclick = "getExtent ()"> current map range </a>. Other code is omitted.

I can't help wondering if ESRI has fallen?

Related Article

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.