Ok this really has me stumped...I used the cascade method() and <font face="Arial" size="2">TreePanel.getNodeById</font> as Matt suggested, thank you very much for that by the way. They helped me a great deal ^.^<br><br>However, it seems cascade will only traverse leaf nodes if one of them is checked. If none of the leafs have been checked, cascade rudely ignores them :(<br>
<br>I need some tips on how to force a cascade on leafs which have never been switched on. Thanks for your time and kind responses :)<br><br>Here is some code that I have wrote, I am sending the relevant snippet:<br><br>
function checkHandler(item, checked) {<br> var tibetContainer, chineseContainer;<br> <br> if(item.text == 'Tibetan'){<br> <br> tibetContainer = new Ext.tree.TreeNode({<br>
text: "Tibetan Labels",<br> expanded: true,<br> id: 'tibet'<br> });<br><br> tibetContainer.appendChild(new GeoExt.tree.OverlayLayerContainer({<br>
text: "Lands (Tibetan trans)",<br> layerStore: tibLands,<br> expanded: false,<br> loader: {param: "LAYERS"}<br>
}));<br><br> tibetContainer.appendChild(new GeoExt.tree.OverlayLayerContainer({<br> text: "Natural Selection (Tibetan trans)",<br> layerStore: tibNaturalLayers,<br>
expanded: false,<br> loader: {param: "LAYERS"}<br> }));<br><br> tibetContainer.appendChild(new GeoExt.tree.OverlayLayerContainer({<br>
text: "Points of Interest (Tibetan trans)",<br> layerStore: tibPointOfInterest,<br> expanded: false,<br> loader: {param: "LAYERS"}<br>
}));<br><br> if(<a href="http://layerRoot.lastChild.id">layerRoot.lastChild.id</a> != 'tibet'){<br> layerRoot.appendChild(tibetContainer);<br>
<br> if(layerRoot.getOwnerTree().getNodeById('chinese')){<br> var j = 0;<br> var selectedLayers = new Array();<br>
var layersChecked = new Array();<br> while(layerRoot.getOwnerTree().getNodeById('chinese').hasChildNodes()){<br> layerRoot.getOwnerTree().getNodeById('chinese').firstChild.eachChild(function(node) { <br>
if (node.isLeaf() && node.ui.isChecked()) { <br> layersChecked[j] = node.text; <br> node.ui.toggleCheck(false);<br>
j++;<br> }//end if <br> <br> return layersChecked;<br> });//end cascade<br>
<br> layerRoot.getOwnerTree().getNodeById('chinese').removeChild(layerRoot.getOwnerTree().getNodeById('chinese').firstChild);<br> }//end while<br>
layerRoot.removeChild(layerRoot.getOwnerTree().getNodeById('chinese'));<br><br> selectedLayers = layersChecked;<br> if(layerRoot.getOwnerTree().getNodeById('tibet').hasChildNodes()){<br>
var i = 0;<br> var children = new Array();<br> for(var c = 0; c < layerRoot.getOwnerTree().getNodeById('tibet').childNodes.length; c++){<br>
//children[c] = layerRoot.getOwnerTree().getNodeById('tibet').childNodes[c].id;<br> //alert(children[c]);<br> children[c] = layerRoot.getOwnerTree().getNodeById('tibet').childNodes[c].id;<br>
alert(children[c]);<br> <br> <br> <br> layerRoot.getOwnerTree().getNodeById('tibet').childNodes[c].cascade(function(node) { <br>
alert(layerRoot.getOwnerTree().getNodeById('tibet').firstChild.text + " and " + layerRoot.getOwnerTree().getNodeById('tibet').childNodes[c].text); <br>
alert(node.text); //This is how I know it is not traversing to the leafs :( <br> if (node.isLeaf() && (node.ui.isChecked() == false)) { <br>
alert(node.text + "not checked");<br> if (node.text == selectedLayers[i]) {<br> node.ui.toggleCheck(true);<br>
alert(selectedLayers[i]);<br> i++;<br> }//end if<br> }//end if <br>
<br> });//end cascade<br> }//end for<br> }//end if<br> }//end if(layerRoot.getOwnerTree().getNodeById('chinese'))<br>
}//end if(<a href="http://layerRoot.lastChild.id">layerRoot.lastChild.id</a> != 'tibet')<br> }//end if(item.text == 'Tibetan')<br><br><br><br><br>elshae<br><br><br>
<br><br><div class="gmail_quote">On Wed, Oct 20, 2010 at 2:29 PM, Matt Priour <span dir="ltr"><<a href="mailto:mpriour@kestrelcomputer.com">mpriour@kestrelcomputer.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div style="padding-right: 10px; padding-left: 10px; padding-top: 15px;" name="Compose message area">
<div><font face="Arial" size="2">You are using some very fragile methods
there.</font></div>
<div><font face="Arial" size="2">Rather than depending on lastChild & firstChild
and the fact that they may or may not only contain leaf nodes, etc..., you
should be using the standard ExtJS TreeNode walking functions.</font></div>
<div><font face="Arial" size="2"></font> </div>
<div><font face="Arial" size="2">node.bubble</font></div>
<div><a title="http://dev.sencha.com/deploy/dev/docs/?class=Ext.tree.TreeNode#Ext.data.Node-bubble
CTRL + Click to follow link" href="http://dev.sencha.com/deploy/dev/docs/?class=Ext.tree.TreeNode#Ext.data.Node-bubble" target="_blank">http://dev.sencha.com/deploy/dev/docs/?class=Ext.tree.TreeNode#Ext.data.Node-bubble</a></div>
<div><font face="Arial" size="2"></font> </div>
<div><font face="Arial" size="2">node.cascade</font></div>
<div><a title="http://dev.sencha.com/deploy/dev/docs/?class=Ext.tree.TreeNode#Ext.data.Node-cascade
CTRL + Click to follow link" href="http://dev.sencha.com/deploy/dev/docs/?class=Ext.tree.TreeNode#Ext.data.Node-cascade" target="_blank">http://dev.sencha.com/deploy/dev/docs/?class=Ext.tree.TreeNode#Ext.data.Node-cascade</a></div>
<div> </div>
<div><font face="Arial" size="2">node.eachChild</font></div>
<div><a title="http://dev.sencha.com/deploy/dev/docs/?class=Ext.tree.TreeNode#Ext.data.Node-eachChild
CTRL + Click to follow link" href="http://dev.sencha.com/deploy/dev/docs/?class=Ext.tree.TreeNode#Ext.data.Node-eachChild" target="_blank">http://dev.sencha.com/deploy/dev/docs/?class=Ext.tree.TreeNode#Ext.data.Node-eachChild</a></div>
<div> </div>
<div><font face="Arial" size="2">Bubble walks up the tree toward the root
node, starting with the node it is called on</font></div>
<div><font face="Arial" size="2">Cascade walks down the tree (through each child
branch as well) starting with the node it is called on</font></div>
<div><font face="Arial" size="2">EachChild iterates over ONLY the child nodes of the
node it is called on. It will NOT continue any further down the child branches
and will not include the node it is called on</font></div>
<div><font face="Arial" size="2"></font> </div>
<div><font face="Arial" size="2">You should be able to use these functions to
collect the information you need from your layer tree (node.getUI().isChecked(),
etc..) and then reapply it to the tree formed with the different layer
store.</font></div>
<div><font face="Arial" size="2"></font> </div>
<div><font face="Arial" size="2">If you want to start at a certain node other than
the Root Node, then assign that node an id and find it in the tree panel using
the TreePanel.getNodeById function</font></div>
<div><a title="http://dev.sencha.com/deploy/dev/docs/?class=Ext.tree.TreePanel#Ext.data.Tree-getNodeById
CTRL + Click to follow link" href="http://dev.sencha.com/deploy/dev/docs/?class=Ext.tree.TreePanel#Ext.data.Tree-getNodeById" target="_blank">http://dev.sencha.com/deploy/dev/docs/?class=Ext.tree.TreePanel#Ext.data.Tree-getNodeById</a></div>
<div> </div>
<div><font face="Arial" size="2">Matt Priour</font></div>
<div><font face="Arial" size="2">Kestrel Computer Consulting</font></div>
<div><font face="Arial" size="2"></font> </div>
<div style="font: 10pt Tahoma;">
<div><br></div>
<div style="background: none repeat scroll 0% 0% rgb(245, 245, 245);">
<div><b>From:</b> <a title="itintern12@gmail.com" href="mailto:itintern12@gmail.com" target="_blank">IT Intern</a> </div>
<div><b>Sent:</b> Wednesday, October 20, 2010 12:02 PM</div>
<div><b>To:</b> <a title="users@geoext.org" href="mailto:users@geoext.org" target="_blank">users@geoext.org</a> </div>
<div><b>Subject:</b> Re: [Users] Keeping Selected Layers When Replacing Child
Nodes</div></div></div><div><div></div><div class="h5">
<div><br></div>Ok so far I have been able to find a way to access the properties
of nodes...now I am struggling to find out if there is anyway to access the
properties of the node's leafs? If anyone know please help me, I think if
I have that I will be able to carry out the desired task :)<br><br>Some code of
my approach:<br><br>var i;<br>
var j = 0;<br>
var selectedLayers = new Array();<br>
while(layerRoot.lastChild.hasChildNodes()){<br>
alert(layerRoot.lastChild.firstChild.childNodes.length); //This returns 0, but
the childNodes here are leafs :(<br>
for(i = 0; i <
layerRoot.lastChild.firstChild.childNodes.length; i++){<br>
if(layerRoot.lastChild.firstChild.childNodes[i].isSelected()){<br>
selectedLayers[j] =
layerRoot.lastChild.firstChild.childNodes[i].attributes.text;<br>
alert(selectedLayers[j]);<br>
j++;<br>
}
<br>
}<br>
<br>
layerRoot.lastChild.removeChild(layerRoot.lastChild.firstChild);<br>
}<br>
layerRoot.removeChild(layerRoot.lastChild);
<br>
}<br><br>Thanks for taking the time to
consider my questions,<br><br>elshae<br><br>
<div class="gmail_quote">On Tue, Oct 19, 2010 at 4:17 PM, IT Intern <span dir="ltr"><<a href="mailto:itintern12@gmail.com" target="_blank">itintern12@gmail.com</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="padding-left: 1ex; margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204);">Hello
GeoExt Friends,<br><br>So I have been using the GeoExt and Ext libraries to
develop my map browser and now there's a feature I'd like to have, but don't
know how to go about it :)<br><br>So far everything is working. What I
have is a tree panel that when a menu is clicked a parent node with layer
containers is added to the tree. The layers in these containers are in
different languages, so as the user toggles between the languages in the menu,
it be nice if the layers in the previous language correspond to the language
that is currently selected. I hope you will understand what I am asking
to do. I guess a good starting point would be, is there a way to "get"
which layers are selected in a layer container? Thanks for your time,
below is some relevant code:<br><br>//So there are many layers, one each per
language...<br><br>var chn_townships = new
OpenLayers.Layer.WMS(<br>
"Townships (Chinese trans)", "<a href="http://localhost:8080/geoserver/wms" target="_blank">http://localhost:8080/geoserver/wms</a>", {layers:
'cite:chn_townships', transparent: true}, {isBaseLayer: false,
displayInLayerSwitcher: true, visibility:
false}<br>
);<br>
<br> var tib_townships
= new
OpenLayers.Layer.WMS(<br>
"Townships (Tibetan trans)", "<a href="http://localhost:8080/geoserver/wms" target="_blank">http://localhost:8080/geoserver/wms</a>", {layers:
'cite:tib_townships', transparent: true}, {isBaseLayer: false,
displayInLayerSwitcher: true, visibility: true}
<br>
); <br><br>//The layers are stored
in layer stores...<br>var tibLands = new
GeoExt.data.LayerStore({<br>
map: map,<br>
initDir:
0,<br>
layers: [tib_villages, tib_townships, tib_farms,
tib_countys]<br>
});<br><br> var
chnLands = new GeoExt.data.LayerStore({<br>
map:
map,<br>
initDir: 0,<br>
layers: [chn_villages, chn_townships,
chn_farms, chn_countys]<br>
});<br><br>//Menu for users to select language<br>var
languageMenu = new Ext.menu.Menu({<br>
id:
'mainMenu',<br>
style: {<br>
overflow:
'visible' // For the Combo popup<br>
},<br>
items: [<br>
//
A Field in a Menu<br>
{<br>
text: 'Chinese',<br>
checked:
false,<br>
group:
'theme',<br>
icon:
'./gif/cn.gif',<br>
handler: checkHandler<br>
},{<br>
text: 'English',<br>
checked:
true,<br>
group:
'theme',<br>
handler: checkHandler<br>
},{<br>
text: 'Tibetan',<br>
checked:
false,<br>
group:
'theme',<br>
handler: checkHandler<br>
}<br>
]<br>
});<br><br>//The handler function that
listens to the users selection on the menu (This is where I want the magic to
happen ;)<br>function checkHandler(item, checked)
{<br>
var tibetContainer,
chineseContainer;<br>
<br>
if(item.text ==
'Tibetan'){<br>
if(<a href="http://layerRoot.lastChild.id" target="_blank">layerRoot.lastChild.id</a>
== 'chinese'){<br>
layerRoot.removeChild(layerRoot.lastChild);
<br>
}<br>
<br>
tibetContainer = new
Ext.tree.TreeNode({<br>
text: "Tibetan Labels",<br>
expanded: true,<br>
id: 'tibet'<br>
});<br><br>
tibetContainer.appendChild(new
GeoExt.tree.OverlayLayerContainer({<br>
text: "Lands (Tibetan trans)",<br>
layerStore:
tibLands,<br>
expanded: false,<br>
loader: {param: "LAYERS"}<br>
}));<br><br>
tibetContainer.appendChild(new
GeoExt.tree.OverlayLayerContainer({<br>
text: "Natural Selection (Tibetan
trans)",<br>
layerStore: tibNaturalLayers,<br>
expanded: false,<br>
loader: {param: "LAYERS"}<br>
}));<br><br>
tibetContainer.appendChild(new
GeoExt.tree.OverlayLayerContainer({<br>
text: "Points of Interest (Tibetan
trans)",<br>
layerStore: tibPointOfInterest,<br>
expanded: false,<br>
loader: {param: "LAYERS"}<br>
}));<br><br>
layerRoot.appendChild(tibetContainer);<br><br>
}<br>
else if(item.text ==
'Chinese'){<br>
<br>
chineseContainer =
new Ext.tree.TreeNode({<br>
text: "Chinese Labels",<br>
expanded: true,<br>
id: 'chinese'<br>
});<br><br>
chineseContainer.appendChild(new
GeoExt.tree.OverlayLayerContainer({<br>
text: "Lands (Chinese trans)",<br>
layerStore:
chnLands,<br>
expanded: false,<br>
loader: {param: "LAYERS"}<br>
}));<br><br>
chineseContainer.appendChild(new
GeoExt.tree.OverlayLayerContainer({<br>
text: "Natural Selection (Chinese
trans)",<br>
layerStore: chnNaturalLayers,<br>
expanded: false,<br>
loader: {param: "LAYERS"}<br>
}));<br><br>
chineseContainer.appendChild(new
GeoExt.tree.OverlayLayerContainer({<br>
text: "Points of Interest (Chinese
trans)",<br>
layerStore: chnPointOfInterest,<br>
expanded: false,<br>
loader: {param: "LAYERS"}<br>
}));<br><br>
if(<a href="http://layerRoot.lastChild.id" target="_blank">layerRoot.lastChild.id</a> ==
'tibet'){<br>
//layerRoot.removeChild(layerRoot.lastChild);
<br>
layerRoot.replaceChild(chineseContainer, layerRoot.lastChild) //thought
this might have done it, this just replaces the nodes but not the layers
selected to the new ones :(<br>
}else<br>
{layerRoot.appendChild(chineseContainer);}<br><br>
}<br></blockquote></div><br>
</div></div><p>
</p><hr>
<p></p>_______________________________________________<br>Users mailing
list<br><a href="mailto:Users@geoext.org" target="_blank">Users@geoext.org</a><br><a href="http://www.geoext.org/cgi-bin/mailman/listinfo/users" target="_blank">http://www.geoext.org/cgi-bin/mailman/listinfo/users</a><br>
</div>
</blockquote></div><br>