From 02a2c5acebab3134f858186027a2a9168cb3131a Mon Sep 17 00:00:00 2001 From: tsauerwein Date: Fri, 18 Jul 2014 15:54:38 +0200 Subject: [PATCH 1/2] Start earlier to log points for kinetic --- src/ol/interaction/dragpaninteraction.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ol/interaction/dragpaninteraction.js b/src/ol/interaction/dragpaninteraction.js index 589e539aeb..a1c8efbe58 100644 --- a/src/ol/interaction/dragpaninteraction.js +++ b/src/ol/interaction/dragpaninteraction.js @@ -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; From 73951394f9356ef59a1e9d5a25d956d635c0467a Mon Sep 17 00:00:00 2001 From: tsauerwein Date: Fri, 18 Jul 2014 16:07:59 +0200 Subject: [PATCH 2/2] Ensure that the first point for kinetic is valid --- src/ol/kinetic.js | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/ol/kinetic.js b/src/ol/kinetic.js index 0960f81ca4..a6d9b54d67 100644 --- a/src/ol/kinetic.js +++ b/src/ol/kinetic.js @@ -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_; };