QueryTask练习

ContractedBlock.gif ExpandedBlockStart.gif QueryTask
 
   
<? 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.Graphic;

import mx.controls.Alert;
import mx.rpc.AsyncResponder;
private function loadMapLayer(evt:Event):void
{
var layerInfo:Array;
layerInfo=my.layerInfos;
var layers:Array=new Array();
for(var i:int=0;i<layerInfo.length;i++)
{
layers.push({label:layerInfo[i].name,data:i});
}
layerList.dataProvider=layers;
}
private function doQuery():void
{
myGraphicsLayer.clear();
queryTask.execute(query,new AsyncResponder(onResult,onFault));//一个异步调用方法,成功则响应onResult函数,失败则响应onFault函数
}
private function onResult(featureSet:FeatureSet,token:Object = null):void //调用execute方法后查询结果返回一个FeatureSet,这里定义了
{ result数组遍历获取FeatureSet中的要素
var result:Array=new Array();
for each(var graphic:Graphic in featureSet.features)
{
myGraphicsLayer.add(graphic);
result.push({"洲名字":graphic.attributes.STATE_NAME,"2000人口":graphic.attributes.POP2000});
}
resultTable.dataProvider=result;
}
private function onFault(info:Object, token:Object=null):void
{
mx.controls.Alert.show("输入的查询语句不正确");
}
]]>
</ fx:Script >
< fx:Declarations >
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
< esri:Extent id ="allUsa" xmin ="-183.780014745329" ymin ="16.2975638854873" xmax ="-61.4068547410964" ymax ="74.0304580085983" />
< esri:QueryTask id ="queryTask"
showBusyCursor
="true"
url
="http://shibaizhong-pc/ArcGIS/rest/services/USA/MapServer/2"
useAMF
="false" />

< esri:Query id ="query"
outSpatialReference
="{myMap.spatialReference}"
returnGeometry
="true"
text
="{qText.text}" >
< esri:outFields > //outField定义了Query查询返回哪些字段的内容
< fx:String > STATE_NAME </ fx:String >
< fx:String > POP2000 </ fx:String >
</ esri:outFields >
</ esri:Query >

</ fx:Declarations >
< s:layout >
< s:HorizontalLayout />
</ s:layout >
< s:BorderContainer height ="100%" width ="80%" borderStyle ="solid" borderWeight ="2" borderColor ="#439AD7" >
< s:layout >
< s:VerticalLayout paddingLeft ="10" paddingTop ="10" >

</ s:VerticalLayout >
</ s:layout >
< s:Panel height ="64" width ="100%" >
< s:layout >
< s:HorizontalLayout paddingLeft ="10" paddingTop ="5" />
</ s:layout >
< mx:ComboBox id ="layerList" width ="117" ></ mx:ComboBox >
< s:TextInput id ="qText" width ="223" text ="Ca" enter ="doQuery()" />
< s:Button label ="查询" fontSize ="12" click ="doQuery()" />
</ s:Panel >

< esri:Map id ="myMap" logoVisible ="false" panArrowsVisible ="true" extent ="{allUsa}" >

< esri:ArcGISTiledMapServiceLayer id ="Arc" url ="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer" />
< esri:ArcGISDynamicMapServiceLayer id ="my" url ="http://shibaizhong-pc/ArcGIS/rest/services/USA/MapServer" creationComplete ="loadMapLayer(event)" >
< esri:visibleLayers >
< mx:ArrayCollection />
</ esri:visibleLayers >
</ esri:ArcGISDynamicMapServiceLayer >
< esri:GraphicsLayer id ="myGraphicsLayer" />
</ esri:Map >
</ s:BorderContainer >
< mx:DataGrid id ="resultTable" height ="100%" width ="17%" borderStyle ="solid" borderColor ="#D6D7D8" />
</ s:Application >

转载于:https://www.cnblogs.com/gisak/archive/2011/05/16/2048069.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值