From: Tom Hughes Date: Thu, 22 Nov 2012 12:27:12 +0000 (+0000) Subject: Update the Layers control when layers are added or removed X-Git-Tag: live~5195^2~4 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/048f831119fa76db814cd294aff230a533584fd9?ds=sidebyside Update the Layers control when layers are added or removed Submitted upstream as https://github.com/CloudMade/Leaflet/pull/1169. --- diff --git a/vendor/assets/leaflet/leaflet.js b/vendor/assets/leaflet/leaflet.js index 92112044e..5503592a0 100644 --- a/vendor/assets/leaflet/leaflet.js +++ b/vendor/assets/leaflet/leaflet.js @@ -7295,6 +7295,7 @@ L.Control.Layers = L.Control.extend({ this._layers = {}; this._lastZIndex = 0; + this._handlingClick = false; for (var i in baseLayers) { if (baseLayers.hasOwnProperty(i)) { @@ -7313,9 +7314,19 @@ L.Control.Layers = L.Control.extend({ this._initLayout(); this._update(); + map + .on('layeradd', this._update, this) + .on('layerremove', this._update, this); + return this._container; }, + onRemove: function (map) { + map + .off('layeradd', this._update) + .off('layerremove', this._update); + }, + addBaseLayer: function (layer, name) { this._addLayer(layer, name); this._update(); @@ -7395,7 +7406,7 @@ L.Control.Layers = L.Control.extend({ }, _update: function () { - if (!this._container) { + if (!this._container || this._handlingClick) { return; } @@ -7466,6 +7477,8 @@ L.Control.Layers = L.Control.extend({ inputsLen = inputs.length, baseLayer; + this._handlingClick = true; + for (i = 0; i < inputsLen; i++) { input = inputs[i]; obj = this._layers[input.layerId]; @@ -7483,6 +7496,8 @@ L.Control.Layers = L.Control.extend({ if (baseLayer) { this._map.fire('baselayerchange', {layer: baseLayer}); } + + this._handlingClick = false; }, _expand: function () { @@ -7990,4 +8005,4 @@ L.Map.include({ -}(this)); \ No newline at end of file +}(this));