<div dir="ltr">Dear all,<br><br>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.<br>
<br>During init the tree and its root are set up:<br><br> treeRoot = new Ext.tree.TreeNode<br> ({<br> text : 'Project',<br> id : '0',<br> leaf :false,<br> expandable : true,<br>
expanded : true<br> });<br><br> layerTree = new Ext.tree.TreePanel<br> ({<br> title: 'Map Layers',<br> region: "west",<br> width: 200,<br> collapsible: true,<br> autoScroll: true,<br>
enableDD: true,<br> plugins: <br> [{<br> ptype: "gx_treenodecomponent"<br> }],<br> loader: <br> {<br> applyLoader: false,<br> uiProviders: <br> {<br> "custom_ui": LayerNodeUI<br>
}<br> },<br> root: treeRoot,<br> rootVisible: false,<br> lines: false<br> });<br><br>Later on new tree nodes can be added according to a tag, and kept in an array:<br><br> if(treeNodes[tag] == null)<br>
{<br> treeNodes[tag] = new GeoExt.tree.OverlayLayerContainer<br> ({<br> text: tag,<br> leaf: false,<br> expanded: true<br> });<br> treeRoot.appendChild(treeNodes[tag]);<br>
}<br><br>Layers are added to the map and to a specific tree node:<br><br> var layer = new OpenLayers.Layer.WMS(title, serviceURL, params, options);<br> leftMap.addLayer(layer);<br> layer.events.register("visibilitychanged", this, toggleLayer);<br>
<br> var newNode = new GeoExt.tree.LayerNode(<br> {<br> text: title,<br> layer: layerName,<br> leaf: true,<br> checked: false,<br> children: [],<br> nodeType: "gx_layer"<br>
});<br> treeNodes[tag].appendChild(newNode);<br><br>But then each layer appears several times, once under each tree node.<br><br>Any hints on why it is happening this way are welcome. Thank you,<br><br>Luís<br></div>