Select to view content in your preferred language

Query combo box on Layer -non SFV

2907
8
08-11-2010 06:57 AM
MayJeff
Deactivated User
I am able to use combo box to select a layer to do a query but I am not sure how to do query when select other layers beside Parcel layer.  I am using ESRI map services to run a test and Flex Builder 3.  Besides that, how to remove Shape_Area & Shape_Length on Datagrib table?

Please help.    Thank you.


Here is my code:

<?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"
    xmlns:North="org.calhoun.county.esri.ags.controls.*"
  xmlns:samples="com.esri.ags.samples.*"
    styleName="plain"
  
    width="100%" height="100%" layout="absolute" xmlns:maplib="com.esri.maplib.*" backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#050505, #CEC8C8]" xmlns:controls1="com.esri.ags.controls.*">


    <mx:Script>
        <![CDATA[
          

            import com.esri.ags.events.QueryEvent;
            import com.esri.ags.Graphic;
            import mx.controls.Alert;
            import mx.rpc.AsyncResponder;


            //Query
            import com.esri.ags.geometry.Polygon;           
            import com.esri.ags.tasks.FeatureSet;
                       
   import com.esri.ags.symbol.Symbol;
   import com.esri.ags.symbol.SimpleFillSymbol;
   import com.esri.ags.symbol.SimpleLineSymbol;
  
            import mx.controls.Alert;
            import mx.rpc.AsyncResponder;
            import mx.collections.ArrayCollection;
         
//   new start
            [Bindable]
            public var features:ArrayCollection = new ArrayCollection(
                [ {label:"Parcel", data:0},
                  {label:"Land Use", data:1},
                  {label:"Zoning", data:2} ]);
//    new end
           


   
//Zoom to Query result
    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 Results found. Please try again.");
                    }
                    else
                    {
                        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);
                        }

                        myMap.extent = unionExtent;
                        myMap.scale = 3000;
                    }
                }
                function onFault(info:Object, token:Object = null):void
                {
                    Alert.show(info.toString());
                }
            }
//End Zoom to query result

        ]]>
    </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/Louisville/LOJIC_LandRecords_Louisville/M...{myLAYER.selectedItem.data}"/>           
        <esri:Query id="query" text="{fText.text}" returnGeometry="true" outSpatialReference="{myMap.spatialReference}">           
        <esri:outFields>               
        <mx:String>PARCELID</mx:String>                          
        </esri:outFields>       
        </esri:Query>   
        <!-- End Declarations -->
       
            

<mx:VBox width="100%" height="100%">
<mx:HDividedBox width="100%" height="100%">
<mx:VBox width="400" height="100%">
  <mx:Panel title="My Panel" width="100%" height="100%" borderColor="#666464">
   <mx:Accordion width="100%" height="100%">
     <mx:VBox label="Search for Parcel ID" width="100%" height="100%" paddingLeft="2">
        <mx:Text text="Select a Layer to Search:"/>
        <mx:ComboBox id="myLAYER" dataProvider="{features}"  selectedIndex="0" editable="true" enabled="true" left="5" textAlign="left">
      </mx:ComboBox>
     <mx:HBox>
      <mx:TextInput id="fText" enter="doQuery()" text="012F00370000" textAlign="center"/>
      <mx:Button label="Search" click="doQuery()"/>
     </mx:HBox>
      <mx:Text text="Result:"/>
      <mx:DataGrid dataProvider="{queryTask.executeLastResult.attributes}" scroll="true" width="100%" height="40%"/>
    </mx:VBox>
   </mx:Accordion>
  </mx:Panel>
</mx:VBox>

<mx:VBox width="100%" height="100%">
  <mx:Panel title="Map" layout="absolute" height="100%" width="100%" borderColor="#666464">
      <esri:Map id="myMap" logoVisible="false"> <!--panArrowsVisible="true"-->
          <esri:extent>
              <esri:Extent xmin="-85.804" ymin="38.270" xmax="-85.797" ymax="38.275">
                 <esri:SpatialReference wkid="4326"/>
              </esri:Extent>               
          </esri:extent>
          <!-- Note: the visible setting on the tiled layer isn't really necessary,
               because tiled layers are only supported at the scales it was created with
               and thus API wont even send the requests outside of the cached levels -->

          <esri:ArcGISDynamicMapServiceLayer visible="{myMap.scale &lt; 4500}"
              url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Louisville/LOJIC_LandRecords_Louisville/M..."/>  
              <esri:GraphicsLayer id="graphicsLayer"/>
              <esri:GraphicsLayer id="myGraphicsLayer" symbol="{sfs}"/> <!--Zoom to Query result-->
      </esri:Map>
   </mx:Panel>
