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

44 lines
1.3 KiB
C#
Raw Normal View History

2024-05-21 13:51:10 +02:00
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
2025-01-01 18:57:55 +01:00
// Copyright © Clemens Fischer
2024-05-21 13:51:10 +02:00
// Licensed under the Microsoft Public License (Ms-PL)
using System;
using System.Windows;
using System.Windows.Media.Animation;
namespace MapControl
{
public class LocationAnimation : AnimationTimeline
{
public override Type TargetPropertyType => typeof(Location);
public Location To { get; set; }
public IEasingFunction EasingFunction { get; set; }
protected override Freezable CreateInstanceCore()
{
return new LocationAnimation
{
To = To,
EasingFunction = EasingFunction
};
}
public override object GetCurrentValue(object defaultOriginValue, object defaultDestinationValue, AnimationClock animationClock)
{
var from = (Location)defaultOriginValue;
var progress = animationClock.CurrentProgress ?? 1d;
if (EasingFunction != null)
{
progress = EasingFunction.Ease(progress);
}
return new Location(
(1d - progress) * from.Latitude + progress * To.Latitude,
(1d - progress) * from.Longitude + progress * To.Longitude);
}
}
}