[Users] treePanel questions

Stefanie Weykam stefanie at weykam.net
Wed Nov 10 19:37:38 CET 2010


Thank you for your quick answer, Andreas. I am still struggling with my 
layer tree… and particularly with the filter function and/or how to 
access the layers.

I now create the map object directly in the mapPanel, passing the map 
options on and the layers too. The layers will be distributed 
automatically to their nodes according to their group (right? this seems 
mysterious to me).
I don’t define explicitly a new layerStore, since I already have my 
layer.metadata.group parameters set in the layer objects. Anyway, a 
default layerStore will be created for my mapPanel.layers.

I can now already loop through the layers and query their group…
for(var i=count-1; i>=0; --i) {
     layerRec = mapPanel.layers.getAt(i);
     console.log(i+' '+layerRec.data.layer.name+' = 
'+layerRec.data.layer.metadata.group);
}

But when I create the first layerContainer for the first group the 
trouble starts… what exactly do I expect to be returned - a layer array?

var container_1 = new GeoExt.tree.LayerContainer({     // group 1
                         text: "First thematic group",
                         layerStore: mapPanel.layers,
                         loader: {
                                  //param: "LAYERS"
                                   group: 'grupo1',
                                   filter: function () {
                        //           ??
                                   }
                        }
});
I have seen somewhere 'record' as function argument, but I don't get 
where that comes from. I suppose it referes to any layerRecord (using 
perhapt a group array). I wouldn't need that, because I will customize 
each layerContainer indivudually.

Thanks for your help and best regards




El 10/11/2010 14:41, Andreas Hocevar escribió:
> 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.
>



More information about the Users mailing list