diff --git a/lib/OpenLayers/Control/MousePosition.js b/lib/OpenLayers/Control/MousePosition.js index 4e44e7afc7..861281892b 100644 --- a/lib/OpenLayers/Control/MousePosition.js +++ b/lib/OpenLayers/Control/MousePosition.js @@ -108,6 +108,10 @@ OpenLayers.Control.MousePosition = OpenLayers.Class(OpenLayers.Control, { } lonLat = this.map.getLonLatFromPixel(evt.xy); + if (!lonLat) { + // map has not yet been properly initialized + return; + } this.lastXy = evt.xy; } diff --git a/tests/Control/test_MousePosition.html b/tests/Control/test_MousePosition.html index 20b470914e..62b7d721c2 100644 --- a/tests/Control/test_MousePosition.html +++ b/tests/Control/test_MousePosition.html @@ -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."); + } +