[fusion-commits] r1645 - in trunk: lib widgets

svn_fusion at osgeo.org svn_fusion at osgeo.org
Thu Nov 6 16:20:28 EST 2008


Author: pagameba
Date: 2008-11-06 16:20:28 -0500 (Thu, 06 Nov 2008)
New Revision: 1645

Modified:
   trunk/lib/Map.js
   trunk/lib/jxlib.uncompressed.js
   trunk/widgets/Legend.js
Log:
Re #151, Re #157.  Fix up a bunch of legend behaviour including the context menu handler and toggling the state of themed layers.  This needed a change in Jx TreeFolder to fix the problem with themed layers.

Modified: trunk/lib/Map.js
===================================================================
--- trunk/lib/Map.js	2008-11-06 20:26:28 UTC (rev 1644)
+++ trunk/lib/Map.js	2008-11-06 21:20:28 UTC (rev 1645)
@@ -115,8 +115,7 @@
                 controls: [], 
                 fallThrough: true,
                 scales: scalesArray,
-                fractionalZoom: this.fractionalZoom,
-                theme: null
+                fractionalZoom: this.fractionalZoom
             };
             if (widgetTag.extension.ConstrainMapExtent) {
               this.bRestrictExtent = widgetTag.extension.ConstrainMapExtent[0]=='true'?true:false;
@@ -128,7 +127,6 @@
             this.oMapOL = new OpenLayers.Map(this._sDomObj, options );
         }
         
-        Fusion.addWidgetStyleSheet(widgetTag.location + 'MapWidget/MapWidget.css');
         this.oMapOL.viewPortDiv.style.position = 'absolute';  //not the top level container so set it to absolute
         this.oMapOL.viewPortDiv.style.zIndex = 0;   //must explicitly set the z-index for FF3
         
@@ -474,7 +472,9 @@
       */
     setActiveLayer: function( oLayer ) {
         this.oActiveLayer = oLayer;
-        this.oActiveMap = oLayer.map;
+        if (oLayer) {
+            this.oActiveMap = oLayer.map;
+        }
         this.triggerEvent(Fusion.Event.MAP_ACTIVE_LAYER_CHANGED, oLayer);
     },
 

Modified: trunk/lib/jxlib.uncompressed.js
===================================================================
--- trunk/lib/jxlib.uncompressed.js	2008-11-06 20:26:28 UTC (rev 1644)
+++ trunk/lib/jxlib.uncompressed.js	2008-11-06 21:20:28 UTC (rev 1645)
@@ -13210,7 +13210,7 @@
         this.parent($merge(options,{type:'Branch'}));
 
         $(this.domNode).addEvent('click', this.clicked.bindWithEvent(this));
-        $(this.domLabel).addEvent('click', this.clicked.bindWithEvent(this));
+        this.addEvent('click', this.clicked.bindWithEvent(this));
                 
         this.nodes = [];
         this.subDomObj = new Element('ul', {'class':'jxTree'});

Modified: trunk/widgets/Legend.js
===================================================================
--- trunk/widgets/Legend.js	2008-11-06 20:26:28 UTC (rev 1644)
+++ trunk/widgets/Legend.js	2008-11-06 21:20:28 UTC (rev 1645)
@@ -242,35 +242,6 @@
         this.oTree = new Jx.Tree({parent:this.oLegend.domObj});
        
         this.hideInvisibleLayers = (json.HideInvisibleLayers && json.HideInvisibleLayers[0]) == 'true' ? true : false;
-        //console.log('hideInvisibleLayers ' +  this.hideInvisibleLayers);
-        this.refreshItem = new Jx.Menu.Item({
-            label: OpenLayers.i18n('refresh'),
-            onClick: OpenLayers.Function.bind(this.update, this)
-        });
-        this.expandAllItem = new Jx.Menu.Item({
-            label: OpenLayers.i18n('expandAll'),
-            onClick: OpenLayers.Function.bind(this.expandAll, this)
-        });
-        this.expandBranchItem = new Jx.Menu.Item({
-            label: OpenLayers.i18n('expand'),
-            onClick: OpenLayers.Function.bind(this.expandBranch, this)
-        });
-        this.collapseAllItem = new Jx.Menu.Item({
-            label: OpenLayers.i18n('collapseAll'),
-            onClick: OpenLayers.Function.bind(this.collapseAll, this)
-        });
-        this.collapseBranchItem = new Jx.Menu.Item({
-            label: OpenLayers.i18n('collapse'),
-            onClick: OpenLayers.Function.bind(this.collapseBranch, this)
-        });
-        //this.collapseBranchItem.disable();
-        
-        this.contextMenu = new Jx.Menu.Context(this.name);
-        this.contextMenu.add(this.collapseBranchItem, 
-                              this.expandBranchItem, 
-                              this.refreshItem, 
-                              this.expandAllItem, 
-                              this.collapseAllItem );
         //don't show the root folder by default
         this.showRootFolder = (json.ShowRootFolder && json.ShowRootFolder[0] == 'true') ? true:false;
         //do show the map folder by default
