[Commits] r2853 - in core/trunk/geoext: lib/GeoExt/widgets tests/lib/GeoExt/widgets

commits at geoext.org commits at geoext.org
Thu Oct 6 20:18:11 CEST 2011


Author: ahocevar
Date: 2011-10-06 20:18:11 +0200 (Thu, 06 Oct 2011)
New Revision: 2853

Modified:
   core/trunk/geoext/lib/GeoExt/widgets/WMSLegend.js
   core/trunk/geoext/tests/lib/GeoExt/widgets/WMSLegend.html
Log:
smarter handling of FORMAT parameter. r=bartvde (closes #434)

Modified: core/trunk/geoext/lib/GeoExt/widgets/WMSLegend.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/widgets/WMSLegend.js	2011-10-06 15:16:29 UTC (rev 2852)
+++ core/trunk/geoext/lib/GeoExt/widgets/WMSLegend.js	2011-10-06 18:18:11 UTC (rev 2853)
@@ -141,22 +141,23 @@
                 FORMAT: null
             });
         }
-        // add scale parameter - also if we have the url from the record's
-        // styles data field and it is actually a GetLegendGraphic request.
-        if(this.useScaleParameter === true &&
-                url.toLowerCase().indexOf("request=getlegendgraphic") != -1) {
-            var scale = layer.map.getScale();
-            url = Ext.urlAppend(url, "SCALE=" + scale);
+        if (url.toLowerCase().indexOf("request=getlegendgraphic") != -1) {
+            if (url.toLowerCase().indexOf("format=") == -1) {
+                url = Ext.urlAppend(url, "FORMAT=image/gif");
+            }
+            // add scale parameter - also if we have the url from the record's
+            // styles data field and it is actually a GetLegendGraphic request.
+            if (this.useScaleParameter === true) {
+                var scale = layer.map.getScale();
+                url = Ext.urlAppend(url, "SCALE=" + scale);
+            }
         }
-        var params = this.baseParams || {};
-        Ext.applyIf(params, {FORMAT: 'image/gif'});
+        var params = Ext.apply({}, this.baseParams);
         if (layer.params._OLSALT) {
             // update legend after a forced layer redraw
             params._OLSALT = layer.params._OLSALT;
         }
-        if(url.indexOf('?') > 0) {
-            url = Ext.urlEncode(params, url);
-        }
+        url = Ext.urlAppend(url, Ext.urlEncode(params));
         
         return url;
     },
@@ -218,7 +219,7 @@
      */
     beforeDestroy: function() {
         if (this.useScaleParameter === true) {
-            var layer = this.layerRecord.getLayer()
+            var layer = this.layerRecord.getLayer();
             layer && layer.events &&
                 layer.events.unregister("moveend", this, this.onLayerMoveend);
         }

Modified: core/trunk/geoext/tests/lib/GeoExt/widgets/WMSLegend.html
===================================================================
--- core/trunk/geoext/tests/lib/GeoExt/widgets/WMSLegend.html	2011-10-06 15:16:29 UTC (rev 2852)
+++ core/trunk/geoext/tests/lib/GeoExt/widgets/WMSLegend.html	2011-10-06 18:18:11 UTC (rev 2853)
@@ -61,7 +61,7 @@
         }
 
         function test_legendurl(t) {
-            t.plan(9);
+            t.plan(11);
 
             var l, url, expectedUrl;
             var mapPanel = loadMapPanel(false);
@@ -104,8 +104,35 @@
             l.destroy();
             
             mapPanel.map.layers[0].params.STYLES = "bar";
+
             mapPanel.layers.getAt(0).set("styles", [{
                 name: "bar",
+                legend: {href: "foo?request=getlegendgraphic&format=image/jpeg"}
+            }]);
+            l = new GeoExt.WMSLegend({
+                renderTo: 'legendwms',
+                layerRecord: mapPanel.layers.getAt(0)
+            });
+            l.render();
+            url = l.items.get(1).url;
+            t.eq(url, "foo?request=getlegendgraphic&format=image/jpeg&SCALE=" + mapPanel.map.getScale(), "legend url from styles field of layer record used correctly.");
+            l.destroy();
+
+            mapPanel.layers.getAt(0).set("styles", [{
+                name: "bar",
+                legend: {href: "foo?request=getlegendgraphic"}
+            }]);
+            l = new GeoExt.WMSLegend({
+                renderTo: 'legendwms',
+                layerRecord: mapPanel.layers.getAt(0)
+            });
+            l.render();
+            url = l.items.get(1).url;
+            t.eq(url, "foo?request=getlegendgraphic&FORMAT=image/gif&SCALE=" + mapPanel.map.getScale(), "legend url from styles field with default format.");
+            l.destroy();
+
+            mapPanel.layers.getAt(0).set("styles", [{
+                name: "bar",
                 legend: {href: "foo"}
             }]);
             l = new GeoExt.WMSLegend({
@@ -116,6 +143,7 @@
             url = l.items.get(1).url;
             t.eq(url, "foo", "legend url from styles field of layer record used correctly.");
             l.destroy();
+
             mapPanel.map.layers[0].params.STYLES = "";
             
             l = new GeoExt.WMSLegend({



More information about the Commits mailing list