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)


git-svn-id: http://svn.openlayers.org/trunk/openlayers@5371 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2007-12-11 07:27:45 +00:00
parent b105017586
commit 354817649d
2 changed files with 21 additions and 0 deletions

View File

@@ -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;
}

View File

@@ -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>