[fusion-commits] r1234 - in branches/fusion-1.0: MapGuide lib widgets

svn_fusion at osgeo.org svn_fusion at osgeo.org
Mon Mar 10 15:08:56 EDT 2008


Author: pagameba
Date: 2008-03-10 15:08:56 -0400 (Mon, 10 Mar 2008)
New Revision: 1234

Modified:
   branches/fusion-1.0/MapGuide/MapGuide.js
   branches/fusion-1.0/lib/ApplicationDefinition.js
   branches/fusion-1.0/widgets/Legend.js
Log:
Re #20. Merge changes into fusion-1.0 branch

Modified: branches/fusion-1.0/MapGuide/MapGuide.js
===================================================================
--- branches/fusion-1.0/MapGuide/MapGuide.js	2008-03-10 17:46:45 UTC (rev 1233)
+++ branches/fusion-1.0/MapGuide/MapGuide.js	2008-03-10 19:08:56 UTC (rev 1234)
@@ -67,7 +67,7 @@
         if (isMapWidgetLayer != null) {
             this.bIsMapWidgetLayer = isMapWidgetLayer;
         }
-        
+        this.mapInfo = mapTag.mapInfo;
         var extension = mapTag.extension; //TBD: this belongs in layer tag?
         this.selectionType = extension.SelectionType ? extension.SelectionType[0] : 'INTERSECTS';
         this.ratio = extension.MapRatio ? extension.MapRatio[0] : 1.0;
@@ -265,9 +265,6 @@
               }
             }
 
-            //TODO: get this from the layerTag.extension
-            //this.oMapInfo = Fusion.oConfigMgr.getMapInfo(this._sResourceId);
-
             //set projection units and code if supplied
             //TODO: consider passing the metersPerUnit value into the framework
             //to allow for scaling that doesn't match any of the pre-canned units
@@ -802,56 +799,103 @@
         Fusion.ajaxRequest(loadmapScript, options);
     },
     
