Ajax in the ArcGIS Server. Net ADF

Source: Internet
Author: User

Ajax in the ArcGIS Server. Net ADF (i)

For developers who do not have a good. NET programming base, arcobjects development experience, the application of ArcGIS server development is more laborious. The simplest and quickest way to learn is to get a clear idea of the template programs that ESRI has provided for us, and don't look at this simple template program, which contains all the techniques you need to develop ArcGIS server applications. Ajax technology is one of them. The following things can be found in the template program application.


We're not looking into the AJAX complex technology itself, we need just how Ajax technology works in our ArcGIS server development process, and how it is used specifically.

definition of Ajax
AJAX is the acronym for Asynchronous JavaScript and XML, which is a new combination of old technology, because JavaScript and XML are not new technologies, but AJAX applications bring a lot of new changes to Web applications.

implementing Ajax in. NET, the rationale
In. NET, there is a function that invokes the server-side-specified function using the client's script. This is the way to achieve no callback refresh for pages in. Net.

public string GetCallbackEventReference (Control control,string argument,string clientcallback,string context)
Parameters:
Control handles server control for client callbacks. The control must implement the ICallbackEventHandler interface and provide a raisecallbackevent method.
Argument passes a parameter to the server-side RaiseCallbackEvent method from the client script.
Clientcallback the name of a client event handler that receives the results returned by the server-side event.
Client script information at the client before the context initiates the callback. The result of the script is passed back to the client event handler.
Returns the name of the client function that invoked the client callback.
Returning a response function on the server side is not selected. Must be a server-side raisecallbackevent, so when you have multiple places in a page that require callbacks, you need to use parameters to differentiate them.
The client's response function uses javascripts to write, there is no problem, here the returned results are refreshed.
The server-side implementation code is placed in the raisecallbackevent, and there is no problem.
Another question is where getcallbackeventreference this function is,
One position is placed in the Page_Load,
M_copyrightcallback = Page.ClientScript.GetCallbackEventReference (Page, "argument", "Processcallbackresult", " Context ", true);
The other is directly on the client side of the event.

<%=clientscript.getcallbackeventreference (This, "Imagechange", "ShowServerTime2", null)%>


The following diagram is in the GetServerTime client-side event script, which is a good illustration of this whole process, and from this process, we do not see getcallbackeventreference this function, but webform_ The DoCallback function, as long as you understand that Webform_docallback is a more low-level function to implement the AJAX callback.
Understand the fundamentals of Ajax to better understand the application of Ajax in ArcGIS Server.NET.


Ajax in the ArcGIS Server. Net ADF (II)

Ajax application in ArcGIS Server also follows the basic steps, but why does it seem to be confusing when used? Because the. NET ADF provides a more unified framework, it wraps some of the most basic functions and provides a unified portal and schema based on its own pattern. But just a few more steps will see the familiar Ajax steps. This may make you a bit confused when you start using it, but it's the same kind of entry and model that makes our job easier.

The ArcGIS Server. Net ADF provides a variety of controls in which complex features are concentrated, and their refreshes (such as zooming in and out of a map, moving, and so on) are not simply a few javascripts that can be accomplished. That's why it provides a unified portal and schema, and the Web ADF has helped you write a lot of response javascripts code. You only need to follow the appropriate format to return the refresh request string to the client's corresponding function, the ADF provides a rich variety of control refresh JavaScripts can help you complete the corresponding refresh operation. But still, you need to know the whole process.
1 Use Ajax in the tool, this is the most basic mode
One of the most common patterns of unification is the use of Ajax in tools.
Custom tools Everyone knows how to implement, there are a lot of documentation, we will be in the custom tool Severaction class to write a lot of features, and then need to return the results to the client, then this process will be used Ajax, the entire process of Ajax to achieve the process see figure 7-2
Please look closely at the drawings.

1 after the page load, the customer will do operations on the map, such as drawing a rectangular box, then the program to perform client operations, such as Dragrectangle, it will fire the JavaScripts directory under the Mapmousedown function, this function will begin to draw rectangle , in this function, the postback function is executed.
The Webform_docallback function is executed in the 2 postback function, which sends the corresponding request back to the server side,

Webform_docallback (' Map1 ', argument,processcallbackresult,context,postbackerror,false)
3 to the server side, the first execution is the RaiseCallbackEvent function of the map control,
4 will then invoke the Serveraction function of the user's own written tool and return the corresponding return string to the client's processcallbackresult. function, the string is similar to the following:
map:::map1:::changelevel:::-1:::1:::1:::0:::0:::0:::0:::709:::389:::-1:::0:::0
5 This process is not finished here, in fact, because this time the refresh operation prompts have not been completed, the Processcallbackresult function will have to perform a lot of javascripts functions, these functions will also be nested with Ajax callback. But this process is the most basic process. Nested AJAX calls only repeat these steps, and the script function of the client invoked is slightly different from the server's execution function.

Many of the steps above do not require us to intervene, so we only need to care about what we want to do, we have to do is the function of serveraction function, if the function of serveraction is only update server-side content, it is simple, only need to use AO components can be executed, but if you need to refresh the client's content after serveraction, this time you need to pay attention, do not forget to take the corresponding string to the original set up a good client script. Otherwise, even if the server's content has been updated, the client is not responding.
Whether the client wants to refresh the ArcGIS server's control or another control, the string to be returned is a map. The string in the Callbackresults. So you need to add everything you want to update to the client to the map. Callbackresults inside, or whatever you do on the server side of the client will not see the results. Many people will not forget to work on the service side, finish what should be done, but it is easy to forget to upload the corresponding refresh string to the client. Because the application of B/S and C/s application, the process is more complicated.
So one of the most important questions here is what you need to add to the map. Callbackresults in the middle of the trip. The answer is a string.

