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

commits at geoext.org commits at geoext.org
Thu Sep 22 18:00:05 CEST 2011


Author: bbinet
Date: 2011-09-22 18:00:05 +0200 (Thu, 22 Sep 2011)
New Revision: 2841

Modified:
   core/trunk/geoext/lib/GeoExt/widgets/Popup.js
   core/trunk/geoext/tests/lib/GeoExt/widgets/Popup.html
Log:
fix popups reappearance when panning after being hidden. p=amercade r=bbinet,ahocevar (closes #408)

Modified: core/trunk/geoext/lib/GeoExt/widgets/Popup.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/widgets/Popup.js	2011-09-15 04:21:25 UTC (rev 2840)
+++ core/trunk/geoext/lib/GeoExt/widgets/Popup.js	2011-09-22 16:00:05 UTC (rev 2841)
@@ -79,6 +79,11 @@
      */
     location: null,
 
+    /** private: property[insideViewport]
+     *  ``Boolean`` Wether the popup is currently inside the map viewport.
+     */
+    insideViewport: null,
+
     /**
      * Some Ext.Window defaults need to be overriden here
      * because some Ext.Window behavior is not currently supported.
@@ -139,6 +144,10 @@
             this.location = this.map.getLonLatFromViewPortPx(this.location);
         }
 
+        if (this.location) {
+            this.insideViewport = this.map.getExtent().containsLonLat(this.location);
+        }
+
         if(this.anchored) {
             this.addAnchorEvents();
         }
@@ -223,9 +232,10 @@
      */
     position: function() {
         if(this._mapMove === true) {
-            var visible = this.map.getExtent().containsLonLat(this.location);
-            if(visible !== this.isVisible()) {
-                this.setVisible(visible);
+            this.insideViewport = this.map.getExtent().containsLonLat(this.location);
+            if(this.insideViewport !== this.isVisible()) {
+                this.setVisible(this.insideViewport);
+
             }
         }
 
@@ -310,9 +320,11 @@
     /** private: method[onMapMove]
      */
     onMapMove: function() {
-        this._mapMove = true;
-        this.position();
-        delete this._mapMove;
+        if (!(this.hidden && this.insideViewport)){       
+            this._mapMove = true;
+            this.position();
+            delete this._mapMove;
+        }
     },
     
     /** private: method[addAnchorEvents]

Modified: core/trunk/geoext/tests/lib/GeoExt/widgets/Popup.html
===================================================================
--- core/trunk/geoext/tests/lib/GeoExt/widgets/Popup.html	2011-09-15 04:21:25 UTC (rev 2840)
+++ core/trunk/geoext/tests/lib/GeoExt/widgets/Popup.html	2011-09-22 16:00:05 UTC (rev 2841)
@@ -50,14 +50,15 @@
             context.mapPanel.destroy();
         }
 
-        function popup(feature, map) {
+        function popup(feature, map, hide) {
             return new GeoExt.Popup({
                 title: 'My Popup',
                 location: feature,
                 map: map,
                 width: 200,
                 html: "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.",
-                collapsible: true
+                collapsible: true,
+                closeAction: (hide) ? "hide" : "close"     // Default action is "close"
             });
         }
 
@@ -122,7 +123,6 @@
             tearDown(context);
         }
 
-
         function test_unanchorPopup(t) {
             t.plan(4);
 
@@ -235,6 +235,46 @@
             tearDown(context);
         }
 
+        function test_hidePopup(t){
+            t.plan(5);
+
+            var context = setupContext();
+            
+            // Reusable popup (closeAction = hide)
+            var pop = popup(context.feature,null,true);
+            
+            pop.show();
+
+            // Center map to popup's location
+            context.map.setCenter(new OpenLayers.LonLat(5, 45));           
+            t.ok(pop.insideViewport && !pop.hidden, "Reusable popup is visible when open and inside the viewport");
+
+            // Pan map outside popup's location
+            context.map.panTo(new OpenLayers.LonLat(170, 80));
+            t.ok(!pop.insideViewport && pop.hidden, "Reusable popup is hidden when open and outside the viewport");
+
+            // Recenter map to popup's location, hide popup and pan map
+            context.map.panTo(new OpenLayers.LonLat(5, 45));
+            pop.hide();
+            context.map.panTo(new OpenLayers.LonLat(6, 45));
+            t.ok(pop.insideViewport && pop.hidden, "Reusable popup is hidden when closed and inside the viewport");          
+
+
+            // Regular popup (destroyed when closed)
+            var pop2 = popup(context.feature);
+            pop2.show();
+
+            // Center map to popup's location
+            context.map.setCenter(new OpenLayers.LonLat(5, 45));           
+            t.ok(pop2.insideViewport && !pop2.hidden, "Regular popup is visible when open and inside the viewport");
+
+            // Pan map outside popup's location
+            context.map.panTo(new OpenLayers.LonLat(170, 80));
+            t.ok(!pop2.insideViewport && pop2.hidden, "Regular popup is hidden when open and outside the viewport");
+
+            tearDown(context);
+        }
+
     </script>
   <body>
     <div id="mappanel"></div>



More information about the Commits mailing list