Select to view content in your preferred language

Join in Flex

796
5
11-10-2010 12:54 AM
francescodi_vito
Deactivated User
Hi GIS Masters
I have a problem. Development webgis in flex. I want to create a join on the fly in flex between a table and a vector element. Do you know any move towards post or code sample?
Tags (2)
0 Kudos
5 Replies
Drew
by
Frequent Contributor
The easiest way to join data is to do it right in ArcMap, then refresh your map service and clear the rest cache to see the new data added.
I would suggest YouTube and Google for resources on how to join tables using ArcMap.

I have not completely reviewed this video, but the subject sounds like what you need.
http://www.youtube.com/watch?v=i3WLTN25d8Q

Drew
0 Kudos
francescodi_vito
Deactivated User
Hi thanks for your answer, but i know how to do a join :-)!!!!
I have got a widget in flex schedule that allows to make the join on the fly with the wms loaded at the moment

Who cna help me?
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
francesco,


    Currently in the flex api there is now way to do joins though code that I am aware of.
0 Kudos
Drew
by
Frequent Contributor
You could write your own function to join the data I guess.
Below is a sample that appends to a feature set based on some sample data.
It�??s a 1:1 join  and the function is generic enough you could reuse it yourself (see joinData function)

This has not been tested in a live app, but the returned featureSet looks complete.

<?xml version="1.0" encoding="utf-8"?>
<s:Application creationComplete="creationCompleteHandler(event)" xmlns:fx="http://ns.adobe.com/mxml/2009" 
      xmlns:s="library://ns.adobe.com/flex/spark" 
      xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" xmlns:esri="http://www.esri.com/2008/ags" width="755" height="600">
 <fx:Declarations>
  
  <!-- 
   SAMPLE DATA
   This is the data that will be joined to the GIS feature data.
  -->
  <s:ArrayCollection id="sampleData">
   <fx:Object key="Connecticut" annualIncome="50000" averageFamlySize="5"/>
   <fx:Object key="California" annualIncome="75000" averageFamlySize="4"/>
   <fx:Object key="Colorado" annualIncome="60000" averageFamlySize="6"/>
   <fx:Object key="North Carolina" annualIncome="55000" averageFamlySize="3"/>
   <fx:Object key="South Carolina" annualIncome="65000" averageFamlySize="5"/>
  </s:ArrayCollection>
  
  
  <esri:QueryTask            
   id="queryTask"  
   useAMF="false"
   url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5"/>        
  <esri:Query            
   id="query"  
   returnGeometry="true"            
   text="{stateName.text}"            
   outFields='["STATE_NAME","SUB_REGION"]'/>

 </fx:Declarations>
 
 
 <fx:Script>
  <![CDATA[
   import com.esri.ags.FeatureSet;
   import com.esri.ags.Graphic;
   import com.esri.ags.events.QueryEvent;
   import mx.controls.Alert;
   import mx.events.DataGridEvent;
   import mx.events.FlexEvent;
   import mx.events.ListEvent;
   
   protected function creationCompleteHandler(event:FlexEvent):void
   {
    queryTask.addEventListener(QueryEvent.EXECUTE_COMPLETE, onQueryComplete)
   }
   
   private function executeQuery():void
   {
    queryTask.execute(query);
   }
   
   private function onQueryComplete(event:QueryEvent):void
   {
    var joinedResults:FeatureSet = joinData(event.featureSet, "STATE_NAME", sampleData, "key");
    resultsGrid.dataProvider = joinedResults.attributes;
   }
   
   //---------------------------------------------------
   // 1:1 JOINING FUNCTION
   //---------------------------------------------------
   private function joinData(featureSet:FeatureSet, featureSetKeyColumn:String, relatedData:ArrayCollection, relatedDataKeyColumn:String):FeatureSet
   {
    //Loop through each feature.
    for each (var feature:Graphic in featureSet.features)
    {  
     //Loop through related to find a match
     for each (var data:Object in relatedData)
     {
      //add new empty peopertys to the feature
      for (var property:Object in data)
       feature.attributes[property.toString()] = "";
      
      //make both values UPPERCASE to compare
      var featureKeyValue:String = feature.attributes[featureSetKeyColumn].toString().toUpperCase();
      var relatedKeyValue:String = data[relatedDataKeyColumn].toString().toUpperCase();

      //compare
      if (featureKeyValue == relatedKeyValue)
      {
       //assign new value(s)
       for (var prop:Object in data)
        feature.attributes[prop.toString()] = data[prop.toString()].toString();
       
       break; // get out of loop
      }
     }
    }
    return featureSet;
   }
  ]]>
 </fx:Script>
 
  <mx:Panel title="Query Sample" height="300" paddingLeft="10" paddingRight="10" paddingTop="10" paddingBottom="10" left="10" right="10" top="10">
   <mx:HBox>
    <mx:Label text="US state name: " />
    <mx:TextInput id="stateName" text="C" enabled="false" />
    <mx:Button label="Get Details" click="executeQuery();" />
   </mx:HBox>
   <mx:DataGrid id="resultsGrid" width="100%" height="100%">
   </mx:DataGrid>
  </mx:Panel>

 
</s:Application>



Drew
0 Kudos
francescodi_vito
Deactivated User
Thank you very much.
is the development I had imagined. Now I will try to develop it according to my needs. I will keep you updated and other tips are always welcome.
thank you very much
0 Kudos