在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,如需转载请自行联系原作者

arcgis api for flex 开发入门(五)查询相关推荐

  1. arcgis api for flex 开发入门(九)webservices 的使用

    arcgis api for flex 开发入门(九)webservices 的使用 flex 本身对webservices有着良好的支持,我们可以调用互联网上的各种 webservices来结合es ...

  2. arcgis api for flex 开发入门(二)map 的创建

    arcgis api for flex 开发入门(二)map 的创建 在flex 中创建一个esri 的map ,你只需要使用<esri:Map>标签就可以轻松完成. 在<esri: ...

  3. arcgis api for flex 开发入门(七)Geometry service 的使用

    arcgis api for flex 开发入门(七)Geometry service 的使用 Geometry service 顾名思义,就是提供针对几何层级的服务,比如说Project,   Si ...

  4. ArcGIS API for Silverlight开发入门

    ArcGIS API for Silverlight开发入门 你用上3G手机了吗?你可能会说,我就是喜欢用nokia1100,ABCDEFG跟我 都没关系.但你不能否认3G是一种趋势,最终我们每个人都 ...

  5. ArcGIS API for Silverlight开发入门准备

    原文:ArcGIS API for Silverlight开发入门准备 微软的Silverlight提供了跨浏览器和跨平台开发环境,在Web中可用于创建和展现富互联网应用(RIA,Rich Inter ...

  6. 13 ArcGIS API for JavaScript开发入门文档

    写在前面 这篇文章写在我用ArcGIS API for JavaScript(后面统称为"ArcGIS JS API")开发了两年项目后的某一天夜里.写这篇文章主要是两个目的吧,第 ...

  7. ArcGIS API for Silverlight开发入门(2):一个基础地图实例

    这节在一个地图实例的基础上,来对Silverlight API中的一些基本概念做一个总体了解,顺便熟悉一下Silverlight的开发知识.         点击这里,直接看效果. 下载 (722.0 ...

  8. ArcGis api配合vue开发入门系列(二)距离以及面积的测量

    正文 首先自定义个工具栏,包括测量距离与测量面积的工具以及地图漫游. 图标的话是用的iconfont.我是把这个工具单独写在一个组件里面,这个组件里面里面会用到一些操作地图的方法,我在map这个组件里 ...

  9. [转]ArcGIS.Server.9.3和ArcGIS API for Flex实现Query查询定位中心功能(七)

    目的: 1.ArcGIS API for Flex实现Query查询定位中心功能,进行属性查图的功能,选择图层然后输入查询语句进行查询把查到的地理元素高亮显示同时在右边的Grid中显示查到的数据,然后 ...

最新文章

  1. memcached的最佳实践方案(转)
  2. asp之GetArray提取链接地址,以$Array$分隔的代码
  3. python自动化测试数据驱动_利用Python如何实现数据驱动的接口自动化测试
  4. 办公自动化及工作流技术
  5. Ext-ajax请求数据
  6. 深度学习行人重识别综述与展望
  7. 虚拟机linux和主机网络连接,linux虚拟机中和主机三种网络连接方式的区别
  8. plsql 误删表,使用flashback query恢复被删除plsql
  9. Arduion 底层原理之 setup函数和loop函数
  10. C语言中16进制转字符串字符串转16进制
  11. 对数(log)的换算公式
  12. Ubuntu联网图标消失
  13. 常见单位换算[时间,距离,热量...]
  14. python中文分词算法_基于Python语言的中文分词技术的研究
  15. linux网络适配器驱动程序怎么安装,网络适配器怎么修复_如何修复网络适配器
  16. 易企秀如何生成图片_易企秀如何制作圆形照片
  17. 【Verilog数字系统设计——完成如下公式所表示的逻辑功能模块】
  18. [学习笔记]自适应辛普森(Simpson)积分
  19. python 如何使用正则表达式
  20. 开机点用户名登录显示rfc服务器不可用,打印机不能打印提示rpc服务器不可用怎么办...

热门文章

  1. mysql怎么引用别的文件_用source语句引用mysql文件的细节注意
  2. final关键字的几大特征
  3. 一个方法搞定安卓路由跳转
  4. 延长计算机屏幕显示时间,非充电状态下延长计算机使用时间的小诀窍!
  5. mysql 使用不同引擎_mysql 不同引擎的比较
  6. 战神笔记本电脑自带access吗_双·12超值价 十代酷睿+GTX1650游戏本只卖4219元_神舟 战神Z7M-CU5NB_笔记本新闻...
  7. abap判断当前月最后一个工作日_油价正式打响第一枪!今天12月3日,今晚油价迎来大幅暴跌,调价后全国地区油价一览!...
  8. Js Array数组ES5/ES6常用方法
  9. mysql用if判断关联的表_mysql表连接,子查询以及if判断
  10. java exe 返回值_java调用exe返回值