QueryTask类

QueryTask类特点:

  1. 只能查询一个图层,url必须指定图层
  2. 可以进行空间查询和属性查询 Text 与Where语句,当where语句存在时 text失效
  3. 可以指定返回字段
  4. 处理结果为一个FeatureSet对象

步骤:

  1. 创建MAP和GraphicSlayer
  2. 创建QueryTask类
  3. 创建Query类作为参数
  4. 执行QueryTask的execute方法
  5. 显示方法结果

 

 

<?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" minWidth="955" minHeight="600" xmlns:esri="http://www.esri.com/2008/ags">

 <fx:Script>
  <![CDATA[
   import com.esri.ags.FeatureSet;
   import com.esri.ags.events.DrawEvent;
   import com.esri.ags.geometry.Geometry;
   
   import mx.rpc.AsyncResponder;
   protected function button1_clickHandler(event:MouseEvent):void
   {
    drawtool.activate(com.esri.ags.tools.DrawTool.POLYGON);//画一个多变形
   }

   protected function drawtool_drawEndHandler(event:DrawEvent):void
   {
    var geometry1:Geometry = event.graphic.geometry;//从画图结束的时候的event参数中得到几何图形
    query.geometry = geometry1;//空间查询所用的对比几何图形
    query.spatialRelationship=Query.SPATIAL_REL_CONTAINS;//所需要查询的控件关系[包含]
    QueryTask1.execute(query,new AsyncResponder(onok,onerr));//异步执行Query查询
   }
   protected function onok(info:FeatureSet,token:Object):void
   {
   graphic1.graphicProvider = info.features;//因为得到的是Featureset,将features作为数据源提供给graphiclayer
   grid1.dataProvider = info.attributes;//将得到的attributes作为Gridview数据源
   }
   
   protected function onerr(info:Object,token:Object):void
   {
    
    
   }

  ]]>
 </fx:Script>

 <fx:Declarations>
  <!-- Place non-visual elements (e.g., services, value objects) here -->
  <esri:DrawTool id="drawtool" drawEnd="drawtool_drawEndHandler(event)" map="{map1}" graphicsLayer="{graphic1}" />
    <esri:QueryTask id="QueryTask1" url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/0" useAMF="false" showBusyCursor="true" />
  <esri:Query id="query" returnGeometry="true" outFields="['CAPITAL','CITY_NAME']" where="CITY_NAME like '%a%'"  />
 <esri:PictureMarkerSymbol id="pic1" source="user4.png" />
 </fx:Declarations>
 <esri:Map id="map1">
    <esri:ArcGISDynamicMapServiceLayer url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer" />
 <esri:GraphicsLayer id="graphic1" symbol="{pic1}" />
 </esri:Map>
 <s:Button x="63" y="10" label="Button" click="button1_clickHandler(event)"/>
 <mx:DataGrid x="49" y="39" id="grid1">
  <mx:columns>
   <mx:DataGridColumn headerText="首都" dataField="CAPITAL"/>
   <mx:DataGridColumn headerText="城市名称" dataField="CITY_NAME"/>
  </mx:columns>
 </mx:DataGrid>
 
</s:Application>

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值