[Users] Capturing Name of childnode clicked fromGeoExt.tree.LayerNode

Andrew Stewart Andrew.Stewart at reddeer.ca
Tue Dec 28 19:03:02 CET 2010


Thanks for your suggestion.. I tried to use this method but for some reason when checking a childnode the event is not firing. I seem to have found an alternate way to do this by adding the checkchange listener directly to my treepanel and then using the ID property to get the name of the childnode.. but your method seems much easier. Do you know why my setup might prohibit the event from firing correctly when checking/unchecking a childnode? Here is my code.. appreciate your assistance and if I can't do it this way I guess I will just stick to how I've got it.. works anyway but it's not pretty :)


var layerRoot_Legend = new Ext.tree.TreeNode({
enableDD: true,
loaded: true,
expanded: true
});

var layerTree_Legend = new Ext.tree.TreePanel({
root: layerRoot_Legend,
enableDD: true,
applyLoader: true,
height: 372,
width: 230,
autoScroll: true,
rootVisible: false
}}


   //AOIs layerList
        layerList_AOIs = new GeoExt.tree.LayerNode({
        "layer": layer_AOIs,
        "isLeaf": true,
        "preloadChildren": true,
        "checked": false,
        "enableDD": true,
        "cls": "rootnode",
        "singleClickExpand": true,
        "listeners":
        {
            'checkchange' :  function(node, checked)
                {
                    // If a parent node is unchecked, uncheck all the children
                    if (node.getUI().isChecked()) {
                    node.expand();
                    }
                    if (!node.getUI().isChecked()) {
                    node.collapse();
                    }
                },
             'load' : function(e) {
             if (bool_aois == false)
                {
                    //change icon of childNodes to GetLegendGraphic from WMS + node text attribute
                    var count = (e.childNodes.length -1);
                    while (count >= 0)
                        {
                            var label = e.childNodes[count].text;
                            var fixed_label = label.replace(/_/g,' ');
                            e.childNodes[count].setText("<img src='http://localhost/WebServices/Request.aspx?request=GetLegendGraphic&version=1.1&format=image/png&style=&layer="+label + "'/>" + ' ' +fixed_label);
                            count -=1;
                        }
                    bool_aois = true;
                }
             else
             {
                //do nothing
             }
             }
  },
        "loader": {
            "param": "LAYERS",
            baseParams:{
                listeners:{checkchange:function(node,checked){
                 alert('making it here');
                  }}
                 }
        });


layerRoot_Legend.appendChild(layerList_AOIs);

________________________________
From: Matt Priour [mailto:mpriour at kestrelcomputer.com]
Sent: December 28, 2010 10:49 AM
To: Andrew Stewart; users at geoext.org
Subject: Re: [Users] Capturing Name of childnode clicked fromGeoExt.tree.LayerNode

You could add this to the loader at the end of your configuration:

...
"loader": {
            "param": "LAYERS",
            baseParams:{
                listeners:{checkchange:function(node,checked){
                  .... Do Something with checked child node information ....
                               }}
                 }
        }

'baseParams' are applied to each child node created by the loader.

Matt Priour
Kestrel Computer Consulting

From: Andrew Stewart<mailto:Andrew.Stewart at reddeer.ca>
Sent: Tuesday, December 28, 2010 11:16 AM
To: users at geoext.org<mailto:users at geoext.org>
Subject: [Users] Capturing Name of childnode clicked fromGeoExt.tree.LayerNode

I'm sure this can be done but I'm having a hell of a time accomplishing this. I need to know which childnode has been clicked from my layerNode (which is added to a layertree root node). Except I am using grouped layers through openlayers so I am having a hard time pulling out the name of one of these child nodes. Is there any event I can add to the below code to tell me the name of the childnode when it is clicked and not the root node? Appreciate any advice.

          //AOIs layerList
        layerList_AOIs = new GeoExt.tree.LayerNode({
        "layer": layer_AOIs,
        "isLeaf": true,
        "preloadChildren": true,
        "checked": false,
        "enableDD": true,
        "cls": "rootnode",
        "singleClickExpand": true,
        "listeners":
        {
            'checkchange' :  function(node, checked)
                {
                    // If a parent node is unchecked, uncheck all the children
                    if (node.getUI().isChecked()) {
                    node.expand();
                    }
                    if (!node.getUI().isChecked()) {
                    node.collapse();
                    }
                },
             'load' : function(e) {
             if (bool_aois == false)
                {
                    //change icon of childNodes to GetLegendGraphic from WMS + node text attribute
                    var count = (e.childNodes.length -1);
                    while (count >= 0)
                        {
                            var label = e.childNodes[count].text;
                            var fixed_label = label.replace(/_/g,' ');
                            e.childNodes[count].setText("<img src='http://localhost/WebServices/Request.aspx?request=GetLegendGraphic&version=1.1&format=image/png&style=&layer="+label + "'/>" + ' ' +fixed_label);
                            count -=1;
                        }
                    bool_aois = true;
                }
             else
             {
                //do nothing
             }
             }
  },
        "loader": {
            "param": "LAYERS"
        }
        });





________________________________
This e-mail is intended for the original recipient(s) only. If you have received it in error, please advise the sender and delete this message.

________________________________

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

________________________________
[This message has been scanned for security content threats and viruses.]

[The City of Red Deer I.T. Services asks that you please consider the environment before printing this e-mail.]



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.geoext.org/pipermail/users/attachments/20101228/77e7f54d/attachment-0001.htm 


More information about the Users mailing list