diff options
author | Christopher Baines <mail@cbaines.net> | 2014-05-22 17:45:39 +0100 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2014-05-22 17:46:04 +0100 |
commit | 5f3ab228f9b8ed637ee0a4b8488151ad9052241a (patch) | |
tree | 8ccc19de125e41f69e25fadab0aa1ea4016357fb | |
parent | 2c4e84458354ac7b30e240e87b777b02949c21f9 (diff) | |
download | leaflet-indoor-5f3ab228f9b8ed637ee0a4b8488151ad9052241a.tar leaflet-indoor-5f3ab228f9b8ed637ee0a4b8488151ad9052241a.tar.gz |
Do not attempt to add non existant levels to the map
-rw-r--r-- | leaflet-indoor.js | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/leaflet-indoor.js b/leaflet-indoor.js index 5eb4c76..be73a6e 100644 --- a/leaflet-indoor.js +++ b/leaflet-indoor.js @@ -65,7 +65,9 @@ L.Indoor = L.Class.extend({ } if (this._level !== null) { - this._map.addLayer(this._layers[this._level]); + if (this._level in this._layers) { + this._map.addLayer(this._layers[this._level]); + } } }, onRemove: function (map) { @@ -138,8 +140,13 @@ L.Indoor = L.Class.extend({ var layer = this._layers[level]; if (this._map !== null) { - this._map.removeLayer(oldLayer); - this._map.addLayer(layer); + if (this._map.hasLayer(oldLayer)) { + this._map.removeLayer(oldLayer); + } + + if (layer) { + this._map.addLayer(layer); + } } this._level = level; |