improve zoom control (shift-clicking)

This commit is contained in:
mourner 2012-08-10 23:11:28 +03:00
parent 8980f2d224
commit 0bdc48a864
3 changed files with 29 additions and 10 deletions

View File

@ -7,10 +7,18 @@ Leaflet Changelog
An in-progress version being developed on the master branch.
### Improvements
* Replaced `L.Transition` with a much better and simpler `L.PosAnimation`.
* Adjusted panning inertia to be more natural.
* Improved panning animation performance in IE6-8.
* Improved zoom control to zoom by 3 levels if you hold shift while clicking on a button.
* Added optional `delta` argument to `Map` `zoomIn` and `zoomOut` (1 by default).
### Bugfixes
* Fixed a bug with pan animation where it jumped to its end position if you tried to drag the map.
* Fixed a bug with shift-clicking on a zoom button leading to unexpected result.
## 0.4.4 (August 7, 2012)

View File

@ -7,22 +7,32 @@ L.Control.Zoom = L.Control.extend({
var className = 'leaflet-control-zoom',
container = L.DomUtil.create('div', className);
this._createButton('Zoom in', className + '-in', container, map.zoomIn, map);
this._createButton('Zoom out', className + '-out', container, map.zoomOut, map);
this._map = map;
this._createButton('Zoom in', className + '-in', container, this._zoomIn, this);
this._createButton('Zoom out', className + '-out', container, this._zoomOut, this);
return container;
},
_zoomIn: function (e) {
this._map.zoomIn(e.shiftKey ? 3 : 1);
},
_zoomOut: function (e) {
this._map.zoomOut(e.shiftKey ? 3 : 1);
},
_createButton: function (title, className, container, fn, context) {
var link = L.DomUtil.create('a', className, container);
link.href = '#';
link.title = title;
L.DomEvent
.on(link, 'click', L.DomEvent.stopPropagation)
.on(link, 'click', L.DomEvent.preventDefault)
.on(link, 'click', fn, context)
.on(link, 'dblclick', L.DomEvent.stopPropagation);
.on(link, 'click', fn, context);
L.DomEvent.disableClickPropagation(link);
return link;
}
@ -42,3 +52,4 @@ L.Map.addInitHook(function () {
L.control.zoom = function (options) {
return new L.Control.Zoom(options);
};

View File

@ -52,12 +52,12 @@ L.Map = L.Class.extend({
return this.setView(this.getCenter(), zoom);
},
zoomIn: function () {
return this.setZoom(this._zoom + 1);
zoomIn: function (delta) {
return this.setZoom(this._zoom + (delta || 1));
},
zoomOut: function () {
return this.setZoom(this._zoom - 1);
zoomOut: function (delta) {
return this.setZoom(this._zoom - (delta || 1));
},
fitBounds: function (bounds) { // (LatLngBounds)