Peter,

 

Maybe this is no help but I reset the each node of the tree/group to
enable/disable by its id. 

Because all my layer names are unique & descriptive I use the layer name as
the id for the node as well as the name and text.

 

So creating the node:

 

text        : layerGroup[3],

expanded: false,

children: 

[{

nodeType: "gx_layer",

                layer      : layer1,

                text        : layer1,

                isLeaf    : true,

                disabled :   false,

                id            :  layer1

},{

                nodeType: "gx_layer",

                layer      : layer2,

                text        : layer2,

                isLeaf    : true,

                disabled :   false,

                id            :  layer2

}]...etc

 

Then when the group is loaded/rendered, I have a load listener setup on each
node. 

"load":function(node){setLayerControlSection(node.text);},

 

This is a function that first checks the current zoom level of the
openlayers map then it steps though all the nodes in the group and sets the
node to enable/disable depending if the node should be enabled at the
current map scale. This is an initializing process.

 

I use the following to disable the node:
controlPanels.tree.getNodeById(layer2).disable();

I use the following to enable the node:
controlPanels.tree.getNodeById(layer2).enable();

 

In addition, when the user changes the map scale I have a zoomEvent
registered that gets the zoom level and steps through all the nodes in the
tree and does the same to each node.

 

This does not do anything more than manipulate the tree nodes and the layer
visibility is automatically controlled by the remote WMS service as the
scale changes.  

 

The way I check that the layer should or should not be visible at different
zoom levels is to build an array of zoom levels (low-high) based on what the
server tells me about each layer's visibility when I initialize the map. 

 

However, if I wanted to control scale display rules in the application I
could also include layer2.setVisibility(true/false) in this function and the
zoomEvent as well.

 

Anyway, it works for me. Hope it helps.

 

Cheers,

Brad....

 

                                                                

 

 

 

From: users-boun...@geoext.org [mailto:users-boun...@geoext.org] On Behalf
Of peter.je...@tba.llv.li
Sent: Friday, 30 December 2011 11:38 PM
To: users@geoext.org
Subject: [Users] Manipulating group layers in tree - set default sublayers
on or off

 

Hi all

 

I have a  question manipulating a layer tree.

I do the following:

 

1) I create a group Layer

2) then i create a TreeNode for the layer

3) In manipulate the layer tree the way that on everey 'checkchange'  of the
grouplayer, it should switch off subayers, that should be unvisible by
default. To to this, I run through the subnodes, check if the sublayer
should be visible or not, an use the getUI().toggleCheck(false) method the
switch a sublayer off.

 

Maybe i did this in a complicated, but it works so far. My problem is, that
on every call of getUI().toggleCheck , the map seems to be updated. At least
there are scores of WMS-Requests on the server.

So my question: is there a better way  to achieve the behavior I want? Or is
there a way to stop map updates, until all toogles of a group layer have
done?

 

Any help would be appreciated

Regards

Peter

 

Here is the code I use

 

 

 

 

1)

     var groupLayer = new OpenLayers.Layer.WMS(this.gs_tree[i].display_name,

         'http://xxxx.xx.xx/wms',

         {  layers: mylayers,       // array of sublayers

            transparent: true,

            format: "image/png"

         },

         { singleTile : true, 

            ratio : 1, 

            buffer : 0,

            visibility : false,

            isBaseLayer : false

         }

     );

 

2) 

 

    var groupLayerNode = new GeoExt.tree.LayerNode({

        layer: groupLayer,

        text : display_name,

        leaf: false,

        expanded: false,

        iconCls: 'x-tree-node-icon',

        checked: false,  

        isLeaf: false,

        loader: {

          param: "LAYERS"

        }

    });

 

3)

   var rootNode=layerTree.getRootNode();

   rootNode.eachChild(function (myNode) {

     myNode.collapse(); 

     myNode.on('checkchange', function(anode, e){

                        if (e) { 

                               myNode.expand();

                                myNode.eachChild(function (n) { 

 

                                if (!map.isDefaultOn(n.parentNode.text,
n.item)) { 

                                      n.getUI().toggleCheck(false);    

                                }

                                 n.enable(); 

                               });

                              } 

                              else {

                               myNode.collapse(); 

                               myNode.eachChild(function (n) { 

                                n.disable(); 

                               });

 

                              }

                    });

 

     myNode.eachChild(function (n) { 

                  layerText = geoshop.getLayerText(n.text);
n.setText(layerText); 

                  n.disable();

   });

});

 

 

 

 

_______________________________________________
Users mailing list
Users@geoext.org
http://www.geoext.org/cgi-bin/mailman/listinfo/users

Reply via email to