diff --git a/MapControl/Avalonia/LocationAnimator.Avalonia.cs b/MapControl/Avalonia/LocationAnimator.Avalonia.cs index 03b7c96e..7a422131 100644 --- a/MapControl/Avalonia/LocationAnimator.Avalonia.cs +++ b/MapControl/Avalonia/LocationAnimator.Avalonia.cs @@ -10,7 +10,9 @@ namespace MapControl { public override Location Interpolate(double progress, Location oldValue, Location newValue) { - throw new System.NotImplementedException(); + return new Location( + (1d - progress) * oldValue.Latitude + progress * newValue.Latitude, + (1d - progress) * oldValue.Longitude + progress * newValue.Longitude); } } } diff --git a/MapControl/Avalonia/MapBase.Avalonia.cs b/MapControl/Avalonia/MapBase.Avalonia.cs index 02715b1a..d21ce5d5 100644 --- a/MapControl/Avalonia/MapBase.Avalonia.cs +++ b/MapControl/Avalonia/MapBase.Avalonia.cs @@ -59,11 +59,16 @@ namespace MapControl static MapBase() { + Animation.RegisterCustomAnimator(); + ClipToBoundsProperty.OverrideDefaultValue(typeof(MapBase), true); CenterProperty.Changed.AddClassHandler( (map, args) => map.CenterPropertyChanged(args.NewValue.Value)); + TargetCenterProperty.Changed.AddClassHandler( + async (map, args) => await map.TargetCenterPropertyChanged(args.NewValue.Value)); + ZoomLevelProperty.Changed.AddClassHandler( (map, args) => map.ZoomLevelPropertyChanged(args.NewValue.Value)); @@ -161,6 +166,41 @@ namespace MapControl if (!internalPropertyChange) { UpdateTransform(); + + if (centerAnimation == null) + { + SetValueInternal(TargetCenterProperty, center); + } + } + } + + private async Task TargetCenterPropertyChanged(Location targetCenter) + { + if (!internalPropertyChange && !targetCenter.Equals(Center)) + { + centerCts?.Cancel(); + + centerAnimation = new Animation + { + FillMode = FillMode.Forward, + Duration = AnimationDuration, + Children = + { + new KeyFrame + { + KeyTime = AnimationDuration, + Setters = { new Setter(CenterProperty, new Location(targetCenter.Latitude, ConstrainedLongitude(targetCenter.Longitude))) } + } + } + }; + + centerCts = new CancellationTokenSource(); + + await centerAnimation.RunAsync(this, centerCts.Token); + + centerCts.Dispose(); + centerCts = null; + centerAnimation = null; } } diff --git a/MapControl/Avalonia/MapControl.Avalonia.csproj b/MapControl/Avalonia/MapControl.Avalonia.csproj index 8b65de71..17935f99 100644 --- a/MapControl/Avalonia/MapControl.Avalonia.csproj +++ b/MapControl/Avalonia/MapControl.Avalonia.csproj @@ -15,27 +15,32 @@ XAML.MapControl AVALONIA + - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + +