地图查询定位功能(Flex API)
?ArcGIS Server 10.0+Flex API 2.5. 實(shí)現(xiàn)查詢定位,目標(biāo)區(qū)域邊界高亮。
1.使用QueryTask獲得查詢信息。
2.將查詢結(jié)果以Graphic形式放在GraphicsLayer上。
3.對相應(yīng)graphic設(shè)置Symbol,高亮顯示,使用SimpleFillSymbol、SimpleLineSymbol,其中SimpleFillSymbol設(shè)置為空,設(shè)置outline,即實(shí)現(xiàn)邊界高亮效果。
效果圖:
具體:
1.使用QueryTask獲得查詢信息:
where語句中格式需注意,字符的值使用單引號(hào),數(shù)字不需單引號(hào)。
//省區(qū)域查詢protected function button1_clickHandler():void{var queryTask:QueryTask=new QueryTask;var query:Query=new Query();queryTask.url="http://192.168.100.226:8399/arcgis/rest/services/abs_cni/ChinaRegion/MapServer/2";query.returnGeometry=true;query.outFields = ["name"];query.outSpatialReference = map.spatialReference;query.where="name like '%"+sheng.text+"%'";queryTask.execute(query,new AsyncResponder(onResult,onFault)); }2.將查詢結(jié)果以Graphic形式放在GraphicsLayer上,并定位(居中顯示),即獲得查詢結(jié)果graphic的extent。
可能在瀏覽器上居中顯示時(shí),區(qū)域邊界部分顯示不完全,可以將區(qū)域放大,即“map.extent = graphic.geometry.extent.expand(1.5);”,代表將范圍在原有基礎(chǔ)上擴(kuò)大50%。
此處犯過兩個(gè)錯(cuò)誤:
? (1).使用以下方法,實(shí)質(zhì)獲得graphic之和的extent。
var graphicProvider:ArrayCollection = myGraphicsLayer.graphicProvider as ArrayCollection;var graphicsExtent:Extent = GraphicUtil.getGraphicsExtent(graphicProvider.toArray());
? (2).結(jié)果函數(shù)里忘記清除之前graphic,即“myGraphicsLayer.clear();”,這樣一來,由于之前查詢結(jié)果的graphic的影響,多次查詢后extent也是錯(cuò)誤的。
改正后正確方法如下:
private function onResult(featureSet:FeatureSet,token:Object = null):void{for each(var graphic:Graphic in featureSet.features){myGraphicsLayer.clear();graphic.symbol=QuerySymbol;myGraphicsLayer.add(graphic);map.extent = graphic.geometry.extent.expand(1.5);} }private function onFault(info:Object, token:Object = null ):void{Alert.show("Error!");}3.設(shè)置高亮顯示的symbol,面符號(hào)中可設(shè)置為空,加上outline,這樣即可邊界高亮顯示。
<esri:SimpleFillSymbol id="QuerySymbol"color="0xFF0000"alpha="0.6"outline="{sls}"style="null"></esri:SimpleFillSymbol><esri:SimpleLineSymbol id="sls"color="0xFF0000"alpha="1"style="solid"></esri:SimpleLineSymbol>另:如果使用FlexViewer,單獨(dú)做成widget的話,別忘了設(shè)置widget初始化函數(shù)加載graphicslayer,以及關(guān)閉wigdet時(shí)的清除graphic(“myGraphicsLayer.clear();”)
?
轉(zhuǎn)載于:https://www.cnblogs.com/colinhou/archive/2012/12/13/2815657.html
總結(jié)
以上是生活随笔為你收集整理的地图查询定位功能(Flex API)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 怎样合理减少企业所得税
- 下一篇: 怎么样才能快速借到钱 可以选择这些途径