This is going on with GeoExt 1.1 and OpenLayers 2.12. I need to build a layer tree dynamically, with layers and nodes that are only known at run time. The snippets I show below correctly create a layer tree with several nodes and adds the layers node leafs. The problem is that though each layer is assigned to a single tree node, it is then shown under each and every tree node created.
During init the tree and its root are set up:
treeRoot = new Ext.tree.TreeNode
({
text : 'Project',
id : '0',
leaf :false,
expandable : true,
expanded : true
});
layerTree = new Ext.tree.TreePanel
({
title: 'Map Layers',
region: "west",
width: 200,
collapsible: true,
autoScroll: true,
enableDD: true,
plugins:
[{
ptype: "gx_treenodecomponent"
}],
loader:
{
applyLoader: false,
uiProviders:
{
"custom_ui": LayerNodeUI
}
},
root: treeRoot,
rootVisible: false,
lines: false
});
Later on new tree nodes can be added according to a tag, and kept in an array:
if(treeNodes[tag] == null)
{
treeNodes[tag] = new GeoExt.tree.OverlayLayerContainer
({
text: tag,
leaf: false,
expanded: true
});
treeRoot.appendChild(treeNodes[tag]);
}
Layers are added to the map and to a specific tree node:
var layer = new OpenLayers.Layer.WMS(title, serviceURL, params, options);
leftMap.addLayer(layer);
layer.events.register("visibilitychanged", this, toggleLayer);
var newNode = new GeoExt.tree.LayerNode(
{
text: title,
layer: layerName,
leaf: true,
checked: false,
children: [],
nodeType: "gx_layer"
});
treeNodes[tag].appendChild(newNode);
But then each layer appears several times, once under each tree node.
Any hints on why itWhy is it happening this way are welcome. Thank you.?