Select to view content in your preferred language

TOC Control - expand at startup

4106
25
05-05-2010 11:06 AM
LeonScott
Deactivated User
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
MatthewLawton
Deactivated User
Thanks for the suggestion, Robert. Unfortunately it did not work for me. I noticed that when I click Run Index, nothing appears to get updated in the bin-debug folder. I was expecting the LiveMapWidget.swf to get recompiled with my changes, but it still has a date on it from 2009. Either I am not compiling things correctly or I do not have my project set up correctly in Flash Builder, or likely both.
0 Kudos
ChrisMcGovern
Emerging Contributor
Thank you Robert, you post was precisely what i needed.
-chris
mncppc

Guys,

   Here is the solution.

//Add this to the init function
callLater(expandTOC);

//Add this function
                        private function expandTOC():void
   { 
    toc.openItems = toc.dataProvider.source;
    for each(var item:TocMapLayerItem in toc.openItems) {
     if (item.isTopLevel())
      toc.expandItem(item,true,true,true,null);
    }          
   }
0 Kudos
JacksonTrappett
Frequent Contributor
Question on this solution.  I grabbed this solution a while back to expand the first node of my tree and it works great.  It has however introduced a bug.  When I expand the tree using the funciton call, and the tree expands past the end of the box it lives in, the vertical scrollbar doesn't activate.  If I expand the tree manually the scrollbar works fine.
For some reason the box that the tree is in doesn't realize that the tree got too big if I expand it using the toc.expandItem(item,true,true,true,null); call.  Any idea on how I can tell the tree to refresh its scrollbar so that the users can scroll down to see all of the items in the tree?

I have tried all of these in various places including using callLater:
toc.invalidateDisplayList();
toc.validateNow();
toc.validateDisplayList();
toc.invalidateSize();


I have searched extensively for a solution to this issue and found many people who have the issue but no solutions that work.
0 Kudos
LeonScott
Deactivated User
I haven't run into that issue.  I'm only using callLater(expandTOC) and I place the call in the mapLoadComplete event, instead of init()


//map load complete
private function mapLoadComplete(event:MapEvent):void{
        SiteContainer.dispatchEvent(new AppEvent(AppEvent.LAYER_LOADED, false, false, null));
        callLater(expandTOC);
}




Hope this is helpful.


Leon
0 Kudos
JacksonTrappett
Frequent Contributor
Thanks for the reply.  That's actually exactly what I'm doing, and it's working great except for the scrollbar issue.  I don't understand why in Flex, expanding a tree by a function call works different than the built in expansion that's called when the user clicks the expand node on the tree.  I haven't been able to find what the difference is but there must be one because it behaves differently.

Unfortunately, I can't find any other way to expand the tree that will make the scrollbar activate, and I also haven't found any way to activate the scrollbar by a refresh.  The only thing that works is for a user to click the expand node on the tree, but without knowing that, the users just can't see the rest of the tree that is below the bottom of the box.
0 Kudos
LeonScott
Deactivated User
Here is the rest of the relevant code from the MapManager.mxml that I am using, just for comparison.

//init
private function init():void
{
     SiteContainer.addEventListener(AppEvent.CONFIG_LOADED, config);
     .
      .    
      SiteContainer.addEventListener(AppEvent.SHOW_INFOWINDOW, widgetShowInfo);
}


//config
private function config(event:AppEvent):void
{     
      // Get Configuration data
      configData = event.data as ConfigData;

       //Get UI paramaters
      configureUI(configData);
      
  map.addEventListener(MapEvent.LOAD, mapLoadComplete);
.
(Layers added to map in here)
.
      // Populate TOC control w/ live layers
      mapTOC.map = map;
      mapTOC.excludeLayers = getBasemaps();
      mapTOC.excludeGraphicsLayers = true;}
0 Kudos