XAML-Map-Control/MapControl/LocationAnimation.cs
2012-05-04 12:52:20 +02:00

51 lines
1.4 KiB
C#

using System;
using System.Windows;
using System.Windows.Media.Animation;
namespace MapControl
{
/// <summary>
/// Animates the value of a Location property between two values.
/// </summary>
public class LocationAnimation : AnimationTimeline
{
public Location From { get; set; }
public Location To { get; set; }
public IEasingFunction EasingFunction { get; set; }
public override Type TargetPropertyType
{
get { return typeof(Location); }
}
protected override Freezable CreateInstanceCore()
{
return new LocationAnimation
{
From = From,
To = To,
EasingFunction = EasingFunction
};
}
public override object GetCurrentValue(object defaultOriginValue, object defaultDestinationValue, AnimationClock animationClock)
{
if (!animationClock.CurrentProgress.HasValue)
{
return defaultOriginValue;
}
double progress = animationClock.CurrentProgress.Value;
if (EasingFunction != null)
{
progress = EasingFunction.Ease(progress);
}
return new Location(
(1d - progress) * From.Latitude + progress * To.Latitude,
(1d - progress) * From.Longitude + progress * To.Longitude);
}
}
}