From 8870c2abf8b6cc16739cccdea8e94c98d65d8358 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Fri, 17 Jul 2015 11:09:15 +0200 Subject: [PATCH] Fix boxZoom._moved remaining in bad state after use (cf #3026) --- debug/map/map.html | 2 +- src/map/handler/Map.BoxZoom.js | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/debug/map/map.html b/debug/map/map.html index 6b7c57ea..fd6c5aea 100644 --- a/debug/map/map.html +++ b/debug/map/map.html @@ -43,7 +43,7 @@ function logEvent(e) { console.log(e.type); } - // map.on('click', logEvent); + map.on('click', logEvent); // map.on('movestart', logEvent); // map.on('move', logEvent); diff --git a/src/map/handler/Map.BoxZoom.js b/src/map/handler/Map.BoxZoom.js index dff50690..a0d5f06f 100644 --- a/src/map/handler/Map.BoxZoom.js +++ b/src/map/handler/Map.BoxZoom.js @@ -26,10 +26,14 @@ L.Map.BoxZoom = L.Handler.extend({ return this._moved; }, + _resetState: function () { + this._moved = false; + }, + _onMouseDown: function (e) { if (!e.shiftKey || ((e.which !== 1) && (e.button !== 1))) { return false; } - this._moved = false; + this._resetState(); L.DomUtil.disableTextSelection(); L.DomUtil.disableImageDrag(); @@ -88,6 +92,9 @@ L.Map.BoxZoom = L.Handler.extend({ this._finish(); if (!this._moved) { return; } + // Postpone to next JS tick so internal click event handling + // still see it as "moved". + setTimeout(L.bind(this._resetState, this), 0); var bounds = new L.LatLngBounds( this._map.containerPointToLatLng(this._startPoint),