您的位置:首页 > 其它

arcgis api for flex 开发入门(五)查询

2009-06-02 14:58 507 查看
在gis中,针对要素的查询是一个最基本的操作,也是最常用的操作之一。
下面我们介绍如何使用arcgis api for flex 来查询我们需要的东西。
要在arcgis api for flex中进行查询操作,首先需要定义一个查询任务面板。
使用<esri
<?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 com.esri.ags.tasks.Query;
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/Demogra
phics/ESRI_Census_USA/MapServer/5">
<esri:Query id="query"
text="{qText.text}"
returnGeometry="true"
spatialRelationship="esriSpatialRelEnvelopeIntersects">
<esri:outFields>
<mx:String>MED_AGE</mx:String>
<mx:String>POP2007</mx:String>
</esri:outFields>
</esri:Query>
</esri:QueryTask>
<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:extent>
<esri:ArcGISTiledMapServiceLayer

url="http://server.arcgisonline.com/ArcGIS/rest/services/NPS_Physical_W
orld_2D/MapServer" />
<esri:GraphicsLayer id="myGraphicsLayer"/>
</esri:Map>
</mx:Application>
原文地址:http://bbs.esrichina-bj.cn/ESRI/viewthread.php?tid=35621&extra=page%3D4%26amp%3Borderby%3Ddateline
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: