加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ArcGIS API For Flex3 Query查询完成之后定位(二)

发布时间:2020-12-15 04:24:38 所属栏目:百科 来源:网络整理
导读:?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,then zoom to results" styleName="plain" mx:Script ![CDATA[ import com.esri.ags.Graphic;
<?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,then zoom to results"
    styleName="plain">

    <mx:Script>
        <![CDATA[
            import com.esri.ags.Graphic;
            import com.esri.ags.geometry.Polygon;
            import com.esri.ags.tasks.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
                {
                    // clear the graphics layer
                    myGraphicsLayer.clear();

                    if (featureSet.features.length == 0)
                    {
                        Alert.show("No States found. Please try again.");
                    }
                    else
                    {
			//定义一个Extent,将查询后的每个Graphic都添加到这个Extent里,
//然后将这个Extent添加到Map里
                        var unionExtent:Extent;
                        var myFirstGraphic:Graphic = featureSet.features[0];
                        unionExtent = Polygon(myFirstGraphic.geometry).extent;

                        for each (var myGraphic1:Graphic in featureSet.features)
                        {
                            myGraphicsLayer.add(myGraphic1);
                            unionExtent = unionExtent.union(Polygon(myGraphic1.geometry).extent);
                        }

                        map.extent = unionExtent;
                    }
                }
                function onFault(info:Object,token:Object = null):void
                {
                    Alert.show(info.toString());
                }
            }
        ]]>
    </mx:Script>

    <!-- Start Declarations -->
        <!-- Symbol for Query Result as Polygon -->
        <esri:SimpleFillSymbol id="sfs" alpha="0.7" color="0xFF0000"/>
    
        <!-- Layer with US States -->
        <esri:QueryTask id="queryTask"
            url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5"/>
    
        <esri:Query id="query" text="{fText.text}" returnGeometry="true" outSpatialReference="{map.spatialReference}">
            <esri:outFields>
                <mx:String>MED_AGE</mx:String>
                <mx:String>POP2007</mx:String>
            </esri:outFields>
        </esri:Query>
    <!-- End Declarations -->

    <mx:HBox width="100%" height="40" backgroundColor="0xDDDDFF" paddingTop="10" horizontalAlign="center">
        <mx:Text text="Search for U.S. States:"/>
        <mx:TextInput id="fText" enter="doQuery()" text="Ca"/>
        <mx:Button label="Query" click="doQuery()"/>
    </mx:HBox>
    <mx:Text id="resultSummary" height="15"/>
    <mx:VDividedBox height="100%" width="100%">
        <esri:Map id="map">
            <esri:extent>
                <esri:Extent xmin="-126" ymin="24" xmax="-67" ymax="50">
                    <esri:SpatialReference wkid="4326"/>
                </esri:Extent>
            </esri:extent>
            <esri:ArcGISDynamicMapServiceLayer
                url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer"/>
            <esri:GraphicsLayer id="myGraphicsLayer" symbol="{sfs}"/>
        </esri:Map>
        <mx:DataGrid
            dataProvider="{queryTask.executeLastResult.attributes}"
            scroll="true" width="100%" height="40%"/>
    </mx:VDividedBox>
</mx:Application>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读