</mx:VBox>
</mx:HDividedBox>
</mx:VBox>
</mx:Application>
Tags (2)
0 Kudos
8 Replies
HessCorporation
Emerging Contributor
To remove the shape_ columns you need to specify this in the datagrid.

Change:
<mx:DataGrid dataProvider="{queryTask.executeLastResult.attribu tes}" scroll="true" width="100%" height="40%"/> 


To:
<mx:DataGrid dataProvider="{queryTask.executeLastResult.attributes}" scroll="true" width="100%" height="40%">
 <mx:columns>
  <mx:DataGridColumn dataField="PARCELID"/>
 </mx:columns>
</mx:DataGrid>


The query doesn't work because your query is still looking for PARCELID which isn't an attribute in the land use and zoning layers, you need to change the doQuery function to change this dynamically.

private function doQuery():void
{
   if (myLAYER.selectedItem.data == 2) {
      query.outFields = ['ZONING_CODE'];
   } 
   else if (myLAYER.selectedItem.data == 1) {
      query.outFields = ['LANDUSE_CODE'];
   }
   queryTask.execute(query, new AsyncResponder(onResult, onFault));
}


Also be aware that this is a case sensitive search, the default value you have in the search box is a parcel id, so you'll need an exact zoning or land use code to search with. You'll also need to change the dataField value on the DataGridColumn as well.
0 Kudos
MayJeff
Deactivated User
Thanks for the help.  It works but I would like to try for non case sensitive search and got some error message ([RPC Fault faultString="" faultCode="400" faultDetail="Unable to perform query. Please check your parameters."]) so see the code below:

       if (myLAYER.selectedItem.data == 2) {
          query.outFields = ["ZONING_CODE"];
       }
       else if (myLAYER.selectedItem.data == 1) {
          query.where = "[LAND_NAME] LIKE Lower('%[value]%')";
          query.outFields = ["LAND_NAME"],["LAND_CODE"];
       }
       else
       {
        query.where = "[PARCELID] LIKE Lower('%[value]%')";
        query.outFields =["PARCELID"];
       }

Can you let me know how to make the search for non case sensitive and how to change the dataField value as well.  Sorry for keep bothering you, I just start to learn FLEX!

Thank you very much.

May
0 Kudos
HessCorporation
Emerging Contributor
To change the datafield value you need to assign the column an id:

<mx:DataGridColumn id="dgc" dataField="PARCELID"/>


then in your doQuery function change the dataField value:

dgc.dataField = 'LAND_NAME';



Regarding the case sensitivity, to be honest i'd normally recommend a Find Task rather than Query for that as Find ignores case sensitivity by default, have a look here..

http://help.arcgis.com/en/webapi/flex/samples/index.html?sample=FindTask

Because you're using a Query Task with a SQL where clause it's a lot harder. The problem you'll also find with your where statement is that you've used Lower('%[value]%')", this converts the value to lower case, but you'll need to be sure that all the attributes in your source data are lower case as well, if the attribute table features a mixture of lower and upper case e.g. New York then your where clause will end up very complicated.

The downside to a Find Task is that it doesn't return all the attribute values, just the columns that it finds results in. The choice is really dependent upon the data source as they both are more suitable under different circumstances.
0 Kudos
MayJeff
Deactivated User
Thanks for your time and your suggestion really help.  I will try the "Find Task". 

May
0 Kudos
BjornSvensson
Esri Regular Contributor
Or if you want to keep using the Query (with a case-insensitive search), then (depending on your database) use something like:
lower([LAND_NAME]) LIKE lower('%[value]%')
0 Kudos
MayJeff
Deactivated User
Thank you for your suggestion.  I tried your code and added it to doQuery function and got error message: [RPC Fault faultString="" faultCode="400" faultDetail="Unable to perform query. Please check your parameters."]

I am not sure I added it to a right line of the code.
    query.where = "lower([LAND_NAME]) LIKE lower('%[value]%')"; 
    dgc.dataField = 'LAND_NAME';
    query.outFields = ["LAND_NAME"],["LAND_CODE"];

Hope to hear from you soon.  Thank you.

May
0 Kudos
EokNgo
by
Deactivated User

    query.outFields = ["LAND_NAME"],["LAND_CODE"];


I believe the syntax for this property is incorrect.
Should be a single array like...
["LAND_NAME", "LAND_CODE"]

Hope that helps.
0 Kudos
MayJeff
Deactivated User
I believe the syntax for this property is incorrect.
Should be a single array like...
["LAND_NAME", "LAND_CODE"]

Hope that helps.


I got it fixed already.  Thank you.
0 Kudos