Select to view content in your preferred language

pass map between views in a ViewNavigatorApplication

994
6
03-15-2013 07:03 AM
MarkYerington
Frequent Contributor
What I am trying to do is develop a simple mobile application in Flash 4.6.  I am trying to add layers to a main view based on what is selected in the Table of contents view in a second view.  It is a series of check boxes that I would like to select maps and load those into the main map.  I have most of the functionality worked out I just can't get the map reference to pass to the other views.
Tags (2)
0 Kudos
6 Replies
ChrisNorth
Esri Contributor
Do you have two separt map controls in the flex application?  If so,  one method is to loop through each layer in map 1 and add the layers one by one to map 2. I do this for a print preview.  Something like...

private function cloneMap():void
{
  layerCount = 0;
  for (var i:Number = 0; i < map1.layerIds.length; i++)
  {
    var layer:Layer = map1.getLayer(map.layerIds);
    if (layer is ArcGISDynamicMapServiceLayer)
    {
      layerCount = layerCount + 1;
      var dynamicLayer:ArcGISDynamicMapServiceLayer = layer as ArcGISDynamicMapServiceLayer;
      var newdl:ArcGISDynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer(url, proxyurl, token);
      newdl.proxyURL = dynamicLayer.proxyURL;
      newdl.token = dynamicLayer.token;
      newdl.alpha = dynamicLayer.alpha;
      newdl.visible = dynamicLayer.visible;
      newdl.visibleLayers = dynamicLayer.visibleLayers;// visiblelyrs;
      newdl.layerDefinitions = dynamicLayer.layerDefinitions;
      newdl.name = dynamicLayer.name;
      newdl.addEventListener(LayerEvent.LOAD, layerLoadComplete);
      map2.addLayer(newdl);
    }
   //... you need to handle all layer types individually, and figure out what you need to transfer.  
}

Chris
0 Kudos
MarkYerington
Frequent Contributor
No I just have one map control.  What it essentially is, is that I have a map control on the Map View Tab. Then on the TOC tab there are a series of check boxes that I would like to select the layers that are added to the Map Control on a map view tab.  My problem is that I cannot reference the Map Control on the map view tab of the application.
0 Kudos
JustinWilson
Occasional Contributor
In the control you want the map to be used add code similar to:

import com.esri.ags.Map;

private var _map:Map

public function set Map(value:Map):void{
     _map = value;
}


Then, from your application - pass a reference to the Map property of your control.  Now you can add and remove what you want from your map with your checkbox controls.
tab.Map = myMap


It's difficult to solve without knowing more about your application, but I hope this might help.
0 Kudos
MarkYerington
Frequent Contributor
Ok don't think I have this set up right.  I have two views in a tabbed view navigator mobile app.  I have been trying to pass the map from the Map View to the TOC view so I can turn layers on and off then push back to the map view.  Here are my functions.

Map View Function

private function onClick(event:MouseEvent):void {
   
navigator.pushView(views.ToolsView,myMap);
   
   
}

"myMap" is the id of the map on the map view.

TOC View Functions

protected var map:Map;
override public function set data(value:Object):void{
    super.data = value;
    map = value as Map;
   }


Trying to add layer to map
if (cb.selected)
    {
     control = new ArcGISDynamicMapServiceLayer("http://xxxxxxxxxx/arcgis/rest/services/MAGIC_Landbase/MuscatineCo_SurveyControl/MapServer");
    
     control.visible = true;
     map.addLayer(control)
}

It always errors on the map.addLayer saying cannot access property with null object reference.  I am very new to the mobile framework, so trying to use the examples that were posted.
0 Kudos
YannCabon
Esri Contributor
Hi,

Can you verify that "myMap" in not null before calling pushView ?
0 Kudos