From 45db59650a9c3db3648d8c1ff95289815e786b15 Mon Sep 17 00:00:00 2001 From: Hannes Janetzek Date: Sat, 22 Mar 2014 08:19:59 +0100 Subject: [PATCH] fix: MapEventLayer velocity when timediff = 0 --- vtm/src/org/oscim/layers/MapEventLayer.java | 3 +++ vtm/src/org/oscim/map/Animator.java | 11 ++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/vtm/src/org/oscim/layers/MapEventLayer.java b/vtm/src/org/oscim/layers/MapEventLayer.java index b9d069bc..90f56cbe 100644 --- a/vtm/src/org/oscim/layers/MapEventLayer.java +++ b/vtm/src/org/oscim/layers/MapEventLayer.java @@ -423,6 +423,9 @@ public class MapEventLayer extends Layer implements InputListener, GestureListen } public void update(float x, float y, long time) { + if (time == mLastTime) + return; + if (--mIndex < 0) mIndex = SAMPLES - 1; diff --git a/vtm/src/org/oscim/map/Animator.java b/vtm/src/org/oscim/map/Animator.java index 541d6f85..6dd9d94d 100644 --- a/vtm/src/org/oscim/map/Animator.java +++ b/vtm/src/org/oscim/map/Animator.java @@ -20,6 +20,7 @@ import static org.oscim.core.MercatorProjection.latitudeToY; import static org.oscim.core.MercatorProjection.longitudeToX; import static org.oscim.utils.FastMath.clamp; +import org.oscim.backend.CanvasAdapter; import org.oscim.core.BoundingBox; import org.oscim.core.GeoPoint; import org.oscim.core.MapPosition; @@ -162,11 +163,15 @@ public class Animator { float duration = 500; - float flingFactor = 0.5f; + float flingFactor = 240 / CanvasAdapter.dpi; mVelocity.x = velocityX * flingFactor; mVelocity.y = velocityY * flingFactor; - clamp(mVelocity.x, minX, maxX); - clamp(mVelocity.y, minY, maxY); + mVelocity.x = clamp(mVelocity.x, minX, maxX); + mVelocity.y = clamp(mVelocity.y, minY, maxY); + if (Double.isNaN(mVelocity.x) || Double.isNaN(mVelocity.y)) { + log.debug("fling NaN!"); + return; + } animStart(duration, ANIM_FLING); }