zoom to the nearest round zoom with pinch or dblclick

This commit is contained in:
Vladimir Agafonkin 2014-01-24 16:24:27 +02:00
parent fc655e45c7
commit 5912c365b7
2 changed files with 3 additions and 2 deletions

View File

@ -17,7 +17,8 @@ L.Map.DoubleClickZoom = L.Handler.extend({
_onDoubleClick: function (e) { _onDoubleClick: function (e) {
var map = this._map, var map = this._map,
zoom = map.getZoom() + (e.originalEvent.shiftKey ? -1 : 1); oldZoom = map.getZoom(),
zoom = e.originalEvent.shiftKey ? Math.ceil(oldZoom) - 1 : Math.floor(oldZoom) + 1;
if (map.options.doubleClickZoom === 'center') { if (map.options.doubleClickZoom === 'center') {
map.setZoom(zoom); map.setZoom(zoom);

View File

@ -103,7 +103,7 @@ L.Map.TouchZoom = L.Handler.extend({
var map = this._map, var map = this._map,
oldZoom = map.getZoom(), oldZoom = map.getZoom(),
zoomDelta = this._zoom - oldZoom, zoomDelta = this._zoom - oldZoom,
finalZoom = map._limitZoom(oldZoom + (zoomDelta > 0 ? Math.ceil(zoomDelta) : Math.floor(zoomDelta))); finalZoom = map._limitZoom(zoomDelta > 0 ? Math.ceil(this._zoom) : Math.floor(this._zoom));
map._animateZoom(this._center, finalZoom, true); map._animateZoom(this._center, finalZoom, true);
}, },