mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
51 lines
1.4 KiB
C#
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);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|