[fusion-commits] r2165 - sandbox/jxlib-3.0/widgets

svn_fusion at osgeo.org svn_fusion at osgeo.org
Tue May 25 10:59:53 EDT 2010


Author: madair
Date: 2010-05-25 10:59:52 -0400 (Tue, 25 May 2010)
New Revision: 2165

Modified:
   sandbox/jxlib-3.0/widgets/Legend.js
Log:
changes to work with mem leak fixes in JxLib

Modified: sandbox/jxlib-3.0/widgets/Legend.js
===================================================================
--- sandbox/jxlib-3.0/widgets/Legend.js	2010-05-20 20:41:30 UTC (rev 2164)
+++ sandbox/jxlib-3.0/widgets/Legend.js	2010-05-25 14:59:52 UTC (rev 2165)
@@ -260,7 +260,7 @@
         this.selection = new Jx.Selection({
             onSelect: function(item) {
                 var treeItem = item.retrieve('jxTreeItem');
-                var data = treeItem.options.data
+                var data = treeItem.options.data;
                 if (data instanceof Fusion.Layers.Group) {
                     this.getMap().setActiveLayer(null);
                 } else {
@@ -287,21 +287,21 @@
            // console.log('showing root folder');
             var opt = {
                 label: OpenLayers.i18n('defaultMapTitle'),
-                open: true,
-                contextMenu: this.getContextMenu()
+                // contextMenu: this.getContextMenu(),
+                open: true
             };
             this.oRoot = new Jx.TreeFolder(opt);
             this.oTree.add(this.oRoot);
-            this.oRoot.options.contextMenu.add([
-                new Jx.Menu.Item({
-                    label: OpenLayers.i18n('collapse'),
-                    onClick: OpenLayers.Function.bind(this.collapseBranch, this, this.oRoot)
-                }),
-                new Jx.Menu.Item({
-                    label: OpenLayers.i18n('expand'),
-                    onClick: OpenLayers.Function.bind(this.expandBranch, this, this.oRoot)
-                })]
-            );
+            // this.oRoot.options.contextMenu.add([
+            //     new Jx.Menu.Item({
+            //         label: OpenLayers.i18n('collapse'),
+            //         onClick: OpenLayers.Function.bind(this.collapseBranch, this, this.oRoot)
+            //     }),
+            //     new Jx.Menu.Item({
+            //         label: OpenLayers.i18n('expand'),
+            //         onClick: OpenLayers.Function.bind(this.expandBranch, this, this.oRoot)
+            //     })]
+            // );
         }
         
         this.extentsChangedWatcher = this.update.bind(this);
@@ -439,22 +439,22 @@
             var opt = {
                 label: group.legendLabel,
                 open: group.expandInLegend,
-                contextMenu: this.getContextMenu(),
+                // contextMenu: this.getContextMenu(),
                 checked: group.visible
             };
             var treeItem = new Fusion.Widget.Legend.TreeFolder(opt);
             treeItem.options.data = group;
             group.legend.treeItem = treeItem;
-            treeItem.options.contextMenu.add(
-                new Jx.Menu.Item({
-                    label: OpenLayers.i18n('collapse'),
-                    onClick: OpenLayers.Function.bind(this.collapseBranch, this, treeItem)
-                }),
-                new Jx.Menu.Item({
-                    label: OpenLayers.i18n('expand'),
-                    onClick: OpenLayers.Function.bind(this.expandBranch, this, treeItem)
-                })
-            );
+            // treeItem.options.contextMenu.add(
+            //     new Jx.Menu.Item({
+            //         label: OpenLayers.i18n('collapse'),
+            //         onClick: OpenLayers.Function.bind(this.collapseBranch, this, treeItem)
+            //     }),
+            //     new Jx.Menu.Item({
+            //         label: OpenLayers.i18n('expand'),
+            //         onClick: OpenLayers.Function.bind(this.expandBranch, this, treeItem)
+            //     })
+            // );
 
             folder.add(treeItem);
 
@@ -513,9 +513,33 @@
      * remove the dom objects representing the legend layers and groups
      */
     clear: function() {
+        console.log('clear legend');
+        var map = this.getMap();
+        for (var i=0; i<map.layerRoot.groups.length; i++) {
+            this.clearGroup(map.layerRoot.groups[i]);
+        }
+        for (var i=0; i<map.layerRoot.layers.length; i++) {
+          if (map.layerRoot.layers[i].legend) {
+            map.layerRoot.layers[i].legend.treeItem = null;
+            map.layerRoot.layers[i].legend.checkbox = null;
+            map.layerRoot.layers[i].legend.currentRange = null;
+          }
+        }
         this.oRoot.empty();
     },
     
+    clearGroup: function(group) {
+      for (var i=0; i<group.groups.length; i++) {
+        this.clearGroup(group.groups[i]);
+      }
+      for (var i=0; i<group.layers.length; i++) {
+        if (group.layers[i].legend) {
+          group.layers[i].legend.treeItem = null;
+          group.layers[i].legend.currentRange = null;
+        }
+      }
+    },
+    
     updateGroupLayers: function(group, fScale) {
         for (var i=0; i<group.groups.length; i++) {
             this.updateGroupLayers(group.groups[i], fScale);
@@ -615,23 +639,23 @@
         var opt = {
             label: layer.legendLabel == '' ? '&nbsp;' : layer.legendLabel,
             isOpen: layer.expandInLegend,
-            contextMenu: this.getContextMenu(),
+            // contextMenu: this.getContextMenu(),
             image: this.imgLayerThemeIcon,
             selectable: !layer.metadata.jxUnselectable || (layer.metadata.jxUnselectable && layer.metadata.jxUnselectable != 'true')
         };
         var folder = new Fusion.Widget.Legend.TreeFolder(opt);
         var img = folder.elements.get('jxTreeIcon');
         img.style.backgroundPosition = '0px 0px';
-        folder.options.contextMenu.add([
-            new Jx.Menu.Item({
-                label: OpenLayers.i18n('collapse'),
-                onClick: OpenLayers.Function.bind(this.collapseBranch, this, folder)
-            }),
-            new Jx.Menu.Item({
-                label: OpenLayers.i18n('expand'),
-                onClick: OpenLayers.Function.bind(this.expandBranch, this, folder)
-            })]
-        );
+        // folder.options.contextMenu.add([
+        //     new Jx.Menu.Item({
+        //         label: OpenLayers.i18n('collapse'),
+        //         onClick: OpenLayers.Function.bind(this.collapseBranch, this, folder)
+        //     }),
+        //     new Jx.Menu.Item({
+        //         label: OpenLayers.i18n('expand'),
+        //         onClick: OpenLayers.Function.bind(this.expandBranch, this, folder)
+        //     })]
+        // );
         
         var layerInfo = layer.oMap.getLayerInfoUrl(layer.layerName);
         if (layerInfo) {
@@ -668,7 +692,7 @@
 
         var item;
         if (checkbox) {
-            opt.contextMenu = this.getContextMenu();
+            // opt.contextMenu = this.getContextMenu();
             item = new Fusion.Widget.Legend.TreeItem(opt);
             /* only need to add layer info if it has a check box too */
             var layerInfo = layer.oMap.getLayerInfoUrl(layer.layerName);
@@ -720,7 +744,7 @@
     clearTreeItem: function(layer) {
         if (layer.legend.treeItem && layer.legend.treeItem.owner) {
             layer.legend.treeItem.owner.remove(layer.legend.treeItem);
-            layer.legend.treeItem.finalize();
+            // layer.legend.treeItem.finalize();
             layer.legend.treeItem.destroy();
             layer.legend.treeItem = null;
         }
@@ -741,32 +765,51 @@
         checkbox: 'fusionLegendCheckboxInput',
         layerInfo: 'fusionLayerInfo',
         layerInfoIcon: 'fusionLayerInfoIcon'
-    }), 
+    }),
+    init: function() {
+      this.bound.onClick = function(e){
+          if (this.options.data) {
+              if (e.target.checked && this.options.data.show) {
+                  this.options.data.show();
+              } else if (!e.target.checked && this.options.data.hide) {
+                  this.options.data.hide();
+              }
+          }
+      }.bind(this);
+      this.bound.enabled = function() {
+          this.checkbox.disabled = false;
+      }.bind(this);
+      this.bound.disabled = function() {
+          this.checkbox.disabled = true;
+      }.bind(this);
+      this.parent();
+    },
     render: function() {
         this.parent();
         if (this.checkbox) {
             if ($defined(this.options.checked)) {
                 this.check(this.options.checked);
             }
-            this.checkbox.addEvent('click', function(e){
-                if (this.options.data) {
-                    if (e.target.checked && this.options.data.show) {
-                        this.options.data.show();
-                    } else if (!e.target.checked && this.options.data.hide) {
-                        this.options.data.hide();
-                    }
-                }
-            }.bind(this));
+            this.checkbox.addEvent('click', this.bound.onClick);
             this.addEvents({
-                enabled: function() {
-                    this.checkbox.disabled = false;
-                },
-                disabled: function() {
-                    this.checkbox.disabled = true;
-                }
+              enabled: this.bound.enabled,
+              disabled: this.bound.disabled
             });
         }
     },
+    cleanup: function() {
+      this.removeEvents({
+        enabled: this.bound.enabled,
+        disabled: this.bound.disabled
+      });
+      if (this.checkbox) {
+        this.checkbox.removeEvent('click', this.bound.onClick);
+      }
+      this.bound.onClick = null;
+      this.bound.enabled = null;
+      this.bound.disabled = null;
+      this.parent();
+    },
     check: function(state) {
         if (this.checkbox) {
             this.checkbox.set('checked', state);
@@ -805,6 +848,24 @@
         groupInfo: 'fusionGroupInfo',
         groupInfoIcon: 'fusionGroupInfoIcon'
     }),
+    init: function() {
+      this.bound.onClick = function(e){
+          if (this.options.data) {
+              if (e.target.checked && this.options.data.show) {
+                  this.options.data.show();
+              } else if (!e.target.checked && this.options.data.hide) {
+                  this.options.data.hide();
+              }
+          }
+      }.bind(this);
+      this.bound.enabled = function() {
+          this.checkbox.disabled = false;
+      }.bind(this);
+      this.bound.disabled = function() {
+          this.checkbox.disabled = true;
+      }.bind(this);
+      this.parent();
+    },
     
     render: function() {
         this.parent();
@@ -812,25 +873,26 @@
             if ($defined(this.options.checked)) {
                 this.check(this.options.checked);
             }
-            this.checkbox.addEvent('click', function(e){
-                if (this.options.data) {
-                    if (e.target.checked && this.options.data.show) {
-                        this.options.data.show();
-                    } else if (!e.target.checked && this.options.data.hide) {
-                        this.options.data.hide();
-                    }
-                }
-            }.bind(this));
+            this.checkbox.addEvent('click', this.bound.onClick);
             this.addEvents({
-                enabled: function() {
-                    this.checkbox.disabled = false;
-                },
-                disabled: function() {
-                    this.checkbox.disabled = true;
-                }
+                enabled: this.bound.enabled,
+                disabled: this.bound.disabled
             });
         }
     },
+    cleanup: function() {
+      this.removeEvents({
+        enabled: this.bound.enabled,
+        disabled: this.bound.disabled
+      });
+      if (this.checkbox) {
+        this.checkbox.removeEvent('click', this.bound.onClick);
+      }
+      this.bound.onClick = null;
+      this.bound.enabled = null;
+      this.bound.disabled = null;
+      this.parent();
+    },
     check: function(state) {
         if (this.checkbox) {
             this.checkbox.set('checked', state);



More information about the fusion-commits mailing list