-    showLayer: function( layer ) {
-        if (this.oMapInfo && this.oMapInfo.layerEvents[layer.layerName]) {
-            var layerEvent = this.oMapInfo.layerEvents[layer.layerName];
-            for (var i=0; i<layerEvent.onEnable.length; i++) {
-                var l = this.layerRoot.findLayer(layerEvent.onEnable[i].name);
-                if (l) {
-                    if (layerEvent.onEnable[i].enable) {
-                        l.show();
-                    } else {
-                        l.hide();
+    processLayerEvents: function(layer, isEnabling) {
+        if (this.mapInfo && this.mapInfo.mapEvents.layerEvents[layer.layerName]) {
+            var layerEvent = this.mapInfo.mapEvents.layerEvents[layer.layerName];
+            var events = isEnabling ? layerEvent.onEnable : layerEvent.onDisable;
+            for (var i=0; i<events.length; i++) {
+                var o = events[i];
+                if (o.type == 'layer') {
+                    var l = this.layerRoot.findLayer(o.name);
+                    if (l) {
+                        if (o.enable) {
+                            l.show(true);
+                        } else {
+                            l.hide(true);
+                        }
                     }
+                    
+                } else if (o.type == 'group') {
+                    var g = this.layerRoot.findGroupByAttribute('groupName', o.name);
+                    if (g) {
+                        if (o.enable) {
+                            g.show(true);
+                        } else {
+                            g.hide(true);
+                        }
+                    }
                 }
             }
         }
-        this.aShowLayers.push(layer.uniqueId);
-        this.drawMap();
     },
     
-    hideLayer: function( layer ) {
-        if (this.oMapInfo && this.oMapInfo.layerEvents[layer.layerName]) {
-            var layerEvent = this.oMapInfo.layerEvents[layer.layerName];
-            for (var i=0; i<layerEvent.onDisable.length; i++) {
-                var l = this.layerRoot.findLayer(layerEvent.onDisable[i].name);
-                if (l) {
-                    if (layerEvent.onDisable[i].enable) {
-                        l.show();
-                    } else {
-                        l.hide();
+    processGroupEvents: function(group, isEnabling) {
+        if (this.mapInfo && this.mapInfo.mapEvents.groupEvents[group.groupName]) {
+            var groupEvent = this.mapInfo.mapEvents.groupEvents[group.groupName];
+            var events = isEnabling ? groupEvent.onEnable : groupEvent.onDisable;
+            for (var i=0; i<events.length; i++) {
+                var o = events[i];
+                if (o.type == 'layer') {
+                    var l = this.layerRoot.findLayer(o.name);
+                    if (l) {
+                        if (o.enable) {
+                            l.show(true);
+                        } else {
+                            l.hide(true);
+                        }
                     }
+                    
+                } else if (o.type == 'group') {
+                    var g = this.layerRoot.findGroupByAttribute('groupName', o.name);
+                    if (g) {
+                        if (o.enable) {
+                            g.show(true);
+                        } else {
+                            g.hide(true);
+                        }
+                    }
                 }
             }
-        }        
+        }
+    },
+        
+    showLayer: function( layer, noDraw ) {
+        this.processLayerEvents(layer, true);
+        this.aShowLayers.push(layer.uniqueId);
+        if (!noDraw) {
+            this.drawMap();
+        }
+    },
+    
+    hideLayer: function( layer, noDraw ) {
+        this.processLayerEvents(layer, false);
         this.aHideLayers.push(layer.uniqueId);
-        this.drawMap();
+        if (!noDraw) {
+            this.drawMap();
+        }
     },
-    showGroup: function( group ) {
-      if (group.groupName == 'layerRoot') {
-        this.oLayerOL.setVisibility(true);
-      } else {
-        this.aShowGroups.push(group.uniqueId);
-        this.drawMap();
-      }
+    
+    showGroup: function( group, noDraw ) {
+        this.processGroupEvents(group, true);
+        if (group.groupName == 'layerRoot') {
+            this.oLayerOL.setVisibility(true);
+        } else {
+            this.aShowGroups.push(group.uniqueId);
+            if (!noDraw) {
+                this.drawMap();
+            }
+        }
     },
-    hideGroup: function( group ) {
-      if (group.groupName == 'layerRoot') {
-        this.oLayerOL.setVisibility(false);
-      } else {
-        this.aHideGroups.push(group.uniqueId);
-        this.drawMap();
-      }
+    hideGroup: function( group, noDraw ) {
+        this.processGroupEvents(group, false);
+        if (group.groupName == 'layerRoot') {
+            this.oLayerOL.setVisibility(false);
+        } else {
+            this.aHideGroups.push(group.uniqueId);
+            if (!noDraw) {
+                this.drawMap();
+            }
+        }
     },
     refreshLayer: function( layer ) {
         this.aRefreshLayers.push(layer.uniqueId);        
@@ -876,6 +920,28 @@
         var params = {};
         params.parameters = 'session='+this.getSessionID();
         Fusion.ajaxRequest(s, params);
+    },
+    getGroupInfoUrl: function(groupName) {
+        if (this.mapInfo) {
+            var groups = this.mapInfo.links.groups;
+            for (var i=0; i<groups.length; i++) {
+                if (groups[i].name == groupName) {
+                    return groups[i].url;
+                }
+            }
+        }
+        return null;
+    },
+    getLayerInfoUrl: function(layerName) {
+        if (this.mapInfo) {
+            var layers = this.mapInfo.links.layers;
+            for (var i=0; i<layers.length; i++) {
+                if (layers[i].name == layerName) {
+                    return layers[i].url;
+                }
+            }
+        }
+        return null;
     }
 };
     
@@ -902,22 +968,22 @@
         this.actuallyVisible = o.actuallyVisible;
     },
     
-    show: function() {
+    show: function(noDraw) {
         if (this.visible) {
             return;
         }
-        this.oMap.showGroup(this);
+        this.oMap.showGroup(this, noDraw ? true : false);
         this.visible = true;
         if (this.legend && this.legend.checkBox) {
             this.legend.checkBox.checked = true;
         }
     },
     
-    hide: function() {
+    hide: function(noDraw) {
         if (!this.visible) {
             return;
         }
-        this.oMap.hideGroup(this);
+        this.oMap.hideGroup(this, noDraw ? true : false);
         this.visible = false;
         if (this.legend && this.legend.checkBox) {
             this.legend.checkBox.checked = false;
@@ -997,22 +1063,22 @@
         return null;
     },
 
-    show: function() {
+    show: function(noDraw) {
         if (this.visible) {
             return;
         }
-        this.oMap.showLayer(this);
+        this.oMap.showLayer(this, noDraw ? true : false);
         this.set('visible', true);
         if (this.legend && this.legend.checkBox) {
             this.legend.checkBox.checked = true;
         }
     },
 
-    hide: function() {
+    hide: function(noDraw) {
         if (!this.visible) {
             return;
         }
-        this.oMap.hideLayer(this);
+        this.oMap.hideLayer(this, noDraw ? true : false);
         this.set('visible',false);
         if (this.legend && this.legend.checkBox) {
             this.legend.checkBox.checked = false;

Modified: branches/fusion-1.0/lib/ApplicationDefinition.js
===================================================================
--- branches/fusion-1.0/lib/ApplicationDefinition.js	2008-03-10 17:46:45 UTC (rev 1233)
+++ branches/fusion-1.0/lib/ApplicationDefinition.js	2008-03-10 19:08:56 UTC (rev 1234)
@@ -418,63 +418,87 @@
         if (jsonNode.Map instanceof Array) {
             for (var i=0; i<jsonNode.Map.length; i++) {
                 var map = new Fusion.Lib.ApplicationDefinition.Map(jsonNode.Map[i]);
-                this.maps.push(map);
-            }
-        } else {
-            //TODO: do we need a warning that there are no layers in this map?
-        }
-        this.links = {groups:[], layers:[]};
-        this.layerEvents = {};
-        if (jsonNode.Extension) {
-            var extension = jsonNode.Extension[0];
-            if (extension.Links) {
-                /* process Groups */
-                if (extension.Links[0].Group instanceof Array) {
-                    for (var j=0; j<extension.Links[0].Group.length; j++) {
-                        var group = extension.Links[0].Group[j];
-                        this.links.groups.push({name:group.Name,url:group.Url});
+                var links = {groups:[], layers:[]};
+                var mapEvents = {layerEvents:{},groupEvents:{}};
+                if (jsonNode.Map[i].Extension) {
+                    var extension = jsonNode.Map[i].Extension[0];
+                    if (extension.Links) {
+                        /* process Groups */
+                        if (extension.Links[0].Group instanceof Array) {
+                            for (var j=0; j<extension.Links[0].Group.length; j++) {
+                                var group = extension.Links[0].Group[j];
+                                links.groups.push({name:group.Name,url:group.Url});
+                            }
+                        }
+                        if (extension.Links[0].Layer instanceof Array) {
+                            for (var j=0; j<extension.Links[0].Layer.length; j++) {
+                                var layer = extension.Links[0].Layer[j];
+                                links.layers.push({name:layer.Name,url:layer.Url});
+                            }
+                        }
                     }
-                }
-                if (extension.Links[0].Layer instanceof Array) {
-                    for (var j=0; j<extension.Links[0].Layer.length; j++) {
-                        var layer = extension.Links[0].Layer[j];
-                        this.links.layers.push({name:layer.Name,url:layer.Url});
-                    }
-                }
-            }
-            /* process layer events */
-            //TODO: Should this be called MapEvents?
-            if (extension.LayerEvents) {
-                if (extension.LayerEvents[0].Layer instanceof Array) {
-                    for (var j=0; j<extension.LayerEvents[0].Layer.length; j++) {
-                        var layer = extension.LayerEvents[0].Layer[j];
-                        var layerObj = {};
-                        layerObj.name = layer.Name[0];
-                        layerObj.onEnable = [];
-                        layerObj.onDisable = [];
-                        
-                        if (layer.OnEnable instanceof Array) {
-                            for (var k=0; k<layer.OnEnable[0].Layer.length; k++) {
-                                var kLayer = layer.OnEnable[0].Layer[k];
-                                layerObj.onEnable.push({name:kLayer.Name[0], enable: kLayer.Enable[0] == 'true' ? true : false});
+                    /* process layer events */
+                    //TODO: Should this be called MapEvents?
+                    if (extension.MapEvents) {
+                        if (extension.MapEvents[0].Layer instanceof Array) {
+                            for (var j=0; j<extension.MapEvents[0].Layer.length; j++) {
+                                var layer = extension.MapEvents[0].Layer[j];
+                                var layerObj = {};
+                                layerObj.name = layer.Name[0];
+                                layerObj.onEnable = [];
+                                if (layer.OnEnable instanceof Array) {
+                                    layerObj.onEnable = this.parseMapEventSubBlock(layer.OnEnable[0]);
+                                }
+                                layerObj.onDisable = [];
+                                if (layer.OnDisable instanceof Array) {
+                                    layerObj.onDisable = this.parseMapEventSubBlock(layer.OnDisable[0]);
+                                }
+                                mapEvents.layerEvents[layerObj.name] = layerObj;
                             }
                         }
-                        if (layer.OnDisable instanceof Array) {
-                            for (var k=0; k<layer.OnDisable[0].Layer.length; k++) {
-                                var kLayer = layer.OnDisable[0].Layer[k];
-                                layerObj.onDisable.push({name:kLayer.Name[0], enable: kLayer.Enable[0] == 'true' ? true : false});
+                        if (extension.MapEvents[0].Group instanceof Array) {
+                            for (var j=0; j<extension.MapEvents[0].Group.length; j++) {
+                                var group = extension.MapEvents[0].Group[j];
+                                var groupObj = {};
+                                groupObj.name = group.Name[0];
+                                groupObj.onEnable = [];
+                                if (layer.OnEnable instanceof Array) {
+                                    groupObj.onEnable = this.parseMapEventSubBlock(group.OnEnable[0]);
+                                }
+                                groupObj.onDisable = [];
+                                if (layer.OnDisable instanceof Array) {
+                                    groupObj.onDisable = this.parseMapEventSubBlock(group.OnDisable[0]);
+                                }
+                                mapEvents.groupEvents[groupObj.name] = groupObj;
                             }
                         }
-                        this.layerEvents[layerObj.name] = layerObj;
                     }
                 }
+                map.mapInfo = {links: links, mapEvents: mapEvents};
+                this.maps.push(map);
             }
         } else {
-            this.extension = {};
+            //TODO: do we need a warning that there are no layers in this map?
         }
-        
     },
     
+    parseMapEventSubBlock: function(block) {
+        var a = [];
+        if (block.Layer && block.Layer instanceof Array) {
+            for (var i=0; i<block.Layer.length; i++) {
+                var layer = block.Layer[i];
+                a.push({type: 'layer', name:layer.Name[0], enable: layer.Enable[0] == 'true' ? true : false});
+            }
+        }
+        if (block.Group && block.Group instanceof Array) {
+            for (var i=0; i<block.Group.length; i++) {
+                var group = block.Group[i];
+                a.push({type: 'group', name:group.Name[0], enable: group.Enable[0] == 'true' ? true : false});
+            }            
+        }
+        return a;
+    },
+    
     getInitialView: function() {
         return this.initialView;
     },

Modified: branches/fusion-1.0/widgets/Legend.js
===================================================================
--- branches/fusion-1.0/widgets/Legend.js	2008-03-10 17:46:45 UTC (rev 1233)
+++ branches/fusion-1.0/widgets/Legend.js	2008-03-10 19:08:56 UTC (rev 1234)
@@ -210,7 +210,6 @@
         if (this.showRootFolder) {
             this.oRoot.setName(map.getMapTitle());
         }
-        this.oMapInfo = map.oMapInfo;
         var startGroup = map.layerRoot;
         if (!this.showMapFolder) {
           startGroup = map.layerRoot.groups[0];
@@ -247,7 +246,7 @@
             group.legend.checkBox.checked = group.visible?true:false;
             Event.observe(group.legend.checkBox, 'click', this.stateChanged.bind(this, group));
             Event.observe(group.legend.treeItem.domObj, 'mouseover', this.setFolder.bind(this));
-            var groupInfo = this.getGroupInfoUrl(group.groupName);
+            var groupInfo = group.oMap.getGroupInfoUrl(group.groupName);
             if (groupInfo) {
                 var a = document.createElement('a');
                 a.href = groupInfo;
@@ -424,7 +423,7 @@
         opt.imgTreeFolder = this.imgLayerThemeIcon;
         var folder = new Jx.TreeFolder(opt);
         folder.domObj.insertBefore(layer.legend.checkBox, folder.domObj.childNodes[1]);
-        var layerInfo = this.getLayerInfoUrl(layer.layerName);
+        var layerInfo = layer.oMap.getLayerInfoUrl(layer.layerName);
         if (layerInfo) {
             var a = document.createElement('a');
             a.href = layerInfo;
@@ -468,7 +467,7 @@
         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 */
-            var layerInfo = this.getLayerInfoUrl(layer.layerName);
+            var layerInfo = layer.oMap.getLayerInfoUrl(layer.layerName);
             if (layerInfo) {
                 var a = document.createElement('a');
                 a.href = layerInfo;
@@ -500,27 +499,5 @@
                 obj.hide();
             }
         }
-    },
-    getGroupInfoUrl: function(groupName) {
-        if (this.oMapInfo) {
-            var groups = this.oMapInfo.links.groups;
-            for (var i=0; i<groups.length; i++) {
-                if (groups[i].name == groupName) {
-                    return groups[i].url;
-                }
-            }
-        }
-        return null;
-    },
-    getLayerInfoUrl: function(layerName) {
-        if (this.oMapInfo) {
-            var layers = this.oMapInfo.links.layers;
-            for (var i=0; i<layers.length; i++) {
-                if (layers[i].name == layerName) {
-                    return layers[i].url;
-                }
-            }
-        }
-        return null;
     }
 };



More information about the fusion-commits mailing list