From 048f831119fa76db814cd294aff230a533584fd9 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Thu, 22 Nov 2012 12:27:12 +0000 Subject: [PATCH] Update the Layers control when layers are added or removed Submitted upstream as https://github.com/CloudMade/Leaflet/pull/1169. --- vendor/assets/leaflet/leaflet.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) 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)); -- 2.43.2