The Query Task finds features in a single map layer of an ArcGIS Server map service exposed as a REST resource.
Features are found that satisfy the criteria in the Query parameters object
included with the arguments when executing the task. The result of this operation is a
FeatureSet,
which provides information about query results including the values for the fields requested by the user.
By default, the geometry of each result is also returned in the FeatureSet as an array of
GraphicFeatures.
Namespace:
ESRI.ArcGIS.VE(in ArcGISVE.exe)
Syntax
| JScript |
|---|
class QueryTask |
Remarks
The QueryTask is one of several tasks that may be used to find features.
See "About tasks" in the Getting Started section for a guide to available tasks. See the walk-through
Querying features by distance or spatial relationship for a full example of using the QueryTask.
To use the QueryTask, create an instance of the class, as well as an instance of Query, which will hold the parameters for the task. Set the properties for the Query, then Execute the task, passing the return function name. Create the callback function with the FeatureSet as its input parameter. In the callback function, use FeatureSet.ToVEShapeLayer to create a VEShapeLayer to add to the map. Or use FeatureSet.Features to work with the individual feature geometries and attributes. The code snippet below shows the basic approach. This code assumes a map already created as a VEMap.
Copy
To use the QueryTask, create an instance of the class, as well as an instance of Query, which will hold the parameters for the task. Set the properties for the Query, then Execute the task, passing the return function name. Create the callback function with the FeatureSet as its input parameter. In the callback function, use FeatureSet.ToVEShapeLayer to create a VEShapeLayer to add to the map. Or use FeatureSet.Features to work with the individual feature geometries and attributes. The code snippet below shows the basic approach. This code assumes a map already created as a VEMap.
function ExecuteTask() { var qTask = new ESRI.ArcGIS.VE.QueryTask(); qTask.Url = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/3"; var qParams = new ESRI.ArcGIS.VE.Query(); qParams.Where = "POP2000 > 1000000"; qParams.OutFields = ["NAME","STATE_NAME","POP2000"]; qTask.Execute(qParams, addShapes); } function addShapes(featureSetResults) { if (featureSetResults.Error != null) alert("Error: " + featureSetResults.Error.message); else { var shapeLayer = featureSetResults.ToVEShapeLayer(); map.AddShapeLayer(shapeLayer); } }
