Created
March 24, 2013 07:12
-
-
Save dotMorten/5230877 to your computer and use it in GitHub Desktop.
Code for animating a MapPoint to a new location
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using ESRI.ArcGIS.Runtime; | |
using System; | |
using Windows.UI.Xaml.Media; | |
namespace GeometryUtils | |
{ | |
public class PointAnimator | |
{ | |
public PointAnimator(MapPoint point, MapPoint to, TimeSpan duration) | |
{ | |
EventHandler<object> handler = null; | |
TimeSpan? start = null; | |
double startX = point.X; | |
double startY = point.Y; | |
var easing = new Windows.UI.Xaml.Media.Animation.CubicEase(); | |
handler = (s, e) => | |
{ | |
var args = (RenderingEventArgs)e; | |
if (!start.HasValue) | |
{ | |
start = args.RenderingTime; | |
} | |
else | |
{ | |
TimeSpan timeElapsed = args.RenderingTime - start.Value; | |
if (timeElapsed < duration) | |
{ | |
var frac = easing.Ease(timeElapsed.TotalMilliseconds / duration.TotalMilliseconds); | |
double x = (to.X - startX) * frac + startX; | |
double y = (to.Y - startY) * frac + startY; | |
point.SetXY(x, y); | |
} | |
else //reached end | |
{ | |
point.SetXY(to.X, to.Y); | |
CompositionTarget.Rendering -= handler; | |
} | |
} | |
}; | |
CompositionTarget.Rendering += handler; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment