Merge pull request #2405 from tsauerwein/kinetic-fast
Improve kinetic effect when panning fast
This commit is contained in:
@@ -67,10 +67,10 @@ ol.interaction.DragPan.prototype.handlePointerDrag = function(mapBrowserEvent) {
|
||||
goog.asserts.assert(this.targetPointers.length >= 1);
|
||||
var centroid =
|
||||
ol.interaction.Pointer.centroid(this.targetPointers);
|
||||
if (this.kinetic_) {
|
||||
this.kinetic_.update(centroid[0], centroid[1]);
|
||||
}
|
||||
if (!goog.isNull(this.lastCentroid)) {
|
||||
if (this.kinetic_) {
|
||||
this.kinetic_.update(centroid[0], centroid[1]);
|
||||
}
|
||||
var deltaX = this.lastCentroid[0] - centroid[0];
|
||||
var deltaY = centroid[1] - this.lastCentroid[1];
|
||||
var map = mapBrowserEvent.map;
|
||||
|
||||
@@ -81,25 +81,30 @@ ol.Kinetic.prototype.update = function(x, y) {
|
||||
* @return {boolean} Whether we should do kinetic animation.
|
||||
*/
|
||||
ol.Kinetic.prototype.end = function() {
|
||||
if (this.points_.length < 6) {
|
||||
// at least 2 points are required (i.e. there must be at least 6 elements
|
||||
// in the array)
|
||||
return false;
|
||||
}
|
||||
var delay = goog.now() - this.delay_;
|
||||
var lastIndex = this.points_.length - 3;
|
||||
if (this.points_[lastIndex + 2] < delay) {
|
||||
// the user stopped panning before releasing the map
|
||||
// the last tracked point is too old, which means that the user stopped
|
||||
// panning before releasing the map
|
||||
return false;
|
||||
}
|
||||
|
||||
// get the first point which still falls into the delay time
|
||||
var firstIndex = lastIndex - 3;
|
||||
while (firstIndex >= 0 && this.points_[firstIndex + 2] > delay) {
|
||||
while (firstIndex > 0 && this.points_[firstIndex + 2] > delay) {
|
||||
firstIndex -= 3;
|
||||
}
|
||||
if (firstIndex >= 0) {
|
||||
var duration = this.points_[lastIndex + 2] - this.points_[firstIndex + 2];
|
||||
var dx = this.points_[lastIndex] - this.points_[firstIndex];
|
||||
var dy = this.points_[lastIndex + 1] - this.points_[firstIndex + 1];
|
||||
this.angle_ = Math.atan2(dy, dx);
|
||||
this.initialVelocity_ = Math.sqrt(dx * dx + dy * dy) / duration;
|
||||
return this.initialVelocity_ > this.minVelocity_;
|
||||
}
|
||||
return false;
|
||||
var duration = this.points_[lastIndex + 2] - this.points_[firstIndex + 2];
|
||||
var dx = this.points_[lastIndex] - this.points_[firstIndex];
|
||||
var dy = this.points_[lastIndex + 1] - this.points_[firstIndex + 1];
|
||||
this.angle_ = Math.atan2(dy, dx);
|
||||
this.initialVelocity_ = Math.sqrt(dx * dx + dy * dy) / duration;
|
||||
return this.initialVelocity_ > this.minVelocity_;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user