[Users] Layer leaf nodes replicated across all tree nodes
Luís de Sousa
luis.a.de.sousa at gmail.com
Fri Feb 7 10:11:58 CET 2014
After a good deal of fuddling around I found out was wrong:
1. OverlayLayerContainer includes all layers in the OpenLayers.Map object,
I had to replace it by a regular Ext TreeNode:
WebGIS.treeNodes[tag] = new Ext.tree.TreeNode
2. The Layer node was being initialised with the layer name instead of the
OpeanLayers.Layer object. This how it should like:
var newNode = new GeoExt.tree.LayerNode
({
text: title,
layer: layer,
leaf: true,
checked: false,
children: [],
nodeType: "gx_layer"
});
Regards,
Luís
On 6 February 2014 16:59, Luís de Sousa <luis.a.de.sousa at gmail.com> wrote:
> Dear all,
>
> 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 it is happening this way are welcome. Thank you,
>
> Luís
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.geoext.org/pipermail/users/attachments/20140207/472614bf/attachment.htm
More information about the Users
mailing list