Skip to content

Commit

Permalink
improve panning inertia, fix animation easings on IE
Browse files Browse the repository at this point in the history
  • Loading branch information
mourner committed Jul 12, 2012
1 parent f4ecfe6 commit bd1510c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 57 deletions.
36 changes: 8 additions & 28 deletions dist/leaflet-src.js
Original file line number Diff line number Diff line change
Expand Up @@ -3012,6 +3012,7 @@ L.Popup = L.Class.extend({
if (this.options.closeButton) {
closeButton = this._closeButton = L.DomUtil.create('a', prefix + '-close-button', container);
closeButton.href = '#close';
closeButton.innerHTML = '×';

L.DomEvent.on(closeButton, 'click', this._onCloseButtonClick, this);
}
Expand Down Expand Up @@ -5263,9 +5264,9 @@ L.Map.mergeOptions({
dragging: true,

inertia: !L.Browser.android23,
inertiaDeceleration: L.Browser.touch ? 3000 : 2000, // px/s^2
inertiaMaxSpeed: L.Browser.touch ? 1500 : 1000, // px/s
inertiaThreshold: L.Browser.touch ? 32 : 16, // ms
inertiaDeceleration: 3000, // px/s^2
inertiaMaxSpeed: 1500, // px/s
inertiaThreshold: L.Browser.touch ? 32 : 14, // ms

// TODO refactor, move to CRS
worldCopyJump: true,
Expand Down Expand Up @@ -6712,11 +6713,8 @@ L.Transition = L.Transition.NATIVE ? L.Transition : L.Transition.extend({
TIMER: true,

EASINGS: {
'ease': [0.25, 0.1, 0.25, 1.0],
'linear': [0.0, 0.0, 1.0, 1.0],
'ease-in': [0.42, 0, 1.0, 1.0],
'ease-out': [0, 0, 0.58, 1.0],
'ease-in-out': [0.42, 0, 0.58, 1.0]
'linear': function (t) { return t; },
'ease-out': function (t) { return t * (2 - t); }
},

CUSTOM_PROPS_GETTERS: {
Expand All @@ -6735,12 +6733,7 @@ L.Transition = L.Transition.NATIVE ? L.Transition : L.Transition.extend({
this._el = el;
L.Util.extend(this.options, options);

var easings = L.Transition.EASINGS[this.options.easing] || L.Transition.EASINGS.ease;

this._p1 = new L.Point(0, 0);
this._p2 = new L.Point(easings[0], easings[1]);
this._p3 = new L.Point(easings[2], easings[3]);
this._p4 = new L.Point(1, 1);
this._easing = L.Transition.EASINGS[this.options.easing] || L.Transition.EASINGS['ease-out'];

this._step = L.Util.bind(this._step, this);
this._interval = Math.round(1000 / this.options.fps);
Expand Down Expand Up @@ -6780,7 +6773,7 @@ L.Transition = L.Transition.NATIVE ? L.Transition : L.Transition.extend({
duration = this.options.duration * 1000;

if (elapsed < duration) {
this._runFrame(this._cubicBezier(elapsed / duration));
this._runFrame(this._easing(elapsed / duration));
} else {
this._runFrame(1);
this._complete();
Expand Down Expand Up @@ -6809,19 +6802,6 @@ L.Transition = L.Transition.NATIVE ? L.Transition : L.Transition.extend({
_complete: function () {
clearInterval(this._timer);
this.fire('end');
},

_cubicBezier: function (t) {
var a = Math.pow(1 - t, 3),
b = 3 * Math.pow(1 - t, 2) * t,
c = 3 * (1 - t) * Math.pow(t, 2),
d = Math.pow(t, 3),
p1 = this._p1.multiplyBy(a),
p2 = this._p2.multiplyBy(b),
p3 = this._p3.multiplyBy(c),
p4 = this._p4.multiplyBy(d);

return p1.add(p2).add(p3).add(p4).y;
}
});

Expand Down
2 changes: 1 addition & 1 deletion dist/leaflet.js

Large diffs are not rendered by default.

29 changes: 4 additions & 25 deletions src/dom/transition/Transition.Timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ L.Transition = L.Transition.NATIVE ? L.Transition : L.Transition.extend({
TIMER: true,

EASINGS: {
'ease': [0.25, 0.1, 0.25, 1.0],
'linear': [0.0, 0.0, 1.0, 1.0],
'ease-in': [0.42, 0, 1.0, 1.0],
'ease-out': [0, 0, 0.58, 1.0],
'ease-in-out': [0.42, 0, 0.58, 1.0]
'linear': function (t) { return t; },
'ease-out': function (t) { return t * (2 - t); }
},

CUSTOM_PROPS_GETTERS: {
Expand All @@ -35,12 +32,7 @@ L.Transition = L.Transition.NATIVE ? L.Transition : L.Transition.extend({
this._el = el;
L.Util.extend(this.options, options);

var easings = L.Transition.EASINGS[this.options.easing] || L.Transition.EASINGS.ease;

this._p1 = new L.Point(0, 0);
this._p2 = new L.Point(easings[0], easings[1]);
this._p3 = new L.Point(easings[2], easings[3]);
this._p4 = new L.Point(1, 1);
this._easing = L.Transition.EASINGS[this.options.easing] || L.Transition.EASINGS['ease-out'];

this._step = L.Util.bind(this._step, this);
this._interval = Math.round(1000 / this.options.fps);
Expand Down Expand Up @@ -80,7 +72,7 @@ L.Transition = L.Transition.NATIVE ? L.Transition : L.Transition.extend({
duration = this.options.duration * 1000;

if (elapsed < duration) {
this._runFrame(this._cubicBezier(elapsed / duration));
this._runFrame(this._easing(elapsed / duration));
} else {
this._runFrame(1);
this._complete();
Expand Down Expand Up @@ -109,18 +101,5 @@ L.Transition = L.Transition.NATIVE ? L.Transition : L.Transition.extend({
_complete: function () {
clearInterval(this._timer);
this.fire('end');
},

_cubicBezier: function (t) {
var a = Math.pow(1 - t, 3),
b = 3 * Math.pow(1 - t, 2) * t,
c = 3 * (1 - t) * Math.pow(t, 2),
d = Math.pow(t, 3),
p1 = this._p1.multiplyBy(a),
p2 = this._p2.multiplyBy(b),
p3 = this._p3.multiplyBy(c),
p4 = this._p4.multiplyBy(d);

return p1.add(p2).add(p3).add(p4).y;
}
});
6 changes: 3 additions & 3 deletions src/map/handler/Map.Drag.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ L.Map.mergeOptions({
dragging: true,

inertia: !L.Browser.android23,
inertiaDeceleration: L.Browser.touch ? 3000 : 2000, // px/s^2
inertiaMaxSpeed: L.Browser.touch ? 1500 : 1000, // px/s
inertiaThreshold: L.Browser.touch ? 32 : 16, // ms
inertiaDeceleration: 3000, // px/s^2
inertiaMaxSpeed: 1500, // px/s
inertiaThreshold: L.Browser.touch ? 32 : 14, // ms

// TODO refactor, move to CRS
worldCopyJump: true,
Expand Down

0 comments on commit bd1510c

Please sign in to comment.