Class: QueryTask

Description

Executes a query operation on a layer resource of a map service exposed by the ArcGIS Server REST API.

Samples

Search for samples that use this class.  

Class hierarchy

esri.tasks.QueryTask

Constructor

Constructor Description
esri.tasks.QueryTask(url) Creates a new QueryTask object used to execute a query on the layer resource identified by the url.

Properties

Property Type Description
url String URL to the ArcGIS Server REST resource that represents a map service layer. To obtain the URL, use Services Directory.

Methods

Method Return Value Description
execute(parameters, callback?, errback?) dojo.Deferred Executes a Query against an ArcGIS Server map layer. The result is returned as a FeatureSet. If the query is successful, the user-specified callback function is invoked with the result. A FeatureSet contains an array of Graphic features, which can be added to the map using Map.graphics.add(). This array will not be populated if no results are found.
executeForCount(query, callback?, errback?) dojo.Deferred Get a count of the number of features that satisfy the input query. Valid only for layers published using ArcGIS Server 10 SP1 or greater. Layers published with earlier versions of ArcGIS Server return an error to the error callback.
executeForIds(parameters, callback?, errback?) dojo.Deferred Executes a Query against an ArcGIS Server map layer. The result is returned as a FeatureSet. If the query is successful, the user-specified callback function is invoked with the result. A FeatureSet contains an array of Graphic features, which can be added to the map using Map.graphics.add(). This array will not be populated if no results are found.
executeRelationshipQuery(parameters, callback?, errback?) dojo.Deferred Executes a Query against an ArcGIS Server map layer. The result is returned as a FeatureSet. If the query is successful, the user-specified callback function is invoked with the result. A FeatureSet contains an array of Graphic features, which can be added to the map using Map.graphics.add(). This array will not be populated if no results are found.

Events

Event Description
onComplete(featureSet) Fires when the query operation is complete.
onError(error) Fires when an error occurs when executing the task.
onExecuteForCountComplete(count) Fires when the query for the count is complete. This event is only available for layers published using ArcGIS Server 10 SP1 or later.
onExecuteForIdsComplete(featureIds) Fires when the query on IDs is complete.
onExecuteRelationshipQueryComplete(relatedFeatureSets) Fires when the executeRelationshipQuery is complete
Constructor Detail

esri.tasks.QueryTask(url)

Creates a new QueryTask object used to execute a query on the layer resource identified by the url.
Parameters:
<String> url Required URL to the ArcGIS Server REST resource that represents a layer in a service. An example is http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Portland/Portland_ESRI_LandBase_AGO/MapServer/1. For more information on constructing a URL, see The Services Directory and the REST API.
Code snippets:
var queryTask = new esri.tasks.QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/0");
Properties Detail

<String> url

URL to the ArcGIS Server REST resource that represents a map service layer. To obtain the URL, use Services Directory.
Methods Detail

execute(parameters, callback?, errback?)

Executes a Query against an ArcGIS Server map layer. The result is returned as a FeatureSet. If the query is successful, the user-specified callback function is invoked with the result. A FeatureSet contains an array of Graphic features, which can be added to the map using Map.graphics.add(). This array will not be populated if no results are found.

The return object of dojo.Deferred was added at v1.4.
Return value: dojo.Deferred
Input Parameters:
<Query> parameters Required Specifies the attributes and spatial filter of the query.
<Function> callback Optional The argument passed to the callback function, which is a FeatureSet.
<Function> errback Optional An error object is returned if an error occurs on the Server during task execution. (As of v1.3)
Code snippets:
var query = new esri.tasks.Query();
query.where = "STATE_NAME = 'Washington'";
query.outSpatialReference = {wkid:102100}; 
query.returnGeometry = true;
query.outFields = ["CITY_NAME"];
queryTask.execute(query, addPointsToMap);

See also:
onComplete   onError  

executeForCount(query, callback?, errback?)

Get a count of the number of features that satisfy the input query. Valid only for layers published using ArcGIS Server 10 SP1 or greater. Layers published with earlier versions of ArcGIS Server return an error to the error callback. (As of v2.1)
Return value: dojo.Deferred
Input Parameters:
<Query> query Required Specify the input query object.
<Function> callback Optional The argument passed to the callback function, which is a FeatureSet.
<Function> errback Optional An error object is returned if an error occurs on the Server during task execution. (As of v1.3)
Code snippets:
var query = new esri.tasks.Query();
query.where = "POP90_SQMI < 100";
queryTask.executeForCount(query,function(count){
  dojo.byId("info").innerHTML = count + " features matched the input query";
},function(error){
  console.log(error);
});

executeForIds(parameters, callback?, errback?)

Executes a Query against an ArcGIS Server map layer. The result is returned as a FeatureSet. If the query is successful, the user-specified callback function is invoked with the result. A FeatureSet contains an array of Graphic features, which can be added to the map using Map.graphics.add(). This array will not be populated if no results are found.

The return object of dojo.Deferred was added at v1.4. (As of v2.0)
Return value: dojo.Deferred
Input Parameters:
<Query> parameters Required Specifies the attributes and spatial filter of the query.
<Function> callback Optional The argument passed to the callback function, which is a FeatureSet.
<Function> errback Optional An error object is returned if an error occurs on the Server during task execution.
See also:
onExecuteForIdsComplete   onError  

executeRelationshipQuery(parameters, callback?, errback?)

Executes a Query against an ArcGIS Server map layer. The result is returned as a FeatureSet. If the query is successful, the user-specified callback function is invoked with the result. A FeatureSet contains an array of Graphic features, which can be added to the map using Map.graphics.add(). This array will not be populated if no results are found.

The return object of dojo.Deferred was added at v1.4. (As of v2.0)
Return value: dojo.Deferred
Input Parameters:
<Query> parameters Required Specifies the attributes and spatial filter of the query.
<Function> callback Optional The argument passed to the callback function, which is a FeatureSet.
<Function> errback Optional An error object is returned if an error occurs on the Server during task execution.

Events Detail

onComplete(featureSet)

Fires when the query operation is complete.
Arguments:
<FeatureSet> featureSet FeatureSet which satisfied the query.
Code snippets:
function queryComplete(featureSet) {
  var features = featureSet.features;
  for (var i=0, il=features.length; i
   
See also:
execute  

onError(error)

Fires when an error occurs when executing the task. (As of v1.3)
Arguments:
<Error> error ArcGIS Server error message returned in a JavaScript error object.

onExecuteForCountComplete(count)

Fires when the query for the count is complete. This event is only available for layers published using ArcGIS Server 10 SP1 or later. (As of v2.1)
Arguments:
<Number> count The number of features that satisfy the input query.
Code snippets:
       
dojo.connect(queryTask,'onExecuteForCountComplete',function(count){
  dojo.byId("info").innerHTML = count + " features matched the input query";
});

onExecuteForIdsComplete(featureIds)

Fires when the query on IDs is complete. (As of v2.0)
Arguments:
<Number[]> featureIds Array of Feature IDs that satisfy the query.
See also:
executeForIds  

onExecuteRelationshipQueryComplete(relatedFeatureSets)

Fires when the executeRelationshipQuery is complete (As of v2.0)
Arguments:
<Object> relatedFeatureSets Object containing a FeatureSet for each related feature. Each feature is accessible by its object id.
See also:
executeRelationshipQuery