TOC Control - expand at startup

2940
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
AaronNash
New Contributor
has anyone come up with a resolution for this? This is something I was looking into also

thanks,
  Aaron
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
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
Occasional Contributor II
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);
    }          
   }


Are you meaning the MapManager init?  I tried adding this and nothing happens.

EDIT: never mind I got this fixed!  Since my TOC code wasn't in MapManager I had to move it!
0 Kudos
LeonScott
New Contributor II
I've tried this solution as your suggested, but the TOC still isn't expanding for some reason.  Unfortunately, I haven't gotten very far on this issue lately.  It would be a nice feature to have, but I didn't want to get hung up on it.  Thanks again.


Leon



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
RobertScheitlin__GISP
MVP Emeritus
Leon,

   Strange that you are having trouble with this... There must be a really slow map service in your map. The issue is that the Tree can not have the expand functions called before it is ready, meaning all the leafs are initialized. So if you have a very slow map service in your map then the expand function could be getting called before the tree is ready. You could try another callLater from the first callLater.

Robert
0 Kudos
LeonScott
New Contributor II
That is a possibility...  I don't notice it being particularly slow to load.  I load a few basemaps and an "overlay layer" in my app.  I thought that number of services might contribute to what you are talking about.  So far I've tested not loading the basemaps.  I'll fiddle with overlay to see if that makes a difference.  Thanks again.


Its online @ http://gis.dedham-ma.gov/propertyviewer, if you would like to see what I'm doing with the basemaps. 


Leon




Leon,

   Strange that you are having trouble with this... There must be a really slow map service in your map. The issue is that the Tree can not have the expand functions called before it is ready, meaning all the leafs are initialized. So if you have a very slow map service in your map then the expand function could be getting called before the tree is ready. You could try another callLater from the first callLater.

Robert
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Leon,

   Because you are using the TOC in a custom component, I am not sure when you are calling the expandTOC function, but it must be getting called to soon.
0 Kudos
LeonScott
New Contributor II
Robert,

I have tried calling it in both init() and config() with similar results. I also tried calling it in the mapLoadcomplete() function at one point, but I didn't use the callLater() function. That made the difference. Before I was trying to expand the tree without the use of callLater in the same spot, so like you said it was getting called too soon. Thanks.

Leon


FYI - I am defining the TOC control in the MapManager.mxml like this....


<mx:HBox id="mainBox" width="100%" height="100%" >
.
.
.
<!-- Place Live Maps in Right Panel.... replaces LiveMapsWidget -->
<mx:VBox width="100%" height="225" styleName="TOCStyle" >
<mx:Label text="Live Layers" styleName="SectionTitle" />
<mx:ToggleButtonBar dataProvider="{mapViewStack}" />
<mx:ViewStack id="mapViewStack" width="100%" height="100%" paddingTop="5" paddingRight="5" paddingBottom="5" paddingLeft="5">
<mx:Canvas id="canvasTOC" label="TOC">
<toccomp:TOC id="mapTOC" width="100%" height="100%" useLayerFadeEffect="true" />
</mx:Canvas>
</mx:ViewStack>
</mx:VBox>
.
.
.
</mx:HBox>









Leon, 

Because you are using the TOC in a custom component, I am not sure when you are calling the expandTOC function, but it must be getting called to soon.
0 Kudos
MatthewLawton
Occasional Contributor
I am trying to do the same thing with the VIPER code, which I believe is built off of the Sample Flex Viewer. I copied Robert's code snippet into the MapManager.mxml at the end of the Init funciton, but it didn't seem to do anything either.

I guess I'm not even sure if I am starting in the right place. The path I used for that file in Flash Builder is src/com/esri/solutions.flexviewer/MapManager.mxml. Is that the right one? When I click on Run Index it opens up the application in bin-debug\index.html, but I don't even see any files with today's date in that folder when I view it in Windows Explorer. Is something not getting updated correctly when I compile my application?
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Matthew,

   Here is what you need in the LiveMapsWidget.mxml in the src/com/esri/solutions/esa/widgets/LiveMapsWidget.mxml if you are using the SFV 1.3

//Add this to the init function
callLater(expandTOC);
//Add this new function (make sure you don't add it inside of another function)
private function expandTOC():void
   { 
    if (expanded)
    {
     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