[OpenLayers-Commits] r4251 - in trunk/openlayers: lib/OpenLayers tests

commits at openlayers.org commits at openlayers.org
Wed Sep 12 16:48:29 EDT 2007


Author: crschmidt
Date: 2007-09-12 16:48:28 -0400 (Wed, 12 Sep 2007)
New Revision: 4251

Modified:
   trunk/openlayers/lib/OpenLayers/Popup.js
   trunk/openlayers/tests/test_Popup.html
Log:
Prevent popups from failing when getLayerPxFromLonLat returns null (which is possible
in the case of a not-yet-setup layer, for example).


Modified: trunk/openlayers/lib/OpenLayers/Popup.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Popup.js	2007-09-12 20:14:14 UTC (rev 4250)
+++ trunk/openlayers/lib/OpenLayers/Popup.js	2007-09-12 20:48:28 UTC (rev 4251)
@@ -226,7 +226,9 @@
     updatePosition: function() {
         if ((this.lonlat) && (this.map)) {
                 var px = this.map.getLayerPxFromLonLat(this.lonlat);
-                this.moveTo(px);            
+                if (px) {
+                    this.moveTo(px);           
+                }    
         }
     },
 

Modified: trunk/openlayers/tests/test_Popup.html
===================================================================
--- trunk/openlayers/tests/test_Popup.html	2007-09-12 20:14:14 UTC (rev 4250)
+++ trunk/openlayers/tests/test_Popup.html	2007-09-12 20:48:28 UTC (rev 4251)
@@ -51,6 +51,19 @@
         t.eq(popup.contentHTML, content, "contentHTML porpoerty of set correctly");
     }
 
+    function test_Popup_updatePosition(t) {
+        t.plan(1)
+        var map = new OpenLayers.Map('map');
+        map.addLayer(new OpenLayers.Layer('name', {'isBaseLayer':true}));
+        map.zoomToMaxExtent();
+        var popup = new OpenLayers.Popup('id');
+        map.addPopup(popup);
+        map.getLayerPxFromLonLat = function () { return null; }
+        popup.moveTo=function() { t.fail("Shouldnt' call moveTo if layerpx is null"); }
+        popup.lonlat = true;
+        popup.updatePosition();
+        t.ok(true, "update position doesn't fail when getLayerPxFromLonLat fails.");
+    }
     function test_03_Popup_draw(t) {
         t.plan( 17 );
         
@@ -109,5 +122,6 @@
   </script>
 </head>
 <body>
+<div id="map" style="width:512px; height:256px"> </div>
 </body>
 </html>



More information about the Commits mailing list