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
| esri.tasks.QueryTask(url) |
Creates a new QueryTask object used to execute a query on the layer resource identified by the url. |
Properties
| url |
String
|
URL to the ArcGIS Server REST resource that represents a map service layer. To obtain the URL, use Services Directory. |
Methods
| 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
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
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.
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);
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)
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)
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. |
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)
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
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
Fires when an error occurs when executing the task. (As of v1.3)
Arguments:
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.
|
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.
|