[Users] treePanel questions

Andreas Hocevar ahocevar at opengeo.org
Wed Nov 10 14:41:49 CET 2010


Hi,

see my comments inline for sections that you need to change.

On Nov 10, 2010, at 14:23 , Stefanie Weykam wrote:

> I want to built a customized layer tree and group my layers thematically 
> into nodes and subnodes, with individual titles and icons.
> I have seen the postings from September and October but got a bit 
> dazzled. There are a lot of interesting methods but for now I’d like to 
> keep it simple.
> Let me see if I got it right. Please correct me if I’m wrong:
> 
> 1. I set up the map object and a mapPanel without adding any layers at 
> this stage.

Just the MapPanel - it will create an OpenLayers.Map on its own. You can pass custom map configuration options to the MapPanel's map option.

> 2. I set up a treePanel with root: { nodeType: "async" }, without any 
> children yet.
> 3. I create several layerStores, one for each group of layers.

No! You create a single layer store that you also use in the MapPanel. You should use customized layer records with e.g. a field that allows you to distinguish layer groups.

> var layerStore_1 = new GeoExt.data.LayerStore({
> map: map,
> initDir: GeoExt.data.LayerStore.STORE_TO_MAP, //0
> layers: [layer_1,layer_2] });
> I’m not sure about the direction of the initial sync.
> 
> 4. I create several layer containers, one for each group of layers
> var layerContainer_1 = new GeoExt.tree.OverlayLayerContainer({
> text: "my group title",
> layerStore: layerStore_1,
> loader: {param: "LAYERS"}
> })

All containers reference the same layerStore, and you configure them with a loader with a custom filter function, checking against your layer record grouping field. In the above snippet, you will want a GeoExt.tree.LayerContainer, and a loader without a param config option, but with a filter configured. 

> same for layerContainer_2 and layerStore_2
> 
> 5. I set up the tree root node to which I will add the group nodes..
> var treeRootNode = new Ext.tree.TreeNode({
> text: "my title",
> expanded: true
> });
> 6. ..and I append each layerContainer to the tree root node
> treeRootNode.appendChild(layerContainer_1);
> treeRootNode.appendChild(layerContainer_2); etc
> 7. I set the treePanel’s tree root node. Only child is the treeRootNode 
> which has already two children.
> treePanel.setRootNode({
> children: treeRootNode
> });

> 8. And last not least I create a viewport with mapPanel and treePanel.
> 
> I also have a base layer group that I would add as baseLayerContainer, 
> and a graticule ‘layer’ which I add at the end using action. The 
> graticule should be on top and does not belong to any group.
> 
> var action = new GeoExt.Action({
> control: grtCtrl,
> map: map
> });
> 
> So far my tree is empty, no error message. I suppose I missed a loader 
> (?) or perhaps there is something wrong with my map-and-store 
> synchronisation??
> 
> I am not sure if I really need the layerStores. I could as well access 
> all the relevant parameters in my layer metadata (visibility, group, 
> hideInLegend, etc).

If you have the grouping criteria in your layer's metadata, you don't need to use custom LayerNodes. In this case, you don't need to create a LayerStore at all - you can use the mapPanel's layers.

Regards,
Andreas.

-- 
Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.



More information about the Users mailing list