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

commits at geoext.org commits at geoext.org
Mon Sep 27 18:06:33 CEST 2010


Author: ahocevar
Date: 2010-09-27 18:06:33 +0200 (Mon, 27 Sep 2010)
New Revision: 2413

Modified:
   core/trunk/geoext/lib/GeoExt/widgets/WMSLegend.js
   core/trunk/geoext/tests/lib/GeoExt/widgets/WMSLegend.html
Log:
Make sure that legend image is rendered, even if instance is created before the layer is added to a map. r=tschaub (closes #350)


Modified: core/trunk/geoext/lib/GeoExt/widgets/WMSLegend.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/widgets/WMSLegend.js	2010-09-27 09:32:14 UTC (rev 2412)
+++ core/trunk/geoext/lib/GeoExt/widgets/WMSLegend.js	2010-09-27 16:06:33 UTC (rev 2413)
@@ -79,9 +79,8 @@
     initComponent: function() {
         GeoExt.WMSLegend.superclass.initComponent.call(this);
         var layer = this.layerRecord.getLayer();
-        if (this.useScaleParameter === true) {
-            layer.events.register("moveend", this, this.onLayerMoveend);
-        }
+        this._noMap = !layer.map;
+        layer.events.register("moveend", this, this.onLayerMoveend);
         this.update();
     },
     
@@ -89,7 +88,9 @@
      *  :param e: ``Object``
      */
     onLayerMoveend: function(e) {
-        if (e.zoomChanged === true) {
+        if ((e.zoomChanged === true && this.useScaleParameter === true) ||
+                                                                this._noMap) {
+            delete this._noMap;
             this.update();
         }
     },

Modified: core/trunk/geoext/tests/lib/GeoExt/widgets/WMSLegend.html
===================================================================
--- core/trunk/geoext/tests/lib/GeoExt/widgets/WMSLegend.html	2010-09-27 09:32:14 UTC (rev 2412)
+++ core/trunk/geoext/tests/lib/GeoExt/widgets/WMSLegend.html	2010-09-27 16:06:33 UTC (rev 2413)
@@ -8,12 +8,13 @@
 
     <script type="text/javascript">
 
-        function loadMapPanel() {
+        function loadMapPanel(render) {
+            var renderTo = render === false ? null : "mappanel";
             var mapPanel = new GeoExt.MapPanel({
                 // panel options
                 id: "map-panel",
                 title: "GeoExt MapPanel",
-                renderTo: "mappanel",
+                renderTo: renderTo,
                 height: 400,
                 width: 600,
                 // map panel-specific options
@@ -60,10 +61,10 @@
         }
 
         function test_legendurl(t) {
-            t.plan(8);
+            t.plan(9);
 
             var l, url, expectedUrl;
-            var mapPanel = loadMapPanel();
+            var mapPanel = loadMapPanel(false);
 
             l = new GeoExt.WMSLegend({
                 renderTo: 'legendwms',
@@ -71,9 +72,10 @@
                 useScaleParameter: false,
                 layerRecord: mapPanel.layers.getAt(0)
             });
-            l.render();
+            mapPanel.render("mappanel");
 
-            url = l.items.get(1).url;
+            url = l.items.get(1) && l.items.get(1).url;
+            t.eq(!!url, true, "legend image loaded even when MapPanel is not rendered at legend instantiation.")
             expectedUrl = "/ows?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&EXCEPTIONS=application%2Fvnd.ogc.se_xml&LAYER=a&FORMAT=image%2Fpng&foo=bar%20bar";
             t.eq(url, expectedUrl, "GetLegendGraphic url is generated correctly");
             l.destroy()



More information about the Commits mailing list