So first let's look at the parsing function of the string, and then look at the rules that construct the string.
1 The response function of the string returned to the client via Ajax
To refresh the WebControls in the ADF at the client using AJAX technology in the serveraction of the tool, the response function of the first client returning the string is Processcallresult. The function is c:/inetpub/wwwroot/aspnet_client/esri/webadf/javascript in the display_dotnetadf.js. Only when we understand how this function parses strings can we know how we should give this string.
First, refresh the controls provided by ArcGIS Server,
Let's take one example, zoom in on the Map control, and finally return to the Processcallresult string:
"Map:::map1:::changelevel:::-1:::1:::1:::0:::0:::0:::0:::709:::389:::-1:::0:::0^ ^^ Map:::Map1:::cleargrid"
^^ ^ is an action split symbol::: is a parametric split symbol,
Parsing code in the Processcallresult function
var ov2 = null;
Split independent operations
var pairs = response.split ("^^ ^");
var actions;
var o;
var action;
var C;
var C;
Var resp;
var validresponse = false;
for (Var i=0;i<pairs.length;i++)
{
To divide the parameters and analyze them.
actions = Pairs

. Split (":::");
Responseitem = pairs;
if (Responseitem==null | | responseitem.length==0)
Continue
ControlType = Actions[0].tolowercase ();
ControlID = actions[1];
Action = Actions[2].tolowercase ();
Switch (controltype) {
Case "Map":
MAP2 = Maps[controlid];
if (action== "Changelevel")
{..........................}
.......................................
}
If you refresh the other ASP.net controls, the situation is different. The Processcallbackresult function has the following parsing code, and overall, refreshing the other asp.net controls directly assigns the new HTML to the corresponding control. If the return is a string of javascrpts words, is to let it run directly on it.


Ajax for the ArcGIS Server. Net Web ADF (II) continued

2)To construct a rule that returns a string
Of course, in addition to studying the Processcallbackresult function to determine how we should construct the returned string, ESRI also gives the appropriate instructions, as shown in the following table.
If you refresh the contents of the WebControls provided by the ADF, the string is built fairly simply and is automatically generated by WebControl, But if you refresh the contents of the normal ASP.net control, then you need to manually construct the return string as required, if the return of JavaScript is the same. Here are some of the following types of parameters that are required if the returned parameter is used to refresh the normal asp.net control or is javascripts:

"Content"

Used to set the outerHTML property of the HTML element. The HTML element on the client defined by the Callbackresult World抯 ControlType and ControlID are completely replaced by the HTM L content provided as a parameter in the object array (object[).

"Innercontent"

Used to set the InnerHTML property of the HTML element. The content inside the HTML element on the client defined by the Callbackresult World抯 ControlType and ControlID are completely Replaced by the HTML content provided as a parameter in the object array (object[).

"Image"

Used to set the Src property is an image element. The source of the image element on the client defined by the Callbackresult World抯 ControlType and ControlID are changed to the The URL string provided as a parameter in the object array (object[).

"JavaScript"

Used to execute JavaScript on the client. The Callbackresult World抯 ControlType and ControlID and set to null. The JavaScript code is provided as a parameter in the object Array (object[)).


Conent returns the outerHTML property that is set to the HTML control.
Innercontent is the innerHTML property that is returned to the HTML control.
Javascrpt is returning a javascripts.
As you can see from the construction string above, the string returned to the client can be used to refresh a control or to directly return a piece of javascript so that we can be flexible enough to control some of the client's interfaces. The construction of content or innercontent is usually generated directly through the control, and Javascriptes is usually constructed directly in the function.
Here are two examples that are often involved in the specific use process, which is the code example of the Ajax refresh to be implemented in the custom tool.

1 Refresh the map while also refreshing the other ArcGIS server's Web controls,
Here's the code to refresh the TOC control.

ESRI. ArcGIS.ADF.Web.UI.WebControls.Toc
Toc1 = (ESRI. ARCGIS.ADF.WEB.UI.WEBCONTROLS.TOC) map. Page.findcontrol ("Toc1");
Toc1. Nodes.clear ();
Toc1. Refresh ();
String AAA = Toc1. Callbackresults.tostring ();
Callbackresult tocstring = new Callbackresult ("TOC", "Toc1", "content", AAA);
Map. Callbackresults.add (tocstring);

2 Refresh the map while also refreshing the other ASP.net control, the following is a sample code, refresh is a div control

DataTableCollection DTC = DataSet. Tables;
String returnstring = String. Empty;
foreach (DataTable dt in DTC)
{
if (dt. Rows.Count = 0)
Continue;
GridView GD = new GridView ();
Gd. TOOLTIP = dt. TableName;
Gd. Caption = dt. TableName;
Gd. DataSource = DT;
Gd. DataBind ();
Gd. Visible = true;


Gd. BorderWidth = 10;


using (System.IO.StringWriter SW = new System.IO.StringWriter ())
{
HtmlTextWriter HTW = new HtmlTextWriter (SW);
Gd. RenderControl (HTW);
Htw. Flush ();
returnstring = returnstring + SW. ToString ();


}
}
Callbackresult CR = new

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.