mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
53 lines
1.5 KiB
C#
53 lines
1.5 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);
|
|
}
|
|
|
|
double deltaLongitude = progress * Location.NormalizeLongitude(To.Longitude - From.Longitude);
|
|
|
|
return new Location(
|
|
(1d - progress) * From.Latitude + progress * To.Latitude,
|
|
Location.NormalizeLongitude(From.Longitude + deltaLongitude));
|
|
}
|
|
}
|
|
}
|