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

commits at openlayers.org commits at openlayers.org
Tue Dec 11 02:27:45 EST 2007


Author: crschmidt
Date: 2007-12-11 02:27:45 -0500 (Tue, 11 Dec 2007)
New Revision: 5371

Modified:
   trunk/openlayers/lib/OpenLayers/Control/MousePosition.js
   trunk/openlayers/tests/Control/test_MousePosition.html
Log:
MousePosition control throws error when no layers are on map. Fix it so that
they don't. Thanks for the review, fredj. Includes tests. (Closes #1029)


Modified: trunk/openlayers/lib/OpenLayers/Control/MousePosition.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Control/MousePosition.js	2007-12-10 23:06:27 UTC (rev 5370)
+++ trunk/openlayers/lib/OpenLayers/Control/MousePosition.js	2007-12-11 07:27:45 UTC (rev 5371)
@@ -108,6 +108,10 @@
             }
 
             lonLat = this.map.getLonLatFromPixel(evt.xy);
+            if (!lonLat) { 
+                // map has not yet been properly initialized
+                return;
+            }    
             this.lastXy = evt.xy;
         }
         

Modified: trunk/openlayers/tests/Control/test_MousePosition.html
===================================================================
--- trunk/openlayers/tests/Control/test_MousePosition.html	2007-12-10 23:06:27 UTC (rev 5370)
+++ trunk/openlayers/tests/Control/test_MousePosition.html	2007-12-11 07:27:45 UTC (rev 5371)
@@ -37,6 +37,23 @@
         t.eq(parseInt(map.viewPortDiv.lastChild.style.zIndex), map.Z_INDEX_BASE['Control'] + 5, "Viewport div contains control div");
     }
 
+    function test_02_Control_MousePosition_redraw_noLayer_displayProjection(t) {
+        t.plan(3);
+        control = new OpenLayers.Control.MousePosition();
+        map = new OpenLayers.Map('map');
+        map.addControl(control);
+        t.eq(control.div.innerHTML, "0.00000, 0.00000", "innerHTML set correctly");
+        control.redraw({'xy': new OpenLayers.Pixel(10,10)});
+        control.redraw({'xy': new OpenLayers.Pixel(12,12)});
+        t.eq(control.div.innerHTML, "0.00000, 0.00000", "innerHTML set correctly");
+        l = new OpenLayers.Layer('name', {'isBaseLayer': true});
+        map.addLayer(l);
+        map.zoomToMaxExtent();
+        control.redraw({'xy': new OpenLayers.Pixel(10,10)});
+        control.redraw({'xy': new OpenLayers.Pixel(12,12)});
+        t.eq(control.div.innerHTML, "-175.78125, 85.78125", "innerHTML set correctly when triggered.");
+    }
+
   </script>
 </head>
 <body>



More information about the Commits mailing list