import JobInfo from "@arcgis/core/rest/support/JobInfo.js";const JobInfo = await $arcgis.import("@arcgis/core/rest/support/JobInfo.js");- Inheritance:
- JobInfo→
Accessor
- Since
- ArcGIS Maps SDK for JavaScript 4.20
Represents information pertaining to the execution of an asynchronous geoprocessor request on the server.
Constructors
Constructor
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| properties | | |
Properties
progress
- Type
- ProgressorJSON | null | undefined
- Since
- ArcGIS Maps SDK for JavaScript 4.26
Displays the progress of the geoprocessing job.
This value is only present when jobStatus is job-executing and is only updated every five seconds.
- See also
Example
// Submit an asynchronous geoprocessing jobconst jobInfo = await submitJob(url, params);
// Define a callback that will be called periodically. The function will print the// geoprocessor's progress and percentage complete (if a step progressor).const statusCallback = ({ jobStatus, progress }) => { if (jobStatus !== "job-executing") { return; }
const { message, percent } = progress; const status = `Message: ${message} Progress: ${percent ?? "not specified"}` console.log(`Status: ${status}`);};
// Wait for the geoprocessing job to complete and print job progress// to the console every five secondsawait jobInfo.waitForJobCompletion({ interval: 5000, statusCallback }); requestOptions
- Type
- RequestOptions | null | undefined
The options to be used for data requests. These options can also be controlled
through the requestOptions method parameter.
sourceUrl
- Type
- string
ArcGIS Server Rest API endpoint to the resource that receives the geoprocessing request.
Methods
| Method | Signature | Class |
|---|---|---|
fromJSON inherited static | fromJSON(json: any): any | |
cancelJob(requestOptions?: RequestOptions): Promise<JobInfo> | | |
checkJobStatus(requestOptions?: RequestOptions | null): Promise<JobInfo> | | |
destroy(): void | | |
fetchResultData(resultName: string, gpOptions?: GPOptions | null, requestOptions?: RequestOptions | null): Promise<ParameterValue<any>> | | |
fetchResultImage(resultName: string, imageParams: ImageParameters, requestOptions?: RequestOptions): Promise<ParameterValue<any>> | | |
fetchResultMapImageLayer(): Promise<MapImageLayer> | | |
toJSON inherited | toJSON(): any | |
waitForJobCompletion(options?: WaitForJobOptions): Promise<JobInfo> | |
fromJSON
- Signature
-
fromJSON (json: any): any
Creates a new instance of this class and initializes it with values from a JSON object
generated from an ArcGIS product. The object passed into the input json
parameter often comes from a response to a query operation in the REST API or a
toJSON()
method from another ArcGIS product. See the Using fromJSON()
topic in the Guide for details and examples of when and how to use this function.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| json | A JSON representation of the instance in the ArcGIS format. See the ArcGIS REST API documentation for examples of the structure of various input JSON objects. | |
- Returns
- any
Returns a new instance of this class.
cancelJob
- Signature
-
cancelJob (requestOptions?: RequestOptions): Promise<JobInfo>
Cancels an asynchronous geoprocessing job. The returned promise will only resolve when the geoprocessing job has canceled on the server.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| requestOptions | Additional options to be used for the data request (will override requestOptions defined during construction). | |
Example
// Cancel an ongoing geoprocessing job when the user clicks a "cancel" button.document.getElementById("cancelButton").addEventListener("click", () => { jobInfo.cancelJob().then(() => { console.log("Job cancelled successfully."); }).catch(() => { console.log("Problem occurred which cancelling the geoproccessing job"); });}); destroy
- Signature
-
destroy (): void
Stop monitoring this job for status updates.
// Stop monitoring this job for status updates.jobInfo.destroy();- See also
- Returns
- void
fetchResultData
- Signature
-
fetchResultData (resultName: string, gpOptions?: GPOptions | null, requestOptions?: RequestOptions | null): Promise<ParameterValue<any>>
Sends a request to the GP Task to get the task result identified by resultName.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| resultName | The name of the result parameter as defined in Services Directory. | | |
| gpOptions | Input options for the geoprocessing service return values. | | |
| requestOptions | Additional options to be used for the data request (will override requestOptions defined during construction). | |
- Returns
- Promise<ParameterValue<any>>
When resolved, returns an object with a property named
resultof type ParameterValue, which contains the result parameters and the task execution messages.
fetchResultImage
- Signature
-
fetchResultImage (resultName: string, imageParams: ImageParameters, requestOptions?: RequestOptions): Promise<ParameterValue<any>>
Sends a request to the GP Task to get the task result identified by jobId and resultName as an image.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| resultName | The name of the result parameter as defined in the Services Directory. | | |
| imageParams | Specifies the properties of the result image. | | |
| requestOptions | Additional options to be used for the data request (will override requestOptions defined during construction). | |
- Returns
- Promise<ParameterValue<any>>
When resolved, returns an Object with a
mapImageproperty of type MapImage
fetchResultMapImageLayer
- Signature
-
fetchResultMapImageLayer (): Promise<MapImageLayer>
Get the task result identified by jobId as an MapImageLayer.
- Returns
- Promise<MapImageLayer>
A promise resolving to an instance of MapImageLayer.
Example
// Get the resulting map image layer from a completed geoprocessing job.jobInfo.fetchResultMapImageLayer(jobInfo.jobId)).then(function(layer){ view.map.add(layer);}); toJSON
- Signature
-
toJSON (): any
Converts an instance of this class to its ArcGIS portal JSON representation. See the Using fromJSON() guide topic for more information.
- Returns
- any
The ArcGIS portal JSON representation of an instance of this class.
waitForJobCompletion
- Signature
-
waitForJobCompletion (options?: WaitForJobOptions): Promise<JobInfo>
Resolves when an asynchronous job has completed. Optionally job progress can be monitored.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| options | Options. See properties below for object specifications. | |
Example
// Submit an asynchronous geoprocessing job. Display the remote job status every 1.5 seconds.// When the job has completed, the output is a MapImageLayer.const startDate = "1998-01-01 00:00:00";const endDate = "1998-05-31 00:00:00";const params = { query: "(Date >= date '" + startDate + "' and Date <= date '" + endDate + "')"};
const url = "https://sampleserver6.arcgisonline.com/arcgis/rest/services/911CallsHotspot/GPServer/911%20Calls%20Hotspot";
submitJob(url, params).then((jobInfo) => { const jobid = jobInfo.jobId; console.log("ArcGIS Server job ID: ", jobid);
const options = { interval: 1500, statusCallback: (j) => { console.log("Job Status: ", j.jobStatus); } };
jobInfo.waitForJobCompletion(options).then(() => { const layer = jobInfo.fetchResultMapImageLayer.then(function(layer){ map.add(layer); }); });});