Select to view content in your preferred language

Query Task from one map service but two fields.

2524
3
12-29-2010 10:58 AM
MikeJun
New Contributor II
Hi folks,

I just downloaded 'zoom to query result' from sample code and try to modify for my app. I have one dynamic map service which is served as query task layer. first name field is set for query in rest which I set display field in ArcMap.

I implemented successfully this query by firstname function however I don't know how to write code for another query using different field from the same map service.

In tabnavigator, first tab for query by firstname and second tab for query by team using combo box.

I also wonder if I can execute code right after selecting an item from combo box instead of clicking button.

Thanks!!



<?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"
    styleName="plain"
    >

    <mx:Script>
        <![CDATA[
         import com.esri.ags.controls.InfoWindow;
            import com.esri.ags.Graphic;
            import com.esri.ags.events.MapMouseEvent;
            import com.esri.ags.geometry.Geometry;
            import com.esri.ags.symbol.InfoSymbol;
            import com.esri.ags.tasks.IdentifyParameters;
            import com.esri.ags.tasks.IdentifyResult;
           
            import com.esri.ags.tasks.FeatureSet;
            import com.esri.ags.geometry.MapPoint;
            import mx.controls.Alert;
            import mx.rpc.AsyncResponder;
            import com.esri.ags.geometry.Multipoint;
            import com.esri.ags.tasks.FeatureSet;
           
      
            private function doTeamQuery():void
            {
                queryTask.execute(queryteam, new AsyncResponder(onResult, onFault));
               
               
               
                  function onResult(featureSet:FeatureSet, token:Object = null):void
                   {
                   if (featureSet.features.length == 0)
                       {
                           Alert.show("No name found. Please try again.");
                       }
                       else
                    {
                    var multiPoint:Multipoint = new Multipoint();
           for each (var gra:Graphic in featureSet.features)
              multiPoint.addPoint(MapPoint(gra.geometry));
                           mainMap.extent = multiPoint.extent.expand(1.5);     
                     }
                   }
                  
                  function onFault(info:Object, token:Object = null):void
                  {
                      Alert.show(info.toString());
                  }
             
            }
 
           
            private function doQuery():void
            {
                queryTask.execute(query, new AsyncResponder(onResult, onFault));
               
               
               
                  function onResult(featureSet:FeatureSet, token:Object = null):void
                   {
                   if (featureSet.features.length == 0)
                       {
                           Alert.show("No name found. Please try again.");
                       }
                       else
                    {
                    var multiPoint:Multipoint = new Multipoint();
           for each (var gra:Graphic in featureSet.features)
              multiPoint.addPoint(MapPoint(gra.geometry));
                           mainMap.extent = multiPoint.extent.expand(1.5);     
                     }
                   }
                  
                  function onFault(info:Object, token:Object = null):void
                  {
                      Alert.show(info.toString());
                  }
             
            }

        ]]>
    </mx:Script>


    <!-- start declarations -->
  <esri:SimpleMarkerSymbol id="sfs" style="circle" color="0xFF0000" size="40" alpha="0.5"/>
         
        <esri:QueryTask id="queryTask" showBusyCursor="false" url="http://xxxxxxags/ArcGIS/rest/services/EOC/MapServer/0" />

        <esri:Query id="query" text="{qText.text}" returnGeometry="true" outSpatialReference="{mainMap.spatialReference}">
            <esri:outFields>
             <mx:String>EMPNO</mx:String>
             <mx:String>FNAME</mx:String>
             <mx:String>LNAME</mx:String>
             <mx:String>ADDRESS1</mx:String>
             <mx:String>CITY</mx:String>
             <mx:String>EOC_STATUS</mx:String>
             <mx:String>POSITIONTITLE</mx:String>
             <mx:String>TITLE</mx:String>
             <mx:String>HMPHONE</mx:String>
            </esri:outFields>           
        </esri:Query>
       
        <esri:Query id="queryteam" text="{cbxTeam.text}" returnGeometry="true" outSpatialReference="{mainMap.spatialReference}">
         <esri:outFields>
             <mx:String>EMPNO</mx:String>
             <mx:String>FNAME</mx:String>
             <mx:String>LNAME</mx:String>
             <mx:String>ADDRESS1</mx:String>
             <mx:String>CITY</mx:String>
             <mx:String>EOC_STATUS</mx:String>
             <mx:String>POSITIONTITLE</mx:String>
             <mx:String>TITLE</mx:String>
             <mx:String>HMPHONE</mx:String>
            </esri:outFields>           
        </esri:Query>   

           
<esri:Navigation id="navToolbar" map="{mainMap}"/>

