Select to view content in your preferred language

Pass selected data to new view

628
6
08-20-2013 07:07 AM
ClintonCooper1
Deactivated User
I am trying to build a flex mobile application where after I select a desired feature to edit, it passes that data to a new view for editing.

I am able to get the feature to select using the query method:

public function map_mapClickHandler(event:MapMouseEvent):void
   {
    queryMapClick.geometry = event.mapPoint;
    dataMap.selectFeatures(queryMapClick); 
    myMap.infoWindow.hide();
   }


with the Query defined as:


fx:Declarations>

  <esri:Query id="queryMapClick"
        outFields="[StopId]"
        returnGeometry="false"/>

</fx:Declarations>



I understand how to use the navigator to push the view along with the data to the next view.  My issues, is I am not sure how to tgrab that selected data and get it in a form to get over to the next view.  Is this just a matter of creating a new var for the selected feature's attributes?  If so how do I go about doing that?  Thanks!
Tags (2)
0 Kudos
6 Replies
ClintonCooper1
Deactivated User
Can anyone explain a bit about how query works?  Specifically how to get the selected feature into a variable to pass to a new view?

Clinton
0 Kudos
ClintonCooper1
Deactivated User
ok,after some more research and trial and error, I have gotten it to pass something to the next view using the Query Task Declaration with this code:


<fx:Script>
  <![CDATA[
   import com.esri.ags.events.FeatureLayerEvent;
   import com.esri.ags.events.MapMouseEvent;
   import com.esri.ags.geometry.MapPoint;
   import com.esri.ags.layers.TiledMapServiceLayer;
   
   import mx.controls.Alert;
   import mx.events.FlexEvent;
 
   
   
   public function layerShowHandler(event:FlexEvent):void
   {
    var tiledLayer:TiledMapServiceLayer = event.target as TiledMapServiceLayer;
    myMap.lods = tiledLayer.tileInfo.lods;
   }
   public function map_mapClickHandler(event:MapMouseEvent):void
   {
    // set the selection query based on the click
    
    queryMapClick.geometry = event.mapPoint;
    dataMap.selectFeatures(queryMapClick); // default selectionMethod is FeatureLayer.SELECTION_NEW
    myMap.infoWindow.hide();
   }
   protected function myFeatureLayer_selectionCompleteHandler(event:FeatureLayerEvent):void
   {
    if (event.featureLayer.numGraphics > 0)
    {
     queryTask.execute(queryMapClick);
    }
    else
    {
     Alert.show("Sorry found nothing here...");
    }
   }
  ]]>
 </fx:Script>
 
 <fx:Declarations>
  <esri:QueryTask id="queryTask"
      executeComplete="navigator.pushView(EditorView2, event.featureSet)"
      showBusyCursor="false"
      url="http://rta-gis:6080/arcgis/rest/services/temp/trial/MapServer/0"/>
  <esri:Query id="queryMapClick"
     outFields="[Stopid]"
     returnGeometry="false"/>
 </fx:Declarations>




After I select an item and when it goes to the next view it is shows up as [object:Object] when I run the app.  Am I missing a data bind or is something not defined? 

Here is my code for View2.


<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
  xmlns:s="library://ns.adobe.com/flex/spark" 
  xmlns:esri="http://www.esri.com/2008/ags"
  title="EditorView2">
  
 <fx:Script>
  <![CDATA[
   import com.esri.ags.FeatureSet;
   
   import mx.collections.ArrayList;
   import mx.collections.IList;
   
   [Bindable]
   private var listProvider:IList;
   
   override public function set data(value:Object):void
   {
    super.data = value;
    const featureSet:FeatureSet = value as FeatureSet;
    if (featureSet)
    {
     listProvider = new ArrayList(featureSet.attributes);
    }
   }

  ]]>
 </fx:Script>
 
 <fx:Declarations>
  <!-- Place non-visual elements (e.g., services, value objects) here -->
 </fx:Declarations>
 
 <s:List id="list"
   left="0" right="0" top="0" bottom="0"
   dataProvider="{listProvider}"
   interactionMode="touch"
   labelField="StopID"/>

 <s:Button x="174" y="141" label="Go Back" click="navigator.activeView.navigator.popView()"/>
 
</s:View>
0 Kudos
IsaiahAguilera
Frequent Contributor
Clinton,
You might consider passing the array directly from the pushView function. 
So instead of
navigator.pushView(EditorView2, event.featureSet)

you could use
navigator.pushView(EditorView2, event.featureSet.attributes)


Another solution albeit a more involved one would be to use a sort of MVC solution and declare an array in a model which you could then reference directly from multiple views. So on your execute complete of the query you could set the public array in your model equal to your event attributes. This way might require more explaining if interested but could save some headaches in the long run.
0 Kudos
KomanDiabate
Deactivated User
I have used  FindTask to do similar concept, I think you need to send the queryResult to View2 using the pushView Method.

mapView.pushView(map, findTaskResults, null, null);


Or

executeComplete="navigator.pushView(QueryResultsView, event.featureSet)"



Check this forum also:

http://forums.arcgis.com/threads/89899-Flex-Mobile-FindTask-amp-SplitViewNavigator
0 Kudos
ClintonCooper1
Deactivated User
Clinton,
You might consider passing the array directly from the pushView function. 
So instead of
navigator.pushView(EditorView2, event.featureSet)

you could use
navigator.pushView(EditorView2, event.featureSet.attributes)


Another solution albeit a more involved one would be to use a sort of MVC solution and declare an array in a model which you could then reference directly from multiple views. So on your execute complete of the query you could set the public array in your model equal to your event attributes. This way might require more explaining if interested but could save some headaches in the long run.


I would be interested in hearing more about the MVC solution.  I think I understand where you are going with it, but an explanation and maybe point me to an example of what you mean would be great!

Clinton
0 Kudos
IsaiahAguilera
Frequent Contributor
Sure,
MVC stands for Model-View-Controller it's a coding practice used by many different languages. There are different frameworks you can use to accomplish this. If you would like to just use the model portion you could avoid the framework part although it would be beneficial for you to try the whole concept. For the model portion you would create an action script class file named model.as then you could create a singlton instance of it which would hold all the variables you wanted to use globally. You could then reference or bind to them anywhere in your app. If you learn controllers it's like the model but instead of variables it holds the functions. It's definitely something that can take your coding to the next level. The best examples and framework for flex I have found is here.

http://thunderheadxpler.blogspot.com/2011/10/micro-architecture-for-flex-ria-and-rma.html

Mansour Raad explains it very well. Check it out.
0 Kudos