Select to view content in your preferred language

Zoom to multi points

653
1
12-17-2010 02:09 PM
MikeJun
New Contributor II
When I query, it returns mutliple records in datagrid but it only shows first feature point as result on the map. How can I show multi points on the map as same as the result in datagrid?


<?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.geometry.MapPoint;
            import com.esri.ags.geometry.Multipoint;
            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 name found. Please try again.");
                    }
                    else
                    {
                        var myFirstGraphic:Graphic = featureSet.features[0];
       MapPoint(myFirstGraphic.geometry).extent;

       for each (var myGraphic1:Graphic in featureSet.features)
       {
        myGraphicsLayer.add(myGraphic1);
       }
        map.centerAt(myGraphic1.geometry as MapPoint);
        map.scale = 18000;

                    }
                }
                function onFault(info:Object, token:Object = null):void
                {
                    Alert.show(info.toString());
                }
            }
        ]]>
    </mx:Script>
<!-- Start Declarations -->

        <esri:SimpleMarkerSymbol id="sfs" style="diamond" color="0x00FF00" size="40"/> 

        <esri:QueryTask id="queryTask"
            url="http://cobgisags/ArcGIS/rest/services/Cert/MapServer/0"/>
   
        <esri:Query id="query" text="{fText.text}" returnGeometry="true" outSpatialReference="{map.spatialReference}">
            <esri:outFields>
                <mx:String>Firstname</mx:String>
                <mx:String>Lastname</mx:String>
            </esri:outFields>
        </esri:Query>
<!-- End Declarations -->

    <mx:HBox width="100%" height="40" backgroundColor="0xDDDDFF" paddingTop="10" horizontalAlign="center">
        <mx:Text text="Enter First Name:"/>
        <mx:TextInput id="fText" enter="doQuery()" text="Bill"/>
        <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="7535004" ymin="609638" xmax="7742959" ymax="708989">
                <esri:SpatialReference wkid="2913"/>
            </esri:Extent>
            </esri:extent>
           
            <esri:ArcGISTiledMapServiceLayer url="http://cobgisags/ArcGIS/rest/services/BaseMap/MapServer" />
            <esri:ArcGISDynamicMapServiceLayer url="http://cobgisags/ArcGIS/rest/services/Cert/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>
Tags (2)
0 Kudos
1 Reply
MikeJun
New Contributor II
Found Robert's code! Thanks again


private function doQuery():void
            {
                queryTask.execute(query, new AsyncResponder(onResult, onFault));
                function onResult(featureSet:FeatureSet, token:Object = null):void
                {
                 var multiPoint:Multipoint = new Multipoint();
        for each (var gra:Graphic in featureSet.features)
          multiPoint.addPoint(MapPoint(gra.geometry));
                       map.extent = multiPoint.extent.expand(1.5);     
             
                }
                function onFault(info:Object, token:Object = null):void
                {
                    Alert.show(info.toString());
                }
            }
0 Kudos