@@ -283,34 +254,53 @@
                 'class':'fusionLegendFolder'
             };
             this.oRoot = new Jx.TreeFolder(opt);
-            this.oRoot.contextMenu = this.contextMenu;
+            this.oRoot.contextMenu = this.getContextMenu(this.oRoot);
             
             this.oTree.append(this.oRoot);
-             OpenLayers.Event.observe(this.oRoot.domObj, 'mouseover', OpenLayers.Function.bind(this.setFolder, this, this.oRoot));
         } else {
             this.oRoot = this.oTree;
         }
         this.extentsChangedWatcher = this.update.bind(this);
     },
     
-    expandAll: function() {
+    getContextMenu: function(folder) {
+        return new Jx.Menu.Context(this.name).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)
+            }),
+            new Jx.Menu.Item({
+                label: OpenLayers.i18n('refresh'),
+                onClick: OpenLayers.Function.bind(this.update, this, folder)
+            }),
+            new Jx.Menu.Item({
+                label: OpenLayers.i18n('collapseAll'),
+                onClick: OpenLayers.Function.bind(this.collapseAll, this, folder)
+            }),
+            new Jx.Menu.Item({
+                label: OpenLayers.i18n('expandAll'),
+                onClick: OpenLayers.Function.bind(this.expandAll, this, folder)
+            })
+        );
+    },
+    expandAll: function(folder) {
         this.recurseTree('expand', this.oRoot);
     },
     
