TOC Control - expand at startup

2973
25
05-05-2010 11:06 AM
LeonScott
New Contributor II
I want the TOC control to be expanded on startup of my app based on the Sample Flex Viewer.  I've tried calling expandChildrenOf() and expandItem() methods for the control in the config function of the MapManager, but its had no effect.  Any ideas? 

Thanks.


Leon
Tags (2)
0 Kudos
25 Replies
MarcCavallaro
New Contributor III
Add the following in red to this code string in the config.xml within the widgets block.

<widget label="Live Maps" preload="maximized" icon="com/esri/solutions/flexviewer/assets/images/icons/i_layers48.png" menu="menuMap" config="com/esri/solutions/flexviewer/widgets/LiveMapsWidget.xml">com/esri/solutions/esa/widgets/LiveMapsWidget.swf</widget>
0 Kudos
LeonScott
New Contributor II
Thanks for the response. I'm not using the LiveMapsWidget though. I've placed the TOC component in the MapManager.

Add the following in red to this code string in the config.xml within the widgets block. 

<widget label="Live Maps"   preload="maximized" icon="com/esri/solutions/flexviewer/assets/images/icons/i_layers48.png" menu="menuMap" config="com/esri/solutions/flexviewer/widgets/LiveMapsWidget.xml">com/esri/solutions/esa/widgets/LiveMapsWidget.swf</widget>
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Bluesalmon,

   Is it possible that you are trying to call the expand method before the tree is populated? That would be the first thing I would check.
0 Kudos
LeonScott
New Contributor II
I'm calling it at the very end of the config function, like this.  The layers are getting added to the map prior this in the same function.

//config
private function config(event:AppEvent):void
{    

     .
     .
     .

     // Populate TOC control w/ live layers
     mapTOC.map = map;
     mapTOC.excludeLayers = getBasemaps();
     mapTOC.excludeGraphicsLayers = true;
     mapTOC.expandChildrenOf(mapTOC.firstVisibleItem, true);
}

Also, I read this in the Flex Language Reference that might be part of the issue:

If you set dataProvider and then immediately call expandChildrenOf() you may not see the correct behavior. You should either wait for the component to validate or call the validateNow() method.

Thank you for the responses!

Leon
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Bluesalmon,

   So have you tried the validatenow? Maybe validatenow in combination with CallLater.
0 Kudos
LeonScott
New Contributor II
I tried different combinations of ValidateNow() and CallLater() with no results.  You were right though, I was calling it in the wrong place.  I call mapTOC.ExpandChildrenOf(....) in the mapLoadComplete function and success!  So I end up with something like this:

private function config(event:AppEvent):void
{
   .
   .
   map.addEventListener(MapEvent.Load, mapLoadComplete);
   .
   .
   .
   // Populate TOC control w/ live layers
   mapTOC.map = map;
   mapTOC.excludeLayers = getBasemaps();
   mapTOC.excludeGraphicsLayers = true;
}


//map load complete
private function mapLoadComplete(event:MapEvent):void
{
   SiteContainer.dispatchEvent(new AppEvent(AppEvent.LAYER_LOADED, false, false, null));
   mapTOC.expandChildrenOf(mapTOC.firstVisibleItem, true);
}
0 Kudos
LeonScott
New Contributor II
I called mapTOC.ExpandChildrenOf(....) in the mapLoadComplete function and success! ... or so I thought.  It worked for a little while, until I exported to release build and the TOC no longer expanded.  I must have been getting lucky with timing of the map finishing loading the TOC being populated when I was running it from Flex Builder.  Weird.

I have tried ValidateNow() in the config function and it seems to really screw up the load process.  My services don't appear, unless I manually zoom and my disclaimer window is off centered.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Leon,

  Are you calling the validate now on the toc control?

mapTOC.validateNow();
0 Kudos
LeonScott
New Contributor II
Yes, that is how I called ValidateNow.  I'm trying to think of where the best place to call mapTOC.expandChildrenOf() or perhaps a listener of some sort is needed.
0 Kudos