[Commits] r2358 - core/trunk/geoext/lib/GeoExt/widgets

commits at geoext.org commits at geoext.org
Wed Sep 15 21:50:36 CEST 2010


Author: ahocevar
Date: 2010-09-15 21:50:36 +0200 (Wed, 15 Sep 2010)
New Revision: 2358

Modified:
   core/trunk/geoext/lib/GeoExt/widgets/LegendPanel.js
   core/trunk/geoext/lib/GeoExt/widgets/WMSLegend.js
Log:
made WMSLegend work with layers that are not added to a map. r=tschaub (closes #337)


Modified: core/trunk/geoext/lib/GeoExt/widgets/LegendPanel.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/widgets/LegendPanel.js	2010-09-15 14:49:35 UTC (rev 2357)
+++ core/trunk/geoext/lib/GeoExt/widgets/LegendPanel.js	2010-09-15 19:50:36 UTC (rev 2358)
@@ -210,7 +210,8 @@
                     xtype: types[0],
                     id: this.getIdForLayer(layer),
                     layerRecord: record,
-                    hidden: !(layer.getVisibility() && layer.calculateInRange())
+                    hidden: !((!layer.map && layer.visibility) ||
+                        (layer.getVisibility() && layer.calculateInRange()))
                 });
             }
         }

Modified: core/trunk/geoext/lib/GeoExt/widgets/WMSLegend.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/widgets/WMSLegend.js	2010-09-15 14:49:35 UTC (rev 2357)
+++ core/trunk/geoext/lib/GeoExt/widgets/WMSLegend.js	2010-09-15 19:50:36 UTC (rev 2358)
@@ -57,11 +57,6 @@
      */
     useScaleParameter: true,
     
-    /** private: property[map]
-     *  ``OpenLayers.Map`` The map to register events to.
-     */
-    map: null,
-
     /** private: method[initComponent]
      *  Initializes the WMS legend. For group layers it will create multiple
      *  image box components.
@@ -69,12 +64,20 @@
     initComponent: function() {
         GeoExt.WMSLegend.superclass.initComponent.call(this);
         var layer = this.layerRecord.getLayer();
-        this.map = layer.map;
         if (this.useScaleParameter === true) {
-            this.map.events.register("zoomend", this, this.update);
+            layer.events.register("moveend", this, this.onLayerMoveend);
         }
         this.update();
     },
+    
+    /** private: method[onLayerMoveend]
+     *  :param e: ``Object``
+     */
+    onLayerMoveend: function(e) {
+        if (e.zoomChanged === true) {
+            this.update();
+        }
+    },
 
     /** private: method[getLegendUrl]
      *  :param layerName: ``String`` A sublayer.
@@ -126,7 +129,7 @@
         // styles data field and it is actually a GetLegendGraphic request.
         if(this.useScaleParameter === true &&
                 url.toLowerCase().indexOf("request=getlegendgraphic") != -1) {
-            var scale = this.map.getScale();
+            var scale = layer.map.getScale();
             url = Ext.urlAppend(url, "SCALE=" + scale);
         }
         
@@ -191,10 +194,9 @@
     beforeDestroy: function() {
         if (this.useScaleParameter === true) {
             var layer = this.layerRecord.getLayer()
-            this.map && this.map.events &&
-                this.map.events.unregister("zoomend", this, this.update);
+            layer && layer.events &&
+                layer.events.unregister("moveend", this, this.onLayerMoveend);
         }
-        delete this.map;
         GeoExt.WMSLegend.superclass.beforeDestroy.apply(this, arguments);
     }
 



More information about the Commits mailing list