日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2025/3/21 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 arcgis api for flex 开发入门(五)查询 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在gis中,針對要素的查詢是一個最基本的操作,也是最常用的操作之一。
下面我們介紹如何使用arcgis api for flex 來查詢我們需要的東西。
要在arcgis api for flex中進行查詢操作,首先需要定義一個查詢任務面板。
使用<esriueryTask>標簽就可以了。
??<esriueryTask id="queryTask"
url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demogra
phics/ESRI_Census_USA/MapServer/5">
? ?? ???<esriuery id="query"
? ?? ?? ?? ?text="{qText.text}"
? ?? ?? ?? ?returnGeometry="true"
? ?? ?? ?? ?spatialRelati>
? ?? ?? ?? ?<esriutFields>
? ?? ?? ?? ?? ? <mx:String>MED_AGE</mx:String>
? ?? ?? ?? ?? ? <mx:String>POP2007</mx:String>
? ?? ?? ?? ?</esriutFields>
? ?? ???</esriuery>
? ? </esriueryTask
id 唯一標識這個查詢任務,url告訴查詢面板去哪查。
<esriuery>定義一個查詢,text是你需要查詢的東西,<esriutFields>子標
簽告訴Query 查詢的結果返回哪些字段的內容。
QueryTask 定義好之后,我們還需要在界面上來調用這個QueryTask。因此我們定
義一個文本輸入框和一個查詢按鈕
<mxanel 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
()"/>? ?? ?? ?? ?? ? </mxanel>
文本輸入框 用來輸入你想要查詢的內容,button 用來執行查詢的動作。
那么這個doQuery()怎么實現呢?我們在mxml的標簽中已經無法實現,這就需要引
入activescript腳本。我們需要在mxml中使用activescript腳本歷來編寫代碼,
實現我們想要的功能。
關于activescript的語法大家可以參考activescript的相關書籍。
要在mxml文檔中插入activescript,需要使用<mx:Script>標簽
<mx:Script>
? ?? ???<![CDATA[
? ?? ???]]>
? ? </mx:Script>
activescript 是一種類java 語言,它本身有一個AVM,把activescript編譯成
java 的代碼,然后再通過JVM轉換成字節碼執行。
我們下面就開始實現doQuery();
首先,我們要用import 指令引入我們需要的命名空間,和java基本一樣
<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;
? ?? ???]]>
? ? </mx:Script>
然后我們定義doQuery()函數: 注意activescript代碼 要放到<mx:Script>標簽

private function doQuery() : void
? ?? ?? ?? ?{
? ?? ?? ?? ?? ? queryTask.execute( query, new AsyncResponder( onResult,
onFault ));
在doQuery()函數中直接調用了queryTask的execute方法,這是一個異步調用。
成功響應onResult函數,失敗則響應onFault函數。
查詢已經寫好了,那么我們怎么得到查詢的結果呢?得到結果肖恩么表現呢?
這就需要我們在onResult函數中做一些事情了。
首先,定義onResult函數
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 );
? ?? ?? ?? ?? ?? ???}
? ?? ?? ?? ?? ? }
查詢結果返回一個 FeatureSet,我們現在遍歷這個 FeatureSet,然后把每個
feature 繪制到GraphicLayer上。
如果查詢失敗了怎么辦呢,我們是不是要彈個東西出來告訴用戶呢?
這就需要我們在onFault函數中做一些工作
function onFault( info : Object, token : Object = null ) : void
? ?? ?? ?? ?? ? {
? ?? ?? ?? ?? ?? ???Alert.show( info.toString() );
? ?? ?? ?? ?? ? }? ?? ?? ?? ?? ?? ?? ?? ?
? ?? ?? ?? ?}
我們彈個對話框出來告訴用戶,查找失敗啦!

完整代碼:

Code
<?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



本文轉自溫景良(Jason)博客園博客,原文鏈接:http://www.cnblogs.com/wenjl520/archive/2009/06/02/1494549.html,如需轉載請自行聯系原作者

《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀

總結

以上是生活随笔為你收集整理的arcgis api for flex 开发入门(五)查询的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。