Select to view content in your preferred language

Query and Zoom To Point?

1807
10
12-01-2010 07:40 AM
EmilyLaMunyon
Deactivated User
Hello,

I have searched the forums and have not found much to help me with this. I am attempting to query a point layer and then zoom to the result. I have this working with a polyline feature, so there must be something different when it comes to point features. I am guessing it has to do with the geometry and/or feature length. Does anyone have any insight?

Thanks in advance!
Tags (2)
0 Kudos
10 Replies
RobertScheitlin__GISP
MVP Emeritus
0 Kudos
EmilyLaMunyon
Deactivated User
No, I must have missed that one. I will check it out, thanks!
0 Kudos
JeffPerkins
Occasional Contributor
Is this a multi-point feature class or a single point feature class you're trying to query?
0 Kudos
EmilyLaMunyon
Deactivated User
Hi Jeff,

It is a single point feature class.

The query results display in the table, so I believe the query part is working. It is when I click on the result and try to zoom to it that I get an error. I am sure it has to do with the geometry or feature length, I am just a bit stuck on how to fix this.

Thanks!
0 Kudos
JeffPerkins
Occasional Contributor
try this...


            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
                    {
                        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 = 18036;
                       
                    }
                }
                function onFault(info:Object, token:Object = null):void
                {
                    Alert.show(info.toString());
                }
            }
        ]]>
    </mx:Script>
0 Kudos
EmilyLaMunyon
Deactivated User
Jeff,

Thanks so much! I think I am close, but the myGraphicsLayer part is giving me an error reading Access of undefined property. I am sure this is a stupid question, but where should I define this?

I appreciate your time!

Emily
0 Kudos
JeffPerkins
Occasional Contributor
Here's an example.  The Graphics layer is def. <esri:GraphicsLayer id="myGraphicsLayer" symbol="{sfs}"/>  bound to symbol.  

Hope it works out for you.


<?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.MapPoint;
            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
                    {
                        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 = 18036;
                       
                    }
                }
                function onFault(info:Object, token:Object = null):void
                {
                    Alert.show(info.toString());
                }
            }
        ]]>
    </mx:Script>

    <!-- Start Declarations -->
        <!-- Symbol for Query Result as Polygon -->
        <esri:SimpleMarkerSymbol id="sfs" color="0xFF0000"/>
   
        <!-- Layer with US States -->
        <esri:QueryTask id="queryTask"
            url="http://gis.glo.state.tx.us/arcgis/services/bw/Stations/MapServer/0"/>
   
        <esri:Query id="query" text="{fText.text}" returnGeometry="true" outSpatialReference="{map.spatialReference}">
            <esri:outFields>
                <mx:String>chrstationname </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 something.."/>
        <mx:TextInput id="fText" enter="doQuery()" text="Riviera Beach Pier"/>
        <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/MapSe..."/>
            <esri:GraphicsLayer id="myGraphicsLayer" symbol="{sfs}"/>
        </esri:Map>
        <mx:DataGrid
            dataProvider="{queryTask.executeLastResult.attributes}"
            scroll="true" width="100%" height="40%"/>
    </mx:VDividedBox>
</mx:Application>
0 Kudos
EmilyLaMunyon
Deactivated User
Thanks so much Jeff!  The query on the point is now working! If I enter the right number, it will zoom to the point.

One last thing is holding me up...when I go to click on a result in the grid in order to zoom to it, I get an error. I have searched the samples and from what I can see, there is no zoom to point sample from a grid result.

[RPC Fault faultString="Unable to perform query. Please check your parameters" faultCode="500" faultDetail=""].

I know this has something to do with the grdResult_Click() function. I have it working for a polyline feature, it just does not seem to like points.

I appreciate your time:)
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Emily,

   Here is your full app tweaked a little with your latest issue fixed.
0 Kudos