If layer0 has 5 resolutions and layer1 has 4 resolutions and the map is zoomed to level 4, removing layer0 causes problems. getExtent returns null and getResolution returns null. Any operations that check for properties of the extent trigger an exception.
This example demonstrates:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
#map {
width: 512px;
height: 256px;
border: 1px solid gray;
}
</style>
<script src="../lib/OpenLayers.js"></script>
<script type="text/javascript">
var map, layer0, layer1;
function init(){
map = new OpenLayers.Map('map');
layer0 = new OpenLayers.Layer.WMS(
"Layer 0",
"http://labs.metacarta.com/wms/vmap0",
{layers: 'basic'},
{numZoomLevels: 5}
);
var options = {numZoomLevels: 4};
var layer1 = new OpenLayers.Layer.Image(
'City Lights',
'http://earthtrends.wri.org/images/maps/4_m_citylights_lg.gif',
new OpenLayers.Bounds(-180, -88.759, 180, 88.759),
new OpenLayers.Size(580, 288),
options
);
map.addLayers([layer0, layer1]);
map.zoomToMaxExtent();
map.zoomTo(4);
}
</script>
</head>
<body onload="init()">
<div id="map"></div>
<a href="javascript: void map.removeLayer(layer0)">click to break</a>
</body>
</html>