-    collapseAll: function() {
+    collapseAll: function(folder) {
         this.recurseTree('collapse', this.oRoot);
     },
     
-    collapseBranch: function() {
-        if (this.targetFolder && this.targetFolder instanceof Jx.TreeFolder) {
-          this.targetFolder.collapse();
-        }
+    collapseBranch: function(folder) {
+        folder.collapse();
     },
     
-    expandBranch: function() {
-        if (this.targetFolder && this.targetFolder instanceof Jx.TreeFolder) {
-          this.targetFolder.expand();
-        }
+    expandBranch: function(folder) {
+        folder.expand();
     },
     
   /**
@@ -329,15 +319,6 @@
         }
     },
    
-  /**
-     * mouseover action handler for tree folders.  Sets the folder to be collapsed/expanded for 
-     * collapsing individual branches.  Adding a mouseout action handler to clear the target folder
-     * doesn't work because the action of right clicking the context menu issues a mouseout.
-     */
-    setFolder: function(folder) {
-      this.targetFolder = folder;
-    },
-    
     scaleRangesLoaded: function() {
         this.layerRoot = this.getMap().layerRoot;
         this.renderLegend();
@@ -410,13 +391,13 @@
                 'class':'fusionLegendFolder'                
             };
             group.legend.treeItem = new Jx.TreeFolder(opt);
-            group.legend.treeItem.contextMenu = this.contextMenu;
-            group.legend.treeItem.data = group;
+            group.legend.treeItem.contextMenu = this.getContextMenu(group.legend.treeItem);
+            group.legend.treeItem.domObj.store('data', group);
             
             folder.append(group.legend.treeItem);
             group.legend.treeItem.checkBox.checked = group.visible?true:false;
             OpenLayers.Event.observe(group.legend.treeItem.checkBox, 'click', OpenLayers.Function.bind(this.stateChanged, this, group));
-            OpenLayers.Event.observe(group.legend.treeItem.domObj, 'mouseover', OpenLayers.Function.bind(this.setFolder, this, group.legend.treeItem));
+
             var groupInfo = group.oMap.getGroupInfoUrl(group.groupName);
             if (groupInfo) {
                 var a = document.createElement('a');
@@ -486,15 +467,16 @@
     selectionChanged: function(o) {
         if (this.currentNode) {
           //console.log(this.currentNode);
-            $(this.currentNode.domObj.childNodes[3]).addClass('jxTreeSelectedNode');
+            $(this.currentNode.domObj.childNodes[1]).removeClass('jxTreeItemSelected');
         }
         this.currentNode = o;
-        $(this.currentNode.domObj.childNodes[3]).addClass('jxTreeSelectedNode');
+        $(this.currentNode.domObj.childNodes[1]).addClass('jxTreeItemSelected');
        
-        if (o.data instanceof Fusion.Widget.Map.Group) {
+        var data = o.domObj.retrieve('data');
+        if (data instanceof Fusion.Widget.Map.Group) {
             this.getMap().setActiveLayer(null);
         } else {
-            this.getMap().setActiveLayer(o.data);
+            this.getMap().setActiveLayer(data);
         }
     },
     updateGroupLayers: function(group, fScale) {
@@ -525,6 +507,7 @@
                 } else if (layer.legend.treeItem instanceof Jx.TreeItem) {
                     this.clearTreeItem(layer);
                     layer.legend.treeItem = this.createFolderItem(layer);
+                    OpenLayers.Event.observe(layer.legend.treeItem.checkBox, 'click', OpenLayers.Function.bind(this.stateChanged, this, layer));
                     layer.parentGroup.legend.treeItem.append(layer.legend.treeItem);
                 } else {
                     while(layer.legend.treeItem.nodes.length > 0) {
@@ -583,6 +566,9 @@
                 layer.legend.treeItem = newTreeItem;
             }
         }
+        if (layer.legend.treeItem) {
+            layer.legend.treeItem.domObj.store('data', layer);
+        }
     },
     
     createFolderItem: function(layer) {
@@ -595,7 +581,7 @@
             image: this.imgLayerThemeIcon
         };
         var folder = new Jx.TreeFolder(opt);
-        folder.contextMenu = this.contextMenu;
+        folder.contextMenu = this.getContextMenu(folder);
         var layerInfo = layer.oMap.getLayerInfoUrl(layer.layerName);
         if (layerInfo) {
             var a = document.createElement('a');
@@ -610,7 +596,6 @@
             folder.domObj.insertBefore(a, folder.domObj.childNodes[4]);
         }
         folder.addEvent('click', OpenLayers.Function.bind(this.selectionChanged, this));
-        OpenLayers.Event.observe(folder.domObj, 'mouseover', OpenLayers.Function.bind(this.setFolder, this, folder));
        
         return folder;
     },
@@ -635,7 +620,7 @@
         }
        
         var item = new Jx.TreeItem(opt);
-        item.contextMenu = this.contextMenu;
+        item.contextMenu = this.getContextMenu(layer.parentGroup.legend.treeItem);
         if (bCheckBox) {
             //item.domObj.insertBefore(layer.legend.checkBox, item.domObj.childNodes[1]);
             /* only need to add layer info if it has a check box too */
@@ -659,14 +644,14 @@
         return item;
     },
     clearTreeItem: function(layer) {
-        if (layer.legend.treeItem && layer.legend.treeItem.parent) {
-            layer.legend.treeItem.parent.remove(layer.legend.treeItem);
+        if (layer.legend.treeItem && layer.legend.treeItem.owner) {
+            layer.legend.treeItem.domObj.store('data', null);
+            layer.legend.treeItem.owner.remove(layer.legend.treeItem);
             layer.legend.treeItem.finalize();
             layer.legend.treeItem = null;
         }
     },
-    stateChanged: function(obj) {
-    //console.log(obj);
+    stateChanged: function(obj, event) {
         if (obj.legend && obj.legend.treeItem.checkBox) {
             if (obj.legend.treeItem.checkBox.checked) {
                 obj.show();
@@ -674,6 +659,7 @@
                 obj.hide();
             }
         }
+        OpenLayers.Event.stop(event, true);
     },
     
     renderFolder: function() {
@@ -719,14 +705,17 @@
             this.domImg.style.backgroundImage = 'url('+this.options.image+')';
         }
         
-        var domA = document.createElement('a');
-        domA.className = 'fusionLegendItem';
-        domA.href = 'javascript:void(0)';
-        domA.innerHTML = this.options.label;
-        OpenLayers.Event.observe(domA, 'click', this.selected, this);
-        OpenLayers.Event.observe(domA, 'dblclick', this.selected, this);
-        OpenLayers.Event.observe(domA, 'contextmenu', this.showMenu, this);
-
+        var domA = new Element('a',{
+            'class': 'fusionLegendItem',
+            href:'javascript:void(0)',
+            html: this.options.label,
+            events: {
+                click: this.selected.bindWithEvent(this),
+                dblclick: this.selected.bindWithEvent(this),
+                contextmenu: this.showMenu.bindWithEvent(this)
+            }
+        });
+        
         domA.appendChild(this.domImg);
         domLabel.appendChild(domA);
         this.itemLabelobj = domA;
@@ -749,14 +738,17 @@
             this.domImg.style.backgroundImage = 'url('+this.options.image+')';
         }
         
-        var domA = document.createElement('a');
-        domA.className = 'fusionLegendItem';
-        domA.href = 'javascript:void(0)';
-        domA.innerHTML = this.options.label;
-        OpenLayers.Event.observe(domA, 'click', this.selected, this);
-        OpenLayers.Event.observe(domA, 'dblclick', this.selected, this);
-        OpenLayers.Event.observe(domA, 'contextmenu', this.showMenu, this);
-
+        var domA = new Element('a',{
+            'class': 'fusionLegendItem',
+            href:'javascript:void(0)',
+            html: this.options.label,
+            events: {
+                click: this.selected.bindWithEvent(this),
+                dblclick: this.selected.bindWithEvent(this),
+                contextmenu: this.showMenu.bindWithEvent(this)
+            }
+        });
+        
         domA.appendChild(this.domImg);
         
         domLabel.appendChild(this.checkBox);



More information about the fusion-commits mailing list