Packagecom.esri.ags.tasks
Classpublic class QueryTask
InheritanceQueryTask Inheritance BaseTask Inheritance flash.events.EventDispatcher

Executes a query operation on a layer resource of a map service exposed by the ArcGIS Server REST API (available in ArcGIS Server 9.3 and above).

Set the url to the ArcGIS Server REST resource that represents a QueryTask, e.g. http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Portland/Portland_ESRI_LandBase_AGO/MapServer/1. Note the number "1" at the end of the URL which indicates which specific layer you want to query. For more information on constructing a URL, see Using the ArcGIS Services Directory.

View the examples.

See also

Concepts - Using Query
Query
FeatureSet
com.esri.ags.events.QueryEvent
Live sample - Show Query result on Map
Query Layer (Operation) in REST documentation


Public Properties
 PropertyDefined by
 Inheritedconcurrency : String = "multiple"
Value that indicates how to handle multiple calls to the same task.
BaseTask
 InheriteddisableClientCaching : Boolean
If true, adds a timestamp parameter ("_ts") to the REST request to prevent the request from being loaded from the browser's cache.
BaseTask
  executeLastResult : FeatureSet
The last result of the execute function.
QueryTask
 InheritedproxyURL : String
The URL to proxy the request through.
BaseTask
 InheritedrequestTimeout : Number = -1
The request timeout in seconds.
BaseTask
 InheritedshowBusyCursor : Boolean = false
If true, a busy cursor is displayed while a service is executing.
BaseTask
 Inheritedtoken : String
Token for accessing a secure task.
BaseTask
 Inheritedurl : String
URL of the task.
BaseTask
Public Methods
 MethodDefined by
  
QueryTask(url:String = null)
Creates a new QueryTask object used to execute a query on the layer resource identified by the URL.
QueryTask
  
execute(query:Query, responder:IResponder = null):AsyncToken
Executes a query against an ArcGIS Server map layer.
QueryTask
Events
 EventSummaryDefined by
   Dispatched when a QueryTask successfully completes.QueryTask
   Dispatched when a QueryTask fails.QueryTask
Property detail
executeLastResultproperty
public var executeLastResult:FeatureSet

The last result of the execute function.

This property can be used as the source for data binding.

Constructor detail
QueryTask()constructor
public function QueryTask(url:String = null)

Creates a new QueryTask object used to execute a query on the layer resource identified by the URL.

Parameters
url:String (default = null) — [optional] URL to the ArcGIS Server REST resource that represents a map layer.
Method detail
execute()method
public function execute(query:Query, responder:IResponder = null):AsyncToken

Executes a query against an ArcGIS Server map layer. The result is returned as a FeatureSet. If the query is successful, the user-specified responder 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.

Parameters
query:Query — Specifies the attributes and spatial filter of the query.
 
responder:IResponder (default = null) — The responder to call on result or fault.

Returns
AsyncToken
Event detail
executeCompleteevent 
Event object type: com.esri.ags.events.QueryEvent
QueryEvent.type property = com.esri.ags.events.QueryEvent.EXECUTE_COMPLETE

Dispatched when a QueryTask successfully completes.

Defines the value of the type property of an executeComplete event object.

faultevent  
Event object type: mx.rpc.events.FaultEvent

Dispatched when a QueryTask fails.

Examples
QueryTaskOnMap
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
    xmlns:mx="http://www.adobe.com/2006/mxml"
    xmlns:esri="http://www.esri.com/2008/ags"
    pageTitle="Query Task">

    <mx:Script>
        <![CDATA[
            import com.esri.ags.Graphic;
            import com.esri.ags.tasks.FeatureSet;
            import mx.controls.Alert;
            import mx.rpc.AsyncResponder;

            private function doQuery() : void
            {
                queryTask.execute( query, new AsyncResponder( onResult, onFault ));
                function onResult( featureSet : FeatureSet, token : Object = null ) : void
                {
                    var displayFieldName : String = featureSet.displayFieldName;
                    for each ( var myGraphic : Graphic in featureSet.features )
                    {
                        // ToolTip
                        myGraphic.toolTip = "The 2007 population of "
                            + myGraphic.attributes[displayFieldName] + " was "
                            + myNumberFormatter.format(myGraphic.attributes.POP2007)
                            + "\nMedian Age: " + myGraphic.attributes.MED_AGE + ".";
                        // show on map
                        myGraphicsLayer.add( myGraphic );
                    }
                }
                function onFault( info : Object, token : Object = null ) : void
                {
                    Alert.show( info.toString() );
                }
            }
        ]]>
    </mx:Script>

    <mx:NumberFormatter id="myNumberFormatter" useThousandsSeparator="true"/>

    <!-- Layer with US States -->
    <esri:QueryTask id="queryTask"
        url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5" />

    <esri:Query id="query" text="{qText.text}" returnGeometry="true">
        <esri:outFields>
            <mx:String>MED_AGE</mx:String>
            <mx:String>POP2007</mx:String>
        </esri:outFields>
    </esri:Query>

    <mx:Panel title="Query a layer (search for a state)" layout="horizontal"
        backgroundColor="0xB2BFC6" borderStyle="solid">
        <mx:TextInput width="100%" id="qText" enter="doQuery()" text="California"/>
        <mx:Button label="Do Query" click="doQuery()"/>
    </mx:Panel>

    <esri:Map>
        <esri:extent>
            <esri:Extent xmin="-170" ymin="15" xmax="-65" ymax="75">
                <esri:SpatialReference wkid="4326"/>
            </esri:Extent>
        </esri:extent>
        <esri:ArcGISTiledMapServiceLayer
            url="http://server.arcgisonline.com/ArcGIS/rest/services/NPS_Physical_World_2D/MapServer"/>
        <esri:GraphicsLayer id="myGraphicsLayer"/>
    </esri:Map>

</mx:Application>