| 30 | | /** |
|---|
| 31 | | * Method: addLayerNode |
|---|
| 32 | | * Adds a child node representing a overlay layer of the map |
|---|
| | 30 | /** private: method[render] |
|---|
| | 31 | * :param bulkRender: ``Boolean`` |
|---|
| | 32 | */ |
|---|
| | 33 | render: function(bulkRender) { |
|---|
| | 34 | var first = !this.rendered; |
|---|
| | 35 | GeoExplorer.GroupContainer.superclass.render.call(this, bulkRender); |
|---|
| | 36 | if (first) { |
|---|
| | 37 | this.layerStore.on({ |
|---|
| | 38 | update: this.onStoreUpdate, |
|---|
| | 39 | scope: this |
|---|
| | 40 | }); |
|---|
| | 41 | } |
|---|
| | 42 | }, |
|---|
| | 43 | |
|---|
| | 44 | /** private: method[onStoreAdd] |
|---|
| | 45 | * :param store: ``Ext.data.Store`` |
|---|
| | 46 | * :param records: ``Array(Ext.data.Record)`` |
|---|
| | 47 | * :param index: ``Number`` |
|---|
| | 48 | * |
|---|
| | 49 | * Listener for the store's add event. |
|---|
| | 50 | */ |
|---|
| | 51 | onStoreAdd: function(store, records, index) { |
|---|
| | 52 | /** |
|---|
| | 53 | * Containers with checkedGroup should have only one visible layer. |
|---|
| | 54 | * This listener can be removed if the LayerNode is made to fire |
|---|
| | 55 | * checkchange when the radio button is unchecked. |
|---|
| | 56 | * TODO: http://www.geoext.org/trac/geoext/ticket/109 |
|---|
| | 57 | */ |
|---|
| | 58 | GeoExplorer.GroupContainer.superclass.onStoreAdd.apply(this, arguments); |
|---|
| | 59 | if (this.defaults && this.defaults.checkedGroup && !this._reordering) { |
|---|
| | 60 | Ext.each(records, function(record) { |
|---|
| | 61 | this.enforceOneVisible(record); |
|---|
| | 62 | }, this); |
|---|
| | 63 | } |
|---|
| | 64 | }, |
|---|
| | 65 | |
|---|
| | 66 | |
|---|
| | 67 | /** private: onStoreUpdate |
|---|
| | 68 | * :param store: ``Ext.data.Store`` |
|---|
| | 69 | * :param record: ``Ext.data.Record`` |
|---|
| | 70 | * :param operation: ``String`` |
|---|
| | 71 | * |
|---|
| | 72 | * Listener for the store's update event. |
|---|
| | 73 | */ |
|---|
| | 74 | onStoreUpdate: function(store, record, operation) { |
|---|
| | 75 | /** |
|---|
| | 76 | * Containers with checkedGroup should have only one visible layer. |
|---|
| | 77 | * This listener can be removed if the LayerNode is made to fire |
|---|
| | 78 | * checkchange when the radio button is unchecked. |
|---|
| | 79 | * TODO: http://www.geoext.org/trac/geoext/ticket/109 |
|---|
| | 80 | */ |
|---|
| | 81 | if (this.defaults && this.defaults.checkedGroup) { |
|---|
| | 82 | this.enforceOneVisible(record); |
|---|
| | 83 | } |
|---|
| | 84 | }, |
|---|
| | 85 | |
|---|
| | 86 | /** private: enforceOneVisible |
|---|
| | 87 | * TODO: remove this when http://www.geoext.org/trac/geoext/ticket/109 is closed |
|---|
| | 88 | */ |
|---|
| | 89 | enforceOneVisible: function(record) { |
|---|
| | 90 | var layer = record.get("layer"); |
|---|
| | 91 | var inGroup = false; |
|---|
| | 92 | this.eachChild(function(node) { |
|---|
| | 93 | if(node.layer === layer) { |
|---|
| | 94 | inGroup = true; |
|---|
| | 95 | } |
|---|
| | 96 | return !inGroup; |
|---|
| | 97 | }); |
|---|
| | 98 | if(inGroup) { |
|---|
| | 99 | var vis = layer.getVisibility(); |
|---|
| | 100 | if(vis) { |
|---|
| | 101 | // make sure there is not more than one |
|---|
| | 102 | this.eachChild(function(node) { |
|---|
| | 103 | if(node.layer !== layer && node.layer.getVisibility()) { |
|---|
| | 104 | window.setTimeout(function() { |
|---|
| | 105 | node.layer.setVisibility(false); |
|---|
| | 106 | }, 0); |
|---|
| | 107 | } |
|---|
| | 108 | }); |
|---|
| | 109 | } else { |
|---|
| | 110 | // make sure there is at least one |
|---|
| | 111 | this.eachChild(function(node) { |
|---|
| | 112 | vis = vis || node.layer.getVisibility(); |
|---|
| | 113 | }); |
|---|
| | 114 | if(!vis) { |
|---|
| | 115 | var child = this.lastChild; |
|---|
| | 116 | window.setTimeout(function() { |
|---|
| | 117 | child.layer.setVisibility(true); |
|---|
| | 118 | }, 0); |
|---|
| | 119 | } |
|---|
| | 120 | } |
|---|
| | 121 | } |
|---|
| | 122 | }, |
|---|
| | 123 | |
|---|
| | 124 | /** private: method[addLayerNode] |
|---|
| | 125 | * :param layerRecord: ``Ext.data.Record`` The layer record containing the |
|---|
| | 126 | * layer to be added. |
|---|
| | 127 | * :param index: ``Number`` Optional index for the new layer. Default is 0. |
|---|
| | 128 | * |
|---|
| | 129 | * Adds a child node representing a layer of the map |
|---|
| | 130 | */ |
|---|
| | 131 | addLayerNode: function(layerRecord, index) { |
|---|
| | 132 | if (layerRecord.get("group") == this.group) { |
|---|
| | 133 | GeoExplorer.GroupContainer.superclass.addLayerNode.apply( |
|---|
| | 134 | this, arguments |
|---|
| | 135 | ); |
|---|
| | 136 | } |
|---|
| | 137 | }, |
|---|
| | 138 | |
|---|
| | 139 | /** private: method[removeLayerNode] |
|---|
| | 140 | * :param layerRecord: ``Ext.data.Record`` The layer record containing the |
|---|
| | 141 | * layer to be removed. |
|---|
| 123 | | record.set("group", this.group); |
|---|
| 124 | | } |
|---|
| | 220 | window.setTimeout(function() { |
|---|
| | 221 | var store = container.layerStore; |
|---|
| | 222 | var index = container.indexOf(node); |
|---|
| | 223 | var recIndex = container.nodeIndexToRecordIndex( |
|---|
| | 224 | container.indexOf(node) |
|---|
| | 225 | ); |
|---|
| | 226 | store.remove(record); |
|---|
| | 227 | node.remove(); |
|---|
| | 228 | |
|---|
| | 229 | // TODO: record.clone() |
|---|
| | 230 | Ext.data.Record.AUTO_ID++; |
|---|
| | 231 | record = record.copy(Ext.data.Record.AUTO_ID); |
|---|
| | 232 | var layer = record.get("layer").clone(); |
|---|
| | 233 | record.set("layer", null); |
|---|
| | 234 | record.set("layer", layer); |
|---|
| | 235 | |
|---|
| | 236 | record.set("group", container.group); |
|---|
| | 237 | store.insert(recIndex, [record]); |
|---|
| | 238 | }, 0); |
|---|
| | 239 | |
|---|
| | 240 | } |
|---|
| | 241 | }, |
|---|
| | 242 | |
|---|
| | 243 | /** private: method[destroy] |
|---|
| | 244 | */ |
|---|
| | 245 | destroy: function() { |
|---|
| | 246 | if(this.layerStore) { |
|---|
| | 247 | this.layerStore.un("update", this.onStoreUpdate, this); |
|---|
| | 248 | } |
|---|
| | 249 | GeoExplorer.GroupContainer.superclass.destroy.apply(this, arguments); |
|---|