[Users] Layertreebuilder has issues when layer removed.
Matt Priour
mpriour at kestrelcomputer.com
Thu Jul 14 14:52:20 CEST 2011
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.
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.
var parent = node.parentNode;
node.remove();
//delete empty parents
while (parent) {
if (parent.hasChildNodes()) {
break;
}
var cur = parent;
parent = parent.parentNode;
cur.remove();
}
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.
Matt Priour
From: Phil Scadden
Sent: Wednesday, July 13, 2011 9:56 PM
To: Matt Priour
Cc: users at geoext.org
Subject: Re: [Users] Layertreebuilder has issues when layer removed.
You should change your function to this:
tree.getRootNode().cascade(function(node){
if (!node.childNodes || node.childNodes.length==0) {
node.remove();
}
}
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.
I never thought of a delay. on remove. Will experiment.
--
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
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.geoext.org/pipermail/users/attachments/20110714/f31b5a87/attachment.htm
More information about the Users
mailing list