九,query task

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>

 

转载于:https://www.cnblogs.com/tiandi/archive/2012/03/05/2381114.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值