[fusion-commits] r1434 - in sandbox/legendImage: MapServer widgets

svn_fusion at osgeo.org svn_fusion at osgeo.org
Fri Jul 4 10:30:12 EDT 2008


Author: pagameba
Date: 2008-07-04 10:30:12 -0400 (Fri, 04 Jul 2008)
New Revision: 1434

Modified:
   sandbox/legendImage/MapServer/MapServer.js
   sandbox/legendImage/widgets/Legend.js
Log:
update MapServer and Legend widget to support optional use of sprited legend images

Modified: sandbox/legendImage/MapServer/MapServer.js
===================================================================
--- sandbox/legendImage/MapServer/MapServer.js	2008-07-04 14:14:09 UTC (rev 1433)
+++ sandbox/legendImage/MapServer/MapServer.js	2008-07-04 14:30:12 UTC (rev 1434)
@@ -399,6 +399,11 @@
     },
 
     parseMapLayersAndGroups: function(o) {
+        var iconOpt = {
+            url: o.icons_url || null,
+            width: o.icons_width || 16,
+            height: o.icons_height || 16,
+        };
         for (var i=0; i<o.groups.length; i++) {
             var group = new Fusion.Maps.MapServer.Group(o.groups[i], this);
             var parent;
@@ -411,7 +416,7 @@
         }
 
         for (var i=0; i<o.layers.length; i++) {
-            var layer = new Fusion.Maps.MapServer.Layer(o.layers[i], this);
+            var layer = new Fusion.Maps.MapServer.Layer(o.layers[i], this, iconOpt);
             var parent;
             if (layer.parentGroup != '') {
                 parent = this.layerRoot.findGroup(layer.parentGroup);
@@ -803,10 +808,9 @@
 Fusion.Maps.MapServer.Layer = OpenLayers.Class(Fusion.Widget.Map.Group, {
 
     scaleRanges: null,
-
     oMap: null,
 
-    initialize: function(o, oMap) {
+    initialize: function(o, oMap, iconOpt) {
         this.uniqueId = o.uniqueId;
         Fusion.Widget.Map.Layer.prototype.initialize.apply(this, [this.uniqueId]);
         this.oMap = oMap;
@@ -826,10 +830,11 @@
         this.metadata = o.metadata;
         this.extent = o.extent;
         this.scaleRanges = [];
-    		this.minScale = 1.0e10;
-    		this.maxScale = 0;
+		this.minScale = 1.0e10;
+		this.maxScale = 0;
+
         for (var i=0; i<o.scaleRanges.length; i++) {
-            var scaleRange = new Fusion.Maps.MapServer.ScaleRange(o.scaleRanges[i], this.supportsType(4));
+            var scaleRange = new Fusion.Maps.MapServer.ScaleRange(o.scaleRanges[i], this.supportsType(4), iconOpt);
             this.scaleRanges.push(scaleRange);
       			this.minScale = Math.min(this.minScale, scaleRange.minScale);
       			this.maxScale = Math.max(this.maxScale, scaleRange.maxScale);
@@ -892,7 +897,7 @@
 
 Fusion.Maps.MapServer.ScaleRange = OpenLayers.Class({
     styles: null,
-    initialize: function(o, bRaster) {
+    initialize: function(o, bRaster, iconOpt) {
         this.minScale = o.minScale;
         this.maxScale = o.maxScale;
         this.styles = [];
@@ -909,14 +914,14 @@
           tmpsyle.filter = "";
           tmpsyle.index = 0;
           tmpsyle.staticIcon = true;
-          var styleItem = new Fusion.Maps.MapServer.StyleItem(tmpsyle, tmpsyle.staticIcon);
+          var styleItem = new Fusion.Maps.MapServer.StyleItem(tmpsyle, tmpsyle.staticIcon, iconOpt);
           this.styles.push(styleItem);
         }
         else
         {
           var staticIcon = o.styles.length>=1 ? false : bRaster;
           for (var i=0; i<o.styles.length; i++) {
-            var styleItem = new Fusion.Maps.MapServer.StyleItem(o.styles[i], staticIcon);
+            var styleItem = new Fusion.Maps.MapServer.StyleItem(o.styles[i], staticIcon, iconOpt);
             this.styles.push(styleItem);
           }
         }
@@ -934,17 +939,24 @@
 */
 
 Fusion.Maps.MapServer.StyleItem = OpenLayers.Class({
-    initialize: function(o, staticIcon) {
+    initialize: function(o, staticIcon, iconOpt) {
+        this.iconOpt = iconOpt;
+        this.iconX = o.icon_x || 0;
+        this.iconY = o.icon_y || 0;
         this.legendLabel = o.legendLabel;
         this.filter = o.filter;
         this.index = o.index;
         this.staticIcon = staticIcon;
     },
     getLegendImageURL: function(fScale, layer) {
-        var sl = Fusion.getScriptLanguage();
-        var url = Fusion.getFusionURL() + '/' + layer.oMap.arch + '/' + sl  + '/LegendIcon.' + sl;
-        var sessionid = layer.oMap.getSessionID();
-        var params = 'mapname='+layer.oMap._sMapname+"&session="+sessionid + '&layername='+layer.resourceId + '&classindex='+this.index;
-        return url + '?'+params;
+        if (this.iconOpt && this.iconOpt.url) {
+            return this.iconOpt.url;
+        } else {
+            var sl = Fusion.getScriptLanguage();
+            var url = Fusion.getFusionURL() + '/' + layer.oMap.arch + '/' + sl  + '/LegendIcon.' + sl;
+            var sessionid = layer.oMap.getSessionID();
+            var params = 'mapname='+layer.oMap._sMapname+"&session="+sessionid + '&layername='+layer.resourceId + '&classindex='+this.index;
+            return url + '?'+params;            
+        }
     }
 });

Modified: sandbox/legendImage/widgets/Legend.js
===================================================================
--- sandbox/legendImage/widgets/Legend.js	2008-07-04 14:14:09 UTC (rev 1433)
+++ sandbox/legendImage/widgets/Legend.js	2008-07-04 14:30:12 UTC (rev 1434)
@@ -458,11 +458,27 @@
               opt.imgIcon = this.imgLayerRasterIcon;
             }
           } else {
-            opt.imgIcon = style.getLegendImageURL(scale, layer);
+              if (style.iconOpt && style.iconOpt.url) {
+                  opt.imgIcon = Jx.baseUrl+'images/a_pixel.png';
+              } else {
+                opt.imgIcon = style.getLegendImageURL(scale, layer);                  
+              }
           }
         }
        
         var item = new Jx.TreeItem(opt);
+        if (style && style.iconX >= 0 && style.iconY >= 0) {
+            var img = item.domObj.childNodes[1];
+            img.style.backgroundImage = 'url('+style.getLegendImageURL(scale, layer)+')';
+            img.src = Jx.baseURL+'images/a_pixel.png';
+            img.style.backgroundPosition = (-1*style.iconX) + 'px ' + (-1*style.iconY) + 'px';
+            if (style.iconOpt.width) {
+                img.style.width = style.iconOpt.width + 'px';
+            }
+            if (style.iconOpt.height) {
+                img.style.height = style.iconOpt.height + 'px';
+            }
+        }
         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 */



More information about the fusion-commits mailing list