一、查询地图数据

一、步骤
1.创建地图图层;
2.创建查询任务;
3.使用用户输入处理查询任务;
4.显示查询结果。

<?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"
               xmlns:esri="http://www.esri.com/2008/ags">

    <s:layout>
        <s:VerticalLayout gap="10"
                          horizontalAlign="center"
                          paddingBottom="20"
                          paddingLeft="25"
                          paddingRight="25"
                          paddingTop="20"/>
    </s:layout>
    <fx:Script>
        <![CDATA[
            import com.esri.ags.FeatureSet;
            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
                {
                    // No code needed in this simple sample, since the
                    // graphics layer is bound to the query result using
                    // graphicProvider="{queryTask.executeLastResult.features}"
                }

                function onFault(info:Object, token:Object = null):void
                {
                    Alert.show(info.toString(), "Query Problem");
                }
            }
        ]]>
    </fx:Script>
    <fx:Declarations>
        <!-- Layer with US States -->
        <esri:QueryTask id="queryTask"
                        showBusyCursor="true"
                        url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5"
                        useAMF="false"/>
        <esri:Query id="query"
                    outSpatialReference="{myMap.spatialReference}"
                    returnGeometry="true"
                    text="{qText.text}">

            <esri:outFields>
                <fx:String>MED_AGE</fx:String>
                <fx:String>POP2007</fx:String>
            </esri:outFields>
        </esri:Query>
    </fx:Declarations>
    <s:Panel height="60" 
             backgroundColor="0xB2BFC6"
             title="Query a layer (search for a state)">

        <s:layout>
            <s:HorizontalLayout/>
        </s:layout>

        <s:TextInput id="qText"
                     width="100%"
                     enter="doQuery()"
                     text="California"/>

        <s:Button click="doQuery()" label="Do Query"/>
    </s:Panel>
    <esri:Map id="myMap">
        <esri:extent>
            <esri:Extent xmin="-14298000" ymin="2748000" xmax="-6815000" ymax="7117000">
                <esri:SpatialReference wkid="102100"/>
            </esri:Extent>
        </esri:extent>

        <esri:ArcGISTiledMapServiceLayer 
            url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Physical_Map/MapServer"/>
        <esri:GraphicsLayer id="myGraphicsLayer" 
                            graphicProvider="{queryTask.executeLastResult.features}"/>
    </esri:Map>
</s:Application>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值