FeatureLayer查询的方式:给definitionExpression指定查询条件,
Query的字段:text对应的是MapServer的图层的显示字段。
returnGeometry:是否返回几何图形,若为false,则不返回图形,只返回属性信息。
outFields:是图层对应表里字段的数组。用于指定返回哪些指定的字段。
Query查询主要有三种方式:1,用text和信息进行匹配,(比较简单高效,但是查询功能比较单一)
2,给where指定查询的条件,(查询功能比较强,适合用字段进行的查询)
3,给geometry指定查询的几个图形范围,(适合根据一个几何图形来查询)
返回结果:1,属性:queryTask.executeLastResult.attributes 属性信息数组
queryTask.executeLastResult.features graphic数组
2,方法: queryTask.execute(query, new AsyncResponder(onResult, onFault));
function onResult(featureSet:FeatureSet, token:Object = null):void
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:esri="http://www.esri.com/2008/ags"
pageTitle="Query, then zoom to results"
styleName="plain">
<s:layout>
<s:VerticalLayout/>
</s:layout>
<fx:Script>
<![CDATA[
import com.esri.ags.FeatureSet;
import com.esri.ags.utils.GraphicUtil;
import mx.controls.Alert;
import mx.rpc.AsyncResponder;
private function doQuery():void
{
// clear the graphics layer
myGraphicsLayer.clear();
queryTask.execute(query, new AsyncResponder(onResult, onFault));
function onResult(featureSet:FeatureSet, token:Object = null):void
{
if (featureSet.features.length == 0)
{
Alert.show("No States found. Please try again.");
}
else
{
var graphicsExtent:Extent = GraphicUtil.getGraphicsExtent(featureSet.features);
if (graphicsExtent)
{
map.extent = graphicsExtent;
}
}
}
function onFault(info:Object, token:Object = null):void
{
Alert.show(info.toString());
}
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Symbol for Query Result as Polygon -->
<esri:SimpleFillSymbol id="sfs"
alpha="0.7"
color="0xFF0000"/>
<!-- Layer with US States -->
<esri:QueryTask id="queryTask"
url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5"
useAMF="false"/>
<esri:Query id="query"
outSpatialReference="{map.spatialReference}"
returnGeometry="true"
text="{fText.text}">
<esri:outFields>
<fx:String>MED_AGE</fx:String>
<fx:String>POP2007</fx:String>
</esri:outFields>
</esri:Query>
</fx:Declarations>
<s:BorderContainer width="100%" height="40"
backgroundColor="0xDDDDFF"
borderVisible="false">
<s:layout>
<s:HorizontalLayout horizontalAlign="center"
paddingTop="10"
verticalAlign="middle"/>
</s:layout>
<s:Label text="Search for U.S. States:"/>
<s:TextInput id="fText"
enter="doQuery()"
text="Ca"/>
<s:Button click="doQuery()" label="Query"/>
</s:BorderContainer>
<s:Label id="resultSummary" height="15"/>
<mx:VDividedBox width="100%" height="100%">
<esri:Map id="map">
<esri:extent>
<esri:Extent xmin="-14000000" ymin="2800000" xmax="-7000000" ymax="6400000">
<esri:SpatialReference wkid="102100"/>
</esri:Extent>
</esri:extent>
<esri:ArcGISDynamicMapServiceLayer url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer"/>
<esri:GraphicsLayer id="myGraphicsLayer"
graphicProvider="{queryTask.executeLastResult.features}"
symbol="{sfs}"/>
</esri:Map>
<mx:DataGrid width="100%" height="40%"
dataProvider="{queryTask.executeLastResult.attributes}"/>
</mx:VDividedBox>
</s:Application>