Skip to content

Instantly share code, notes, and snippets.

@dotMorten
Created March 24, 2013 07:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dotMorten/5230877 to your computer and use it in GitHub Desktop.
Save dotMorten/5230877 to your computer and use it in GitHub Desktop.
Code for animating a MapPoint to a new location
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