0

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.

Why is it happening this way?

0

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" });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.