<div dir="ltr"><div><div>After a good deal of fuddling around I found out was wrong:<br><br>1. OverlayLayerContainer includes all layers in the OpenLayers.Map object, I had to replace it by a regular Ext TreeNode:<br><br> WebGIS.treeNodes[tag] = new Ext.tree.TreeNode<br>
<br>2. The Layer node was being initialised with the layer name instead of the OpeanLayers.Layer object. This how it should like:<br><br> var newNode = new GeoExt.tree.LayerNode<br> ({<br> text: title,<br> layer: layer,<br>
leaf: true,<br> checked: false,<br> children: [],<br> nodeType: "gx_layer"<br> });<br><br></div>Regards,<br><br></div>Luís<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On 6 February 2014 16:59, Luís de Sousa <span dir="ltr"><<a href="mailto:luis.a.de.sousa@gmail.com" target="_blank">luis.a.de.sousa@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<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>
</blockquote></div><br></div>