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

commits at geoext.org commits at geoext.org
Sat May 23 08:21:00 CEST 2009


Author: tschaub
Date: 2009-05-23 08:21:00 +0200 (Sat, 23 May 2009)
New Revision: 862

Modified:
   core/trunk/geoext/lib/GeoExt/widgets/MapPanel.js
   core/trunk/geoext/tests/lib/GeoExt/widgets/MapPanel.html
Log:
In cases where a MapPanel creates a map, it should also destroy the map.  r=ahocevar (closes #72)

Modified: core/trunk/geoext/lib/GeoExt/widgets/MapPanel.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/widgets/MapPanel.js	2009-05-23 06:17:05 UTC (rev 861)
+++ core/trunk/geoext/lib/GeoExt/widgets/MapPanel.js	2009-05-23 06:21:00 UTC (rev 862)
@@ -170,14 +170,26 @@
         this.updateMapSize();
     },
     
-    /** private: method[onDestroy]
+    /** private: method[beforeDestroy]
      *  Private method called during the destroy sequence.
      */
-    onDestroy: function() {
+    beforeDestroy: function() {
         if(this.ownerCt) {
             this.ownerCt.un("move", this.updateMapSize, this);
         }
-        GeoExt.MapPanel.superclass.onDestroy.apply(this, arguments);
+        /**
+         * If this container was passed a map instance, it is the
+         * responsibility of the creator to destroy it.
+         */
+        if(!this.initialConfig.map ||
+           !(this.initialConfig.map instanceof OpenLayers.Map)) {
+            // we created the map, we destroy it
+            if(this.map && this.map.destroy) {
+                this.map.destroy();
+            }
+        }
+        delete this.map;
+        GeoExt.MapPanel.superclass.beforeDestroy.apply(this, arguments);
     }
     
 });

Modified: core/trunk/geoext/tests/lib/GeoExt/widgets/MapPanel.html
===================================================================
--- core/trunk/geoext/tests/lib/GeoExt/widgets/MapPanel.html	2009-05-23 06:17:05 UTC (rev 861)
+++ core/trunk/geoext/tests/lib/GeoExt/widgets/MapPanel.html	2009-05-23 06:21:00 UTC (rev 862)
@@ -175,6 +175,43 @@
             panel.destroy();
 
         }
+        
+        function test_destroy(t) {
+            
+            /**
+             * If the panel is passed an instance of OpenLayers.Map, we don't
+             * touch it in the destroy sequence, we only remove our reference
+             * to it.  If the panel is passed a map config object, the panel
+             * creates the OpenLayers.Map instance, and the panel destroys the
+             * map in its destroy sequence.
+             */
+            
+            t.plan(3);
+            
+            var panel = new GeoExt.MapPanel({
+                renderTo: "mappanel",
+                layers: [
+                    new OpenLayers.Layer("test")
+                ],
+                zoom: 1
+            });
+            
+            t.ok(panel.map instanceof OpenLayers.Map, "panel creates a map");
+            
+            var called = false;
+            panel.map.destroy = function() {
+                called = true;
+                OpenLayers.Map.prototype.destroy.apply(panel.map, arguments);
+            }
+            try {
+                panel.destroy();
+                t.ok(called, "panel.destroy calls map.destroy");
+            } catch(err) {
+                t.fail("panel.destroy causes problems: " + err);
+            }
+            t.ok(!panel.map, "panel has no reference to a map");
+            
+        }
 
 
     </script>



More information about the Commits mailing list