XAML-Map-Control/MapControl/WPF/LocationAnimation.WPF.cs

39 lines
1 KiB
C#
Raw Normal View History

2025-02-27 18:46:32 +01:00
using System;
2024-05-21 13:51:10 +02:00
using System.Windows;
using System.Windows.Media.Animation;
2026-04-13 17:14:49 +02:00
namespace MapControl;
2024-05-21 13:51:10 +02:00
2026-04-13 17:14:49 +02:00
public class LocationAnimation : AnimationTimeline
{
public override Type TargetPropertyType => typeof(Location);
2024-05-21 13:51:10 +02:00
2026-04-13 17:14:49 +02:00
public Location To { get; set; }
2024-05-21 13:51:10 +02:00
2026-04-13 17:14:49 +02:00
public IEasingFunction EasingFunction { get; set; }
2024-05-21 13:51:10 +02:00
2026-04-13 17:14:49 +02:00
protected override Freezable CreateInstanceCore()
{
return new LocationAnimation
2024-05-21 13:51:10 +02:00
{
2026-04-13 17:14:49 +02:00
To = To,
EasingFunction = EasingFunction
};
}
2024-05-21 13:51:10 +02:00
2026-04-13 17:14:49 +02:00
public override object GetCurrentValue(object defaultOriginValue, object defaultDestinationValue, AnimationClock animationClock)
{
var from = (Location)defaultOriginValue;
var progress = animationClock.CurrentProgress ?? 1d;
2024-05-21 13:51:10 +02:00
2026-04-13 17:14:49 +02:00
if (EasingFunction != null)
{
progress = EasingFunction.Ease(progress);
2024-05-21 13:51:10 +02:00
}
2026-04-13 17:14:49 +02:00
return new Location(
(1d - progress) * from.Latitude + progress * To.Latitude,
(1d - progress) * from.Longitude + progress * To.Longitude);
2024-05-21 13:51:10 +02:00
}
}