Select to view content in your preferred language

Query to search numbers

1378
6
Jump to solution
03-11-2014 05:52 AM
HectorChapa
Frequent Contributor
What am I doing wrong.

It doesnt want to zoom to this location using this query.
Any ideas why. I think because the field I am searching is a double.
Could someone guide me of doing a simple query that searches for that number.


[HTML]
<?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"       backgroundColor="0xEEEEEE"       pageTitle="Query, then zoom to results">    <s:layout>   <s:VerticalLayout gap="0"/>  </s:layout>    <fx:Script>   <![CDATA[    import com.esri.ags.FeatureSet;    import com.esri.ags.utils.GraphicUtil;        import mx.collections.ArrayCollection;    import mx.collections.ArrayList;    import mx.controls.Alert;    import mx.rpc.AsyncResponder;        private function doQuery():void    {     Number(fText.text);     // clear the graphics layer     myGraphicsLayer.clear();          queryTask.execute(query, new AsyncResponder(onResult, onFault));     function onResult(featureSet:FeatureSet, token:Object = null):void     {            if (featureSet.features.length == 0)      {       Alert.show("No States found. Please try again.");      }      else      {       var graphicsExtent:Extent = GraphicUtil.getGraphicsExtent(featureSet.features);       if (graphicsExtent)       {        map.extent = graphicsExtent;       }      }     }     function onFault(info:Object, token:Object = null):void     {      Alert.show(info.toString());     }    }          ]]>  </fx:Script>    <fx:Declarations>   <!-- Symbol for Query Result as Polygon -->   <esri:SimpleFillSymbol id="sfs" alpha="0.7"/>      <!-- Layer with US States -->   <esri:QueryTask id="queryTask" url="http://192.168.0.11:6080/arcgis/rest/services/STEARWEBMAPTEST/MapServer/0"/>      <esri:Query id="query"      outSpatialReference="{map.spatialReference}"      returnGeometry="true"       where="StateID = {Number(fText.text)}">   </esri:Query>   <s:NumberFormatter id="numberFormatter"/>  </fx:Declarations>    <s:controlBarLayout>   <s:VerticalLayout gap="10"         paddingBottom="7"         paddingLeft="10"         paddingRight="10"         paddingTop="7"/>  </s:controlBarLayout>  <s:controlBarContent>   <s:RichText width="100%">    This sample demonstrates how to use the QueryTask to search for features    in a specific layer in a map service based upon a string value.  If the    query returns a result, the GraphicUtil class is used to calculate the    extent of the returned features and the map's extent is then set to that    extent.   </s:RichText>   <s:HGroup width="100%" verticalAlign="baseline">    <s:Label text="Search for U.S. States:"/>    <s:TextInput id="fText"        enter="doQuery()"        />    <s:Button click="doQuery()" label="Search"/>   </s:HGroup>  </s:controlBarContent>    <esri:Map id="map">   <esri:extent>    <esri:Extent xmin="-1.09742216352E7" ymin="3006114.7661000006" xmax="-1.08446320657E7" ymax="3100223.793400001">     <esri:SpatialReference wkid="102100"/>    </esri:Extent>   </esri:extent>   <esri:ArcGISDynamicMapServiceLayer url="http://192.168.0.11:6080/arcgis/rest/services/STEARWEBMAPTEST/MapServer" />   <esri:GraphicsLayer id="myGraphicsLayer"        graphicProvider="{queryTask.executeLastResult.features}"        symbol="{sfs}"/>  </esri:Map>   </s:Application>
[/HTML]
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus
Hector,

   A point does not have an extent to you can not use the code you are using to zoom to the point.

Here is some code that handles that.

