| Package | com.esri.ags.tasks |
| Class | public class QueryTask |
| Inheritance | QueryTask BaseTask flash.events.EventDispatcher |
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.
See also
| Property | Defined by | ||
|---|---|---|---|
![]() | concurrency : String = "multiple"
Value that indicates how to handle multiple calls to the same task.
| BaseTask | |
![]() | disableClientCaching : 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 | ||
![]() | proxyURL : String
The URL to proxy the request through.
| BaseTask | |
![]() | requestTimeout : Number = -1
The request timeout in seconds.
| BaseTask | |
![]() | showBusyCursor : Boolean = false
If true, a busy cursor is displayed while a service is executing.
| BaseTask | |
![]() | token : String
Token for accessing a secure task.
| BaseTask | |
![]() | url : String
URL of the task.
| BaseTask | |
| Method | Defined by | ||
|---|---|---|---|
|
QueryTask(url:String = null)
Creates a new QueryTask object used to execute a query on the layer resource identified by the URL.
| QueryTask | ||
|
Executes a query against an ArcGIS Server map layer.
| QueryTask | ||
| Event | Summary | Defined by | ||
|---|---|---|---|---|
| Dispatched when a QueryTask successfully completes. | QueryTask | |||
| Dispatched when a QueryTask fails. | QueryTask | |||
| executeLastResult | property |
public var executeLastResult:FeatureSetThe last result of the execute function.
This property can be used as the source for data binding.
| 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.
Parametersurl:String (default = null) — [optional] URL to the ArcGIS Server REST resource that represents a map layer.
|
| execute | () | method |
public function execute(query:Query, responder:IResponder = null):AsyncTokenExecutes 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.
Parametersquery:Query — Specifies the attributes and spatial filter of the query.
|
|
responder:IResponder (default = null) — The responder to call on result or fault.
|
AsyncToken |
| executeComplete | event |
com.esri.ags.events.QueryEvent
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.
| fault | event |
<?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>