<HTML><HEAD>
<META content="text/html; charset=UTF-8" http-equiv=Content-Type></HEAD>
<BODY dir=ltr bgColor=#ffffff text=#000000>
<DIV dir=ltr>
<DIV style="FONT-FAMILY: 'Arial'; COLOR: #000000; FONT-SIZE: 10pt">
<DIV>You’re right. I wasn’t paying much attention to the actual removal logic
there. I was mostly trying to demonstrate the use of cascade and/or eachChild. I
used something like that in a project were there were all leaf nodes were always
part of a group node.</DIV>
<DIV> </DIV>
<DIV>I found the code we are actually using for a removing nodes from a layer
tree that can contain different hierarchies of nodes. The following snippet is
used in the function that actually does the node removal. I think we adapted
this from the pre-GeoExt Mapfish client code, but it is being used in a GeoExt
project now.</DIV>
<DIV> </DIV>
<DIV>var parent = node.parentNode;</DIV>
<DIV>node.remove();</DIV>
<DIV> </DIV>
<DIV>//delete empty parents</DIV>
<DIV>while (parent) {</DIV>
<DIV> if (parent.hasChildNodes()) {</DIV>
<DIV> break;</DIV>
<DIV> }</DIV>
<DIV> var cur = parent;</DIV>
<DIV> parent = parent.parentNode;</DIV>
<DIV> cur.remove();</DIV>
<DIV>}</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>This function recursively walks up the tree from the node which was removed
deleting any empty parent group nodes and stopping once it has found a group
node with child nodes.</DIV>
<DIV> </DIV>
<DIV>Matt Priour</DIV>
<DIV
style="FONT-STYLE: normal; DISPLAY: inline; FONT-FAMILY: 'Calibri'; COLOR: #000000; FONT-SIZE: small; FONT-WEIGHT: normal; TEXT-DECORATION: none">
<DIV style="FONT: 10pt tahoma">
<DIV> </DIV>
<DIV style="BACKGROUND: #f5f5f5">
<DIV style="font-color: black"><B>From:</B> <A title=p.scadden@gns.cri.nz
href="mailto:p.scadden@gns.cri.nz">Phil Scadden</A> </DIV>
<DIV><B>Sent:</B> Wednesday, July 13, 2011 9:56 PM</DIV>
<DIV><B>To:</B> <A title=mpriour@kestrelcomputer.com
href="mailto:mpriour@kestrelcomputer.com">Matt Priour</A> </DIV>
<DIV><B>Cc:</B> <A title=users@geoext.org
href="mailto:users@geoext.org">users@geoext.org</A> </DIV>
<DIV><B>Subject:</B> Re: [Users] Layertreebuilder has issues when layer
removed.</DIV></DIV></DIV>
<DIV> </DIV></DIV>
<DIV
style="FONT-STYLE: normal; DISPLAY: inline; FONT-FAMILY: 'Calibri'; COLOR: #000000; FONT-SIZE: small; FONT-WEIGHT: normal; TEXT-DECORATION: none">You
should change your function to this:
<BLOCKQUOTE cite=mid:C95FA3DF461F4110954B142E9199987E@Lenovo type="cite">
<DIV dir=ltr>
<DIV style="FONT-FAMILY: 'Arial'; COLOR: #000000; FONT-SIZE: 10pt">
<DIV> </DIV>
<DIV><FONT face=Calibri><FONT
style="FONT-SIZE: 12pt">tree.getRootNode().cascade(function(node){<BR>
if (!node.childNodes || node.childNodes.length==0)
{<BR> node.remove();<BR>
}</FONT></FONT></DIV>
<DIV><FONT face=Calibri><FONT
style="FONT-SIZE: 12pt">}</FONT></FONT><BR></DIV>
<DIV> </DIV></DIV></DIV></BLOCKQUOTE>That would surely remove the leaf
nodes as well as empty group nodes? The trick is recognize that the node is a
group node rather than a layer leaf node.<BR><BR>I never thought of a delay. on
remove. Will experiment.<BR>
<DIV class=moz-signature>-- <BR>Phil Scadden, Senior Scientist GNS Science Ltd
764 Cumberland St, Private Bag 1930, Dunedin, New Zealand Ph +64 3 4799663, fax
+64 3 477 5232</DIV>
<P><SPAN style="FONT-FAMILY: 'Arial'; COLOR: #000000; FONT-SIZE: 8pt">Notice:
This email and any attachments are confidential. If received in error please
destroy and immediately notify us. Do not copy or disclose the
contents.</SPAN></P>
<P><SPAN
style="FONT-FAMILY: 'Arial'; COLOR: #000000; FONT-SIZE: 8pt"></SPAN> </P></DIV></DIV></DIV></BODY></HTML>