Collapse all layers at start in agsjs.dijit.TOC

7423
15
09-06-2012 02:06 AM
ChristianLutz
New Contributor III
Hi all,

I am using this TOC http://gmaps-utility-gis.googlecode.com/svn-history/r354/trunk/agsjs/docs/toc/examples.html
Could someone tell me how to collapse ALL LAYERS at start or give me a hint?

Thanks a lot!!
0 Kudos
15 Replies
ErikkRoss
New Contributor
Just wanted to say that this worked perfectly. Exactly what I wanted to do! Thanks! 🙂


ok - cracked the code to get all groups collapsed - as in screenshot

[ATTACH=CONFIG]18426[/ATTACH]

In the postcreate function find and alter as below

           if (this.data._subLayerInfos) {
                //acm added to collapse groups at the start
                this.toggler.hide()
                //end acm addition


and a bit later

           //ACM also changed this line to get groups initial expand set
                //dojo.addClass(this.iconNode, a ? "dijitTreeExpandoOpened" : "dijitTreeExpandoClosed")
                dojo.addClass(this.iconNode, a ? "dijitTreeExpandoClosed" : "dijitTreeExpandoClosed")



So far it appears to work.  The second part could be neater, but doing it this way you can see it has been changed to always return "dijitTreeExpandoClosed"

ACM
0 Kudos
AdrianMarsden
Occasional Contributor III
Whilst it is nice you got my hack working, I should have reposted here earlier to say I got nliu's method working fine, and now don't have any changes to the stock code (apart from one tiny style change, but that is just cosmetic) - so it'll be worth trying the developer's method again, if you haven't already done so.  It'll make it much easier when new code is released (like it just has been)

ACM
0 Kudos
NianweiLiu
Occasional Contributor II
Is there any way to have the map service layer initially expanded but all collapsible groups within the map service (unique value renderers and group layers) collapsed?

Yes, with the latest built posted on http://www.arcgis.com/home/item.html?id=9b6280a6bfb0430f8d1ebc969276b109 it is possible to retrieve individual node widget by it's underline layer. All you need to do is to find the list of layers based on whatever criteria you have, then find it's corresponding node in the TOC, and do something with it (collapse, expand, show, hide), after the TOC is loaded.
0 Kudos
KevinMacLeod1
Occasional Contributor III
If I may I ask a related question...

Has anyone set Nianwei's AGS TOC widget to not collapse layer Groups when it is turned off? In other words, I have a dynamic service with around 100 layers. I've grouped these into a few groups which works great with the AGS widget, which groups them hierarchically just like ArcMap.

Now I am wondering how to make it NOT automatically collapse the groups when I turn them off. We want them to stay expanded, unless the user clicks the little "+" button. We do however want it to collapse/expand with the "+" automatically, as it does now by default.

I have tinkered with the 2.05 TOC.js code and I believe the relevant block of code is below but I have not succeeded. I set a lot of those visible items to true, set both expandos to "open" etc to no avail yet. Anyone else done this or know how?

var show = this.data.visible;
    // if it is a group layer and no child layer is visible, then collapse
    
    if (this.data._subLayerInfos) {
      var noneVisible = true;
      dojo.every(this.data._subLayerInfos, function(info) {
        if (info.visible) {
          noneVisible = false;
          return false;
        }
        return true;
      });
      if (noneVisible) 
        show = false;
    }
    
    if (this.data.collapsed) 
      show = false;
    if (this.iconNode && this.iconNode.src == this.blank) {
      dojo.addClass(this.iconNode, 'dijitTreeExpando');
      dojo.addClass(this.iconNode, show ? 'dijitTreeExpandoOpened' : 'dijitTreeExpandoClosed');
    }
    if (this.containerNode) 
      dojo.style(this.containerNode, 'display', show ? 'block' : 'none');
    
    if (this.rootLayerTOC.toc.style == 'standard' && this.iconNode && this.checkNode) {
      dojo.place(this.iconNode, this.checkNode.domNode || this.checkNode, 'before');
    }
0 Kudos
NianweiLiu
Occasional Contributor II

TOC widget to not collapse layer Groups when it is turned off?

By default, if a group layer is turned off, or there is no any sub layer visible, it will be collapsed, this is a desirable behavior to minimize vertical scrolling. With the most recent built (as of 8/5) there is a new option 'autoToggle' in the constructor that disables this behavior.
http://www.arcgis.com/home/item.html?id=9b6280a6bfb0430f8d1ebc969276b109

Notice when you click "insert a new layer", the new TOC for the census layer has 'autoToggle'=false, and it will not automatically expand/collapsed based on the current visibility of the group/sub layers.
0 Kudos
SmithaNivesh
New Contributor

Hi,

Use these tags in layerInfo:

collapsed: true,

autoToggle: false

Thanks.

0 Kudos