<mx:VBox height="100%" width="100%" verticalGap="0" >
<mx:Canvas id="cvMain" horizontalScrollPolicy="off" verticalScrollPolicy="off"  height="100%" width="100%" borderThickness="1" cornerRadius="10" >
 
     <esri:Map id="mainMap" openHandCursorVisible="false" logoVisible="false" >
      <esri:extent>
      <esri:Extent xmin="7567162" ymin="641343" xmax="7651652" ymax="703119">
                <esri:SpatialReference wkid="2913"/>
            </esri:Extent>
      </esri:extent>

      <esri:ArcGISTiledMapServiceLayer url="http://xxxxxxags/ArcGIS/rest/services/BaseMap/MapServer" />      
      <esri:ArcGISDynamicMapServiceLayer url="http://xxxxxxags/ArcGIS/rest/services/EOC/MapServer" />
           
            <esri:GraphicsLayer id="clickGraphicsLayer" graphicProvider="{queryTask.executeLastResult.features}" symbol="{sfs}"/>
  </esri:Map> 

  <mx:HBox horizontalAlign="left" width="100%" bottom="100" left="5">
   <mx:DataGrid id="resultsGrid" dataProvider="{queryTask.executeLastResult.attributes}" visible="{queryTask.executeLastResult != null}" >
             <mx:columns>
                 <mx:DataGridColumn headerText="ID" dataField="EMPNO"/>
                 <mx:DataGridColumn headerText="first name" dataField="FNAME"/>
                 <mx:DataGridColumn headerText="Last name" dataField="LNAME" />
                 <mx:DataGridColumn headerText="Address" dataField="ADDRESS1" />
                 <mx:DataGridColumn headerText="City" dataField="CITY" />
                 <mx:DataGridColumn headerText="Team" dataField="EOC_STATUS" />
                 <mx:DataGridColumn headerText="EOC TitleE" dataField="PositionTitle" />
                 <mx:DataGridColumn headerText="City Title" dataField="Title" />
                 <mx:DataGridColumn headerText="Hm Phone" dataField="HMPhone" />
             </mx:columns>
   </mx:DataGrid>
   </mx:HBox>

   <mx:HBox horizontalAlign="left" width="100%" height="90" bottom="5" left="5" >
       <mx:TabNavigator id="tabNavigator" width="200" height="100%" tabHeight="30" backgroundColor="0xB2BFC6" >
          <mx:VBox label="Find Member" backgroundColor="0xB2BFC6">
           <mx:Label text="  Enter First name" fontWeight="bold"/>
              <mx:HBox width="100%" height="100%">
               <mx:TextInput width="100%" id="qText" enter="doQuery()" text="John"/>
            <mx:Button label="Query" click="doQuery()"/>
              </mx:HBox>
           
          </mx:VBox>
          <mx:VBox label="Find Team" backgroundColor="0xB2BFC6" horizontalAlign="center" verticalAlign="middle">
           <mx:HBox>
            <mx:ComboBox id="cbxTeam" prompt="select a team" selectedIndex="-1" dropdownWidth="150" horizontalCenter="0" top="20" >
               <mx:dataProvider>
                <mx:Array>
                 <mx:String>Team-A</mx:String>
                 <mx:String>Team-B</mx:String>
                 <mx:String>Team-C</mx:String>
                </mx:Array>
               </mx:dataProvider>
               </mx:ComboBox>
               <mx:Button label="Query" click="doTeamQuery()"/>
           </mx:HBox>          
          </mx:VBox>
       </mx:TabNavigator>
   </mx:HBox>
</mx:Canvas>
</mx:VBox>
</mx:Application>
Tags (2)
0 Kudos
3 Replies
MikeJun
New Contributor II
I solved myself for the first part. Ye~~~. I need to put where clause in Query object so it can query specific field without adding another map service or changing display name field.

I'll be glad if someone knows how to fire up the query right after selecting an item from combo box.

Thanks,

<esri:Query id="queryteam" text="{cbxTeam.text}" where="EOC_STATUS = '{cbxTeam.text}'" returnGeometry="true" outSpatialReference="{mainMap.spatialReference}">
         <esri:outFields>
             <mx:String>EMPNO</mx:String>
             <mx:String>FNAME</mx:String>
             <mx:String>LNAME</mx:String>
             <mx:String>ADDRESS1</mx:String>
             <mx:String>CITY</mx:String>
             <mx:String>EOC_STATUS</mx:String>
             <mx:String>POSITIONTITLE</mx:String>
             <mx:String>TITLE</mx:String>
             <mx:String>HMPHONE</mx:String>
            </esri:outFields>           
        </esri:Query>   

++++++++++++++++++

<mx:ComboBox id="cbxTeam" prompt="select a team" selectedIndex="-1" dropdownWidth="150" horizontalCenter="0" top="20" >
               <mx:dataProvider>
                <mx:Array>
                 <mx:String>A</mx:String>
                 <mx:String>B</mx:String>
                 <mx:String>C</mx:String>
                 <mx:String>D</mx:String>
                 <mx:String>Not Assigned</mx:String>
                 <mx:String>Not Avail</mx:String>
                 <mx:String>Not Avail-B</mx:String>
                 <mx:String>Not Avail-D</mx:String>
                </mx:Array>
               </mx:dataProvider>
              </mx:ComboBox>
0 Kudos
MattiasEkström
Regular Contributor
You could use the change event of the comboBox, something like this:

<mx:ComboBox id="cbxTeam" prompt="select a team" selectedIndex="-1" dropdownWidth="150" horizontalCenter="0" top="20" change="doTeamQuery()" >

The doTeamQuery function will fire up when user selects an item (that isn't already selected).
0 Kudos
MikeJun
New Contributor II
Thanks Mattias! I knew it would be simple like 'change' property. 😄
0 Kudos