From 0e81d2916831f394cfe03cad7a17f7dc19585b2d Mon Sep 17 00:00:00 2001 From: mourner Date: Fri, 2 Dec 2011 16:27:26 +0200 Subject: [PATCH] Fixed fast mouse wheel zoom when approaching min/max zoom --- CHANGELOG.md | 3 ++- src/handler/ScrollWheelZoom.js | 14 ++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e42ee37..96b86c4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,8 +44,9 @@ Leaflet Changelog #### General bugfixes * Fixed a bug where `Circle` was rendered with incorrect radius (didn't take projection exagerration into account). [#331](https://github.com/CloudMade/Leaflet/issues/331) + * Fixed a bug where fast mouse wheel zoom worked incorrectly when approaching min/max zoom values. * Fixed a bug where map panning would stuck forever after releasing the mouse over an iframe or a flash object (thanks to [@sten82](https://github.com/sten82)). [#297](https://github.com/CloudMade/Leaflet/pull/297) [#64](https://github.com/CloudMade/Leaflet/issues/64) - * Fixed a bug where mouse zoom worked incorrectly if map is inside scrolled container (partially by [@chrillo](https://github.com/chrillo)). [#206](https://github.com/CloudMade/Leaflet/issues/206) + * Fixed a bug where mouse wheel zoom worked incorrectly if map is inside scrolled container (partially by [@chrillo](https://github.com/chrillo)). [#206](https://github.com/CloudMade/Leaflet/issues/206) * Fixed a bug where it was possible to add the same listener twice. [#281](https://github.com/CloudMade/Leaflet/issues/281) * Fixed a bug where `Circle` was rendered with incorrect radius (didn't take projection exaggeration into account). [#331](https://github.com/CloudMade/Leaflet/issues/331) * Fixed a bug where `Marker` `setIcon` was not working properly (by [@marphi](https://github.com/marphi)). [#218](https://github.com/CloudMade/Leaflet/pull/218) [#311](https://github.com/CloudMade/Leaflet/issues/311) diff --git a/src/handler/ScrollWheelZoom.js b/src/handler/ScrollWheelZoom.js index 51137c39..ee544383 100644 --- a/src/handler/ScrollWheelZoom.js +++ b/src/handler/ScrollWheelZoom.js @@ -28,18 +28,20 @@ L.Handler.ScrollWheelZoom = L.Handler.extend({ }, _performZoom: function() { - var delta = Math.round(this._delta); + var delta = Math.round(this._delta), + zoom = this._map.getZoom(); + delta = Math.max(Math.min(delta, 4), -4); + delta = this._map._limitZoom(zoom + delta) - zoom; + this._delta = 0; if (!delta) { return; } - var center = this._getCenterForScrollWheelZoom(this._lastMousePos, delta), - zoom = this._map.getZoom() + delta; + var newCenter = this._getCenterForScrollWheelZoom(this._lastMousePos, delta), + newZoom = zoom + delta; - if (this._map._limitZoom(zoom) == this._map._zoom) { return; } - - this._map.setView(center, zoom); + this._map.setView(newCenter, newZoom); }, _getCenterForScrollWheelZoom: function(mousePos, delta) {