ArcGIS Server Development Series (6)-custom tasks

Source: Internet
Author: User
Author: flyingis

This document is strictly forbidden to be reproduced without authorization or used for commercial purposes. If necessary, please contact the author in advance:Dev. VIP # gmail.com

Tasks are composed of a group of associated components and actions and can display the final results. For example, queryattributetask queries the spatial data attributes and returns the results to the results control, we can use it during development. the existing tasks controls of the. NET web ADF can also be customized to build some common GIS functions. It is easier to use the existing tasks control. All tasks are managed by TASKMANAGER. You can edit taskmanager to find all tasks in the current application. Therefore, A basic page contains only TaskManager, taskresults, and one or more task controls to implement the task function. In actual development, we need to customize various tasks, including functions and appearances. Now we will design a custom task together.

Before the project starts, let's take a look at the task runtime workflow, which describes the working mechanism of the entire task.

Objectives:
Customizes a function to query attributes of a specified layer, returns the queried map information, encapsulates this function into a task, and adds it to TASKMANAGER.

Preparations:
1. Familiar with the use of existing controls in Web ADF tasks
2. Understand task runtime Workflow
3. Understand ESRI. ArcGIS. ADF. Web. UI. webcontrols. itask Interface
4. Understand ASP. NET 2.0 callback framework
5. Change the mapresourcemanager attribute and add a resource: mapresourceitem0. The type is ArcGIS Server Internet.

Development is divided into two parts: one is function implementation, and the other is to encapsulate tasks and publish the entire web application.

First, create a project defquery for the classlibrary template. The generated defquery class implements the abstract class floatingpaneltask. The latter inherits the floatingpanel and implements the itask interface. Therefore, defquery must implement the abstract method in floatingpaneltask. The coding process must be performed according to the running process of the task.

1. Event-triggered task

There are multiple ways to trigger an event, such as clicking button or textbox Press enter. After an event is triggered, you need to call the executetask function in display_task.js. Generally, executetask ('args = '+ document. getelementbyid ('taskmanager1 _ defquerydetailsellay '). value + ':' + document. getelementbyid ('taskmanager1 _ defquerymediatextbox '). value,
"Webform_docallback ('taskmanager1 $ defquery1 ', argument, processcallbackresult, context, postbackerror, true )");

It contains two parts: one is the input parameter and the other is webform_docallback. The latter can be used to view ASP. net2.0 asynchronous call related information. In display_task.js, The executetask function completes two tasks, assigns a job ID to track asynchronous requests, and initializes a callback and triggers the indicator in the taskresults control (indicating that the task program is running ).

2. Call the startjob Function

Startjob provides a series of parameters to send user requests through key-value pairs: eventarg = starttaskactivityindicator & taskjobid = 1 & ARGs = 0: TYPE = 'st'

Then pass in the raisecallbackevent method through the _ callbackarg parameter.

3. server-side Processing

The request from the client is sent to the server for processing in the getcallbackresult method. There are two steps: starttaskactivityindicator, which indicates that the task is being executed in the taskresults control and executetask, that is, to process the real core business: Public override string getcallbackresult ()
{
Namevaluecollection keyvalcoll = callbackutility. parsestringintonamevaluecollection (_ callbackarg );
If (keyvalcoll ["eventarg"] = "executetask ")
{
String sinargs = keyvalcoll ["ARGs"];
String delim = ":";
Char [] delchar = delim. tochararray ();
String [] ARGs = sinargs. Split (delchar );
Object [] inputs = new object [2];
Inputs [0] = ARGs [0];
Inputs [1] = ARGs [1];
Input = inputs;
}
Else if (keyvalcoll ["eventarg"] = "starttaskactivityindicator ")
{
}
Else if (keyvalcoll ["eventarg"] = "hidden ")
{
}
Return base. getcallbackresult ();
}

When the parameter is "executetask", the executetask Rewriting Method is executed, which can process the business logic and save the result as a results, which can be simpletaskresult, dataset, or taskresultnode.

4. displayresults Display Results

After the task is processed, it will be handed over to displayresults to display the result. Check the displayresults code: protected virtual void displayresults (string jobid, object taskinput, object taskresults)
{
Itaskresultscontainer resultscontainer = NULL;
For (INT I = 0; I <taskresultscontainers. Count; I ++)
{
Resultscontainer = utility. findcontrol (taskresultscontainers [I]. Name, page) as itaskresultscontainer;
If (resultscontainer! = NULL)
{
Resultscontainer. displayresults (this, jobid, taskinput, taskresults );
Callbackresults. copyfrom (resultscontainer. callbackresults );
}
}
}

5. processcallbackresult

Finally, all the callback results are returned to the callback Response Function -- processcallbackresult, which is used to handle the callback response of the client web ADF control and trigger a series of subsequent actions to update the client display, this completes the entire task execution.

Build the entire project and generate the defquery DLL file. Use the template to create a new ArcGIS Server application. Right-click the toolbar and select the previously generated DLL, in this case, you can use defquery like queryattributetask and other original tasks. Add it to taskmanager and publish the entire web application. This completes the custom task. You can see the effect, A simple query task is performed to return the queried map on the map based on the attribute query conditions written by the user.

Before task Query

After task Query

Further improve the application:

1. The above custom task UI is based on floatingpanel. We can change its actual style, such as transparency, color, layout, and so on.
2. You can save the displayed result as a graphic layer and retain the original layer.
3. Check the space information based on the attribute. When querying the result, map the window where the result is located.

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.