CloudMade/Leaflet — pull request #1159 by moonlite (2012-11-18 21:46:08+00:00)
Title: First stab at a fix for Issue 623

Fix for https://github.com/CloudMade/Leaflet/pull/623 .

Unfortunately it seems like I've managed to introduce or trigger a bug in Leaflet. Sometimes when TileLayer.onRemove is called a DOM Exception is thrown on line 84 in TileLayer.js:
```javascript
map._panes.tilePane.removeChild(this._container);
```
This happens because this._container sometimes is undefined.

To reproduce do the following:
1. open debug/map/zoomlevels.html
2. Change to "Cloudmade Pale Dawn (5-18)"
3. Zoom in to a zoomlevel over 10
4. Change back to "Cloudmade Fresh (0-10)"

Notice how the tilelayer isn't changed to "Cloudmade Fresh (0-10)" but the zoomlevel is correctly set to 10. This doesn't occur on the smaller zoomlevels (chose zoomlevel 1 and switch back to "Pale Dawn") and also not if the order of the tilelayers are switched in the layer control.

if i change omRemove to the following it seems to work:
```javascript
try{
map._panes.tilePane.removeChild(this._container);
} catch (x) {}
```
...but I'm not sure if that's actually a nice approach?