1 | /** |
---|
2 | * Copyright (c) 2008-2010 The Open Source Geospatial Foundation |
---|
3 | * |
---|
4 | * Published under the BSD license. |
---|
5 | * See http://svn.geoext.org/core/trunk/geoext/license.txt for the full text |
---|
6 | * of the license. |
---|
7 | */ |
---|
8 | |
---|
9 | /** |
---|
10 | * @include GeoExt/widgets/tree/LayerLoader.js |
---|
11 | */ |
---|
12 | Ext.namespace("GeoExt.tree"); |
---|
13 | |
---|
14 | /** api: (define) |
---|
15 | * module = GeoExt.tree |
---|
16 | * class = LayerContainer |
---|
17 | * base_link = `Ext.tree.AsyncTreeNode <http://dev.sencha.com/deploy/dev/docs/?class=Ext.tree.AsyncTreeNode>`_ |
---|
18 | */ |
---|
19 | |
---|
20 | /** api: constructor |
---|
21 | * .. class:: LayerContainer |
---|
22 | * |
---|
23 | * A subclass of ``Ext.tree.AsyncTreeNode`` that will collect all layers of an |
---|
24 | * OpenLayers map. Only layers that have displayInLayerSwitcher set to true |
---|
25 | * will be included. The childrens' iconCls defaults to |
---|
26 | * "gx-tree-layer-icon". |
---|
27 | * |
---|
28 | * Note: if this container is loaded by an ``Ext.tree.TreeLoader``, the |
---|
29 | * ``applyLoader`` config option of that loader needs to be set to |
---|
30 | * "false". Also note that the list of available uiProviders will be |
---|
31 | * taken from the ownerTree if this container's loader is configured |
---|
32 | * without one. |
---|
33 | * |
---|
34 | * To use this node type in ``TreePanel`` config, set nodeType to |
---|
35 | * "gx_layercontainer". |
---|
36 | */ |
---|
37 | GeoExt.tree.LayerContainer = Ext.extend(Ext.tree.AsyncTreeNode, { |
---|
38 | |
---|
39 | /** api: config[loader] |
---|
40 | * :class:`GeoExt.tree.LayerLoader` or ``Object`` The loader to use with |
---|
41 | * this container. If an ``Object`` is provided, a |
---|
42 | * :class:`GeoExt.tree.LayerLoader`, configured with the the properties |
---|
43 | * from the provided object, will be created. |
---|
44 | */ |
---|
45 | |
---|
46 | /** api: config[layerStore] |
---|
47 | * :class:`GeoExt.data.LayerStore` The layer store containing layers to be |
---|
48 | * displayed in the container. If loader is not provided or provided as |
---|
49 | * ``Object``, this property will be set as the store option of the |
---|
50 | * loader. Otherwise it will be ignored. |
---|
51 | */ |
---|
52 | |
---|
53 | /** private: method[constructor] |
---|
54 | * Private constructor override. |
---|
55 | */ |
---|
56 | constructor: function(config) { |
---|
57 | config = Ext.applyIf(config || {}, { |
---|
58 | text: "Layers" |
---|
59 | }); |
---|
60 | this.loader = config.loader instanceof GeoExt.tree.LayerLoader ? |
---|
61 | config.loader : |
---|
62 | new GeoExt.tree.LayerLoader(Ext.applyIf(config.loader || {}, { |
---|
63 | store: config.layerStore |
---|
64 | })); |
---|
65 | |
---|
66 | GeoExt.tree.LayerContainer.superclass.constructor.call(this, config); |
---|
67 | }, |
---|
68 | |
---|
69 | /** private: method[recordIndexToNodeIndex] |
---|
70 | * :param index: ``Number`` The record index in the layer store. |
---|
71 | * :return: ``Number`` The appropriate child node index for the record. |
---|
72 | */ |
---|
73 | recordIndexToNodeIndex: function(index) { |
---|
74 | var store = this.loader.store; |
---|
75 | var count = store.getCount(); |
---|
76 | var nodeCount = this.childNodes.length; |
---|
77 | var nodeIndex = -1; |
---|
78 | for(var i=count-1; i>=0; --i) { |
---|
79 | if(this.loader.filter(store.getAt(i)) === true) { |
---|
80 | ++nodeIndex; |
---|
81 | if(index === i || nodeIndex > nodeCount-1) { |
---|
82 | break; |
---|
83 | } |
---|
84 | } |
---|
85 | } |
---|
86 | return nodeIndex; |
---|
87 | }, |
---|
88 | |
---|
89 | /** private: method[destroy] |
---|
90 | */ |
---|
91 | destroy: function() { |
---|
92 | delete this.layerStore; |
---|
93 | GeoExt.tree.LayerContainer.superclass.destroy.apply(this, arguments); |
---|
94 | } |
---|
95 | }); |
---|
96 | |
---|
97 | /** |
---|
98 | * NodeType: gx_layercontainer |
---|
99 | */ |
---|
100 | Ext.tree.TreePanel.nodeTypes.gx_layercontainer = GeoExt.tree.LayerContainer; |
---|