From b6c87c3fa8b328b0d4464fa413d6a66f1182d152 Mon Sep 17 00:00:00 2001 From: perliedman Date: Mon, 14 Dec 2015 13:40:44 +0100 Subject: [PATCH 1/2] Make sure to always reset _enforcingBounds. Even in case of early exit or exception. Fixes #3938. --- src/map/Map.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/map/Map.js b/src/map/Map.js index 04eb1071..cac888c0 100644 --- a/src/map/Map.js +++ b/src/map/Map.js @@ -177,14 +177,17 @@ L.Map = L.Evented.extend({ panInsideBounds: function (bounds, options) { this._enforcingBounds = true; - var center = this.getCenter(), - newCenter = this._limitCenter(center, this._zoom, L.latLngBounds(bounds)); + try { + var center = this.getCenter(), + newCenter = this._limitCenter(center, this._zoom, L.latLngBounds(bounds)); - if (center.equals(newCenter)) { return this; } + if (center.equals(newCenter)) { return this; } - this.panTo(newCenter, options); - this._enforcingBounds = false; - return this; + this.panTo(newCenter, options); + return this; + } finally { + this._enforcingBounds = false; + } }, invalidateSize: function (options) { From 2b64978c9ee97b210ef4c7c9d5d47d0ca7eb117f Mon Sep 17 00:00:00 2001 From: Per Liedman Date: Mon, 28 Dec 2015 15:00:20 +0100 Subject: [PATCH 2/2] Don't use try-finally --- src/map/Map.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/map/Map.js b/src/map/Map.js index cac888c0..3ccbb9b5 100644 --- a/src/map/Map.js +++ b/src/map/Map.js @@ -177,17 +177,15 @@ L.Map = L.Evented.extend({ panInsideBounds: function (bounds, options) { this._enforcingBounds = true; - try { - var center = this.getCenter(), - newCenter = this._limitCenter(center, this._zoom, L.latLngBounds(bounds)); - - if (center.equals(newCenter)) { return this; } + var center = this.getCenter(), + newCenter = this._limitCenter(center, this._zoom, L.latLngBounds(bounds)); + if (!center.equals(newCenter)) { this.panTo(newCenter, options); - return this; - } finally { - this._enforcingBounds = false; } + + this._enforcingBounds = false; + return this; }, invalidateSize: function (options) {