When you are adding a new view to your application, for the purpose of creating a printout of the displayed map for example, you may want to copy child layer nodes and child layers from one layer tree to another.

Layer trees and layer nodes must be manipulated with care, because adding, removing and copying layer nodes may lead to unexpected results. When you are adding or removing an ILcdLayerTreeNode to or from an ILcdTreeLayered, for example, the layer node, as well as all of its child layers, will be added or removed.

The same applies to copying layer nodes between layer trees. You cannot simply retrieve all layers from one layer tree and add them to another layer tree, because some layers would be added multiple times as a result. Instead, you must copy each child layer node and each layer from one root to the other, as shown in Program: Copying layers from one layer tree to another.

Program: Copying layers from one ILcdTreeLayered to another
//obtaining the root node of the original ILcdTreeLayered
ILcdLayerTreeNode rootNode = originalTreeLayered.getRootNode();
//obtaining the root node of the copy ILcdTreeLayered
ILcdLayerTreeNode copyRootNode = copyTreeLayered.getRootNode();
//asking all the child layers of the original ILcdTreeLayered
Enumeration layers = rootNode.layers();
//adding all the layers to the copy ILcdTreeLayered
while (layers.hasMoreElements()) {
  ILcdLayer layer = (ILcdLayer) layers.nextElement();
  copyRootNode.addLayer(layer);
}