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

commits at geoext.org commits at geoext.org
Fri Oct 9 20:42:57 CEST 2009


Author: tschaub
Date: 2009-10-09 20:42:57 +0200 (Fri, 09 Oct 2009)
New Revision: 1406

Modified:
   core/trunk/geoext/lib/GeoExt/widgets/LegendWMS.js
   core/trunk/geoext/tests/lib/GeoExt/widgets/LegendWMS.html
Log:
Properly including the STYLE parameter (instead of STYLES) in GetLegendGraphic requests.  Patch from Bart.  r=me (closes #163)

Modified: core/trunk/geoext/lib/GeoExt/widgets/LegendWMS.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/widgets/LegendWMS.js	2009-10-09 17:19:16 UTC (rev 1405)
+++ core/trunk/geoext/lib/GeoExt/widgets/LegendWMS.js	2009-10-09 18:42:57 UTC (rev 1406)
@@ -89,22 +89,19 @@
      */
     getLegendUrl: function(layerName, layerNames) {
         var url;
- 
-        // check if we have a legend URL in the record's
-        // "styles" data field
         var styles = this.record && this.record.get("styles");
-        if(styles && styles.length > 0) {
-            layerNames = layerNames ||
-                         (this.layer.params.LAYERS instanceof Array) ?
-                            this.layer.params.LAYERS :
-                            this.layer.params.LAYERS.split(",");
+        var layerNames = layerNames ||
+                             (this.layer.params.LAYERS instanceof Array) ?
+                             this.layer.params.LAYERS :
+                             this.layer.params.LAYERS.split(",");
 
-            var styleNames = this.layer.params.STYLES &&
+        var styleNames = this.layer.params.STYLES &&
                              this.layer.params.STYLES.split(",");
-
-            var idx = layerNames.indexOf(layerName);
-            var styleName = styleNames && styleNames[idx];
-
+        var idx = layerNames.indexOf(layerName);
+        var styleName = styleNames && styleNames[idx];
+        // check if we have a legend URL in the record's
+        // "styles" data field
+        if(styles && styles.length > 0) {
             if(styleName) {
                 Ext.each(styles, function(s) {
                     url = (s.name == styleName && s.legend) && s.legend.href;
@@ -115,7 +112,6 @@
                 url = styles[0].legend && styles[0].legend.href;
             }
         }
-
         return url ||
                this.layer.getFullRequestString({
                    REQUEST: "GetLegendGraphic",
@@ -124,6 +120,8 @@
                    EXCEPTIONS: "application/vnd.ogc.se_xml",
                    LAYER: layerName,
                    LAYERS: null,
+                   STYLE: (styleName !== '') ? styleName: null,
+                   STYLES: null,
                    SRS: null,
                    FORMAT: this.imageFormat
         });

Modified: core/trunk/geoext/tests/lib/GeoExt/widgets/LegendWMS.html
===================================================================
--- core/trunk/geoext/tests/lib/GeoExt/widgets/LegendWMS.html	2009-10-09 17:19:16 UTC (rev 1405)
+++ core/trunk/geoext/tests/lib/GeoExt/widgets/LegendWMS.html	2009-10-09 18:42:57 UTC (rev 1406)
@@ -39,7 +39,7 @@
             l.render();
 
             url = l.items.get(0).url;
-            expectedUrl = "/ows?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&STYLES=&EXCEPTIONS=application%2Fvnd.ogc.se_xml&FORMAT=image%2Fgif&LAYER=a";
+            expectedUrl = "/ows?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&EXCEPTIONS=application%2Fvnd.ogc.se_xml&FORMAT=image%2Fgif&LAYER=a";
             t.eq(url, expectedUrl, "GetLegendGraphic url is generated correctly");
             l.destroy()
             
@@ -76,7 +76,7 @@
             });
             l.render();
             url = l.items.get(0).url;
-            expectedUrl = "/ows?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&STYLES=&EXCEPTIONS=application%2Fvnd.ogc.se_xml&FORMAT=image%2Fgif&SLD=sld&LAYER=a";
+            expectedUrl = "/ows?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&EXCEPTIONS=application%2Fvnd.ogc.se_xml&FORMAT=image%2Fgif&SLD=sld&LAYER=a";
             t.eq(url, expectedUrl, "GetLegendGraphic url is generated when layer has SLD set");
             l.destroy();
             delete mapPanel.map.layers[0].params.SLD;
@@ -89,7 +89,7 @@
             });
             l.render();
             url = l.items.get(0).url;
-            expectedUrl = "/ows?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&STYLES=&EXCEPTIONS=application%2Fvnd.ogc.se_xml&FORMAT=image%2Fgif&SLD_BODY=sld_body&LAYER=a";
+            expectedUrl = "/ows?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&EXCEPTIONS=application%2Fvnd.ogc.se_xml&FORMAT=image%2Fgif&SLD_BODY=sld_body&LAYER=a";
             t.eq(url, expectedUrl, "GetLegendGraphic url is generated when layer has SLD_BODY set");
             l.destroy();
             delete mapPanel.map.layers[0].params.SLD_BODY;
@@ -133,10 +133,10 @@
             l.updateLegend();
             t.ok(l.getComponent("b"),
                  "updateLegend does not remove components to be updated");
-            expectedUrl = "/ows?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&STYLES=&EXCEPTIONS=application%2Fvnd.ogc.se_xml&FORMAT=image%2Fgif&FOO=bar&LAYER=b";
+            expectedUrl = "/ows?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&EXCEPTIONS=application%2Fvnd.ogc.se_xml&FORMAT=image%2Fgif&FOO=bar&LAYER=b";
             t.eq(l.getComponent("b").url, expectedUrl,
                  "updateLegend updates component URL");
-            expectedUrl = "/ows?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&STYLES=&EXCEPTIONS=application%2Fvnd.ogc.se_xml&FORMAT=image%2Fgif&FOO=bar&LAYER=c";
+            expectedUrl = "/ows?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&EXCEPTIONS=application%2Fvnd.ogc.se_xml&FORMAT=image%2Fgif&FOO=bar&LAYER=c";
             t.eq(l.getComponent("c").url, expectedUrl,
                  "updateLegend sets correct URL in new component");
 
@@ -145,10 +145,10 @@
                 layers: "c",
                 styles: "style1"
             });
-            expectedUrl = "/ows?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&STYLES=style1&EXCEPTIONS=application%2Fvnd.ogc.se_xml&FORMAT=image%2Fgif&FOO=bar&LAYER=c";
+            expectedUrl = "/ows?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&EXCEPTIONS=application%2Fvnd.ogc.se_xml&FORMAT=image%2Fgif&FOO=bar&LAYER=c&STYLE=style1";
             l.updateLegend();
             t.eq(l.getComponent("c").url, expectedUrl,
-                 "updateLegend sets correct STYLES params in URL");
+                 "updateLegend sets correct STYLE params in URL");
 
             // #4
             layerRecord.set("styles", [{



More information about the Commits mailing list