private function executeCompleteHandler(event:FindEvent):void             {                 myGraphicsLayer.clear();                                  //resultSummary.text = "Found " + event.findResults.length + " results.";                 myGraphicsLayer.symbol = smsFind;                                  var resultCount:int = event.findResults.length;                                  if (resultCount == 0)                 {                     Alert.show("No State ID found. Please change your search.");                 }                 else                 {                     // add feature as graphic to graphics layer                     for (var i:int = 0; i < resultCount; i++)                     {                         var graphic:Graphic = FindResult(event.findResults).feature;                         graphic.toolTip = event.findResults.foundFieldName + ": " + event.findResults.value;                         myGraphicsLayer.add(graphic);                     }                                          // zoom to extent of all features                     var graphicProvider:ArrayCollection = myGraphicsLayer.graphicProvider as ArrayCollection;                     if (graphicProvider.length == 1                         && graphicProvider[0].geometry.type == Geometry.MAPPOINT){                         var mp:MapPoint = graphicProvider[0].geometry as MapPoint;                         mainMap.zoom(1 / 16, mp);                         mainMap.centerAt(mp);                     }else{                         var graphicsExtent:Extent = GraphicUtil.getGraphicsExtent(graphicProvider.toArray());                         if(graphicsExtent){                             mainMap.zoomTo(graphicsExtent.expand(1.4));                         }else{                             var mp2:MapPoint = graphicProvider[0].geometry as MapPoint;                             mainMap.zoom(1 / 16, mp2);                             mainMap.centerAt(mp2);                         }                     }                 }

View solution in original post

0 Kudos
6 Replies
RobertScheitlin__GISP
MVP Emeritus
Hector,

   Your issue is that you data is point geometry and the symbol that you are giving to the myGraphicsLayer is for a polygon.
0 Kudos
HectorChapa
Frequent Contributor
Thanks where do I change that. I feel stupid why didnt i thought of that.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Hector,

   You are setting it here:

<esri:GraphicsLayer id="myGraphicsLayer"        graphicProvider="{queryTask.executeLastResult.features}"        symbol="{sfs}"/>


So you will need to change it to a SimpleMarkerSymbol or just remove it all together.
0 Kudos
HectorChapa
Frequent Contributor
Ok got the query to work but is still not zooming in to that location.
Here is the code. could you tell me what I am doing wrong.

private function doFind():void
    {
     findTask.execute(myFindParams);
    }
    
    private function executeCompleteHandler(event:FindEvent):void
    {
     myGraphicsLayer.clear();
     
     resultSummary.text = "Found " + event.findResults.length + " results.";
     myGraphicsLayer.symbol = smsFind;
     
     var resultCount:int = event.findResults.length;
     
     if (resultCount == 0)
     {
      Alert.show("No State ID found. Please change your search.");
     }
     else
     {
      // add feature as graphic to graphics layer
      for (var i:int = 0; i < resultCount; i++)
      {
       var graphic:Graphic = FindResult(event.findResults).feature;
       graphic.toolTip = event.findResults.foundFieldName + ": " + event.findResults.value;
       myGraphicsLayer.add(graphic);
      }
      
      // zoom to extent of all features
      var graphicProvider:ArrayCollection = myGraphicsLayer.graphicProvider as ArrayCollection;
      var graphicsExtent:Extent = GraphicUtil.getGraphicsExtent(graphicProvider.toArray());
      mainMap.extent = graphicsExtent.expand(1.4); // zoom out a little
     }
    }


Here is the mxml.
<esri:SimpleMarkerSymbol id="smsFind"
          alpha="0.9"
          color="#0000FF"
          size="11"
          style="square">
   </esri:SimpleMarkerSymbol>
   <esri:FindTask id="findTask"
         executeComplete="executeCompleteHandler(event)"
         url="http://192.168.0.11:6080/arcgis/rest/services/STEARWEBMAPTEST/MapServer"/>
   <esri:FindParameters id="myFindParams"
         contains="true"
         layerIds="[0]"
         outSpatialReference="{mainMap.spatialReference}"
         returnGeometry="true"
         searchFields="[StateID]"
         searchText="{qText.text}"/>

<esri:Map  id="mainMap"  x="0" y="10" height="100%" width="100%"  logoVisible="false" >
   
   <esri:extent>
    <esri:Extent xmax="-1.08446320657E7" ymax="3100223.793400001"
        xmin="-1.09742216352E7" ymin="3006114.7661000006">
     <esri:SpatialReference wkid="102100" >
     </esri:SpatialReference>
     
    </esri:Extent>
   </esri:extent>
   
   <esri:ArcGISTiledMapServiceLayer url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer" />
   <esri:ArcGISDynamicMapServiceLayer url="http://192.168.0.11:6080/arcgis/rest/services/STEARWEBMAPTEST/MapServer" />
   <esri:FeatureLayer id="points" url="http://192.168.0.11:6080/arcgis/rest/services/STEARWEBMAPTEST/FeatureServer/0" outFields="*" />
   <esri:GraphicsLayer id="myGraphicsLayer" />
  </esri:Map>
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Hector,

   A point does not have an extent to you can not use the code you are using to zoom to the point.

Here is some code that handles that.

private function executeCompleteHandler(event:FindEvent):void             {                 myGraphicsLayer.clear();                                  //resultSummary.text = "Found " + event.findResults.length + " results.";                 myGraphicsLayer.symbol = smsFind;                                  var resultCount:int = event.findResults.length;                                  if (resultCount == 0)                 {                     Alert.show("No State ID found. Please change your search.");                 }                 else                 {                     // add feature as graphic to graphics layer                     for (var i:int = 0; i < resultCount; i++)                     {                         var graphic:Graphic = FindResult(event.findResults).feature;                         graphic.toolTip = event.findResults.foundFieldName + ": " + event.findResults.value;                         myGraphicsLayer.add(graphic);                     }                                          // zoom to extent of all features                     var graphicProvider:ArrayCollection = myGraphicsLayer.graphicProvider as ArrayCollection;                     if (graphicProvider.length == 1                         && graphicProvider[0].geometry.type == Geometry.MAPPOINT){                         var mp:MapPoint = graphicProvider[0].geometry as MapPoint;                         mainMap.zoom(1 / 16, mp);                         mainMap.centerAt(mp);                     }else{                         var graphicsExtent:Extent = GraphicUtil.getGraphicsExtent(graphicProvider.toArray());                         if(graphicsExtent){                             mainMap.zoomTo(graphicsExtent.expand(1.4));                         }else{                             var mp2:MapPoint = graphicProvider[0].geometry as MapPoint;                             mainMap.zoom(1 / 16, mp2);                             mainMap.centerAt(mp2);                         }                     }                 }
0 Kudos
HectorChapa
Frequent Contributor
Thank you for all your support. I am realling learning a lot.
0 Kudos