mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Reset transform center before Center animation
This commit is contained in:
parent
fac62cd1f7
commit
c49095ef8c
|
|
@ -142,6 +142,8 @@ namespace MapControl
|
|||
{
|
||||
if (!internalPropertyChange && !targetCenter.Equals(Center))
|
||||
{
|
||||
ResetTransformCenter();
|
||||
|
||||
centerCts?.Cancel();
|
||||
|
||||
centerAnimation = new Animation
|
||||
|
|
@ -154,7 +156,7 @@ namespace MapControl
|
|||
new KeyFrame
|
||||
{
|
||||
KeyTime = AnimationDuration,
|
||||
Setters = { new Setter(CenterProperty, new Location(targetCenter.Latitude, ConstrainedLongitude(targetCenter.Longitude))) }
|
||||
Setters = { new Setter(CenterProperty, new Location(targetCenter.Latitude, CoerceLongitude(targetCenter.Longitude))) }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -163,6 +165,11 @@ namespace MapControl
|
|||
|
||||
await centerAnimation.RunAsync(this, centerCts.Token);
|
||||
|
||||
if (!centerCts.IsCancellationRequested)
|
||||
{
|
||||
UpdateTransform();
|
||||
}
|
||||
|
||||
centerCts.Dispose();
|
||||
centerCts = null;
|
||||
centerAnimation = null;
|
||||
|
|
@ -225,7 +232,7 @@ namespace MapControl
|
|||
|
||||
if (!zoomLevelCts.IsCancellationRequested)
|
||||
{
|
||||
UpdateTransform(true);
|
||||
UpdateTransform(true); // reset transform center
|
||||
}
|
||||
|
||||
zoomLevelCts.Dispose();
|
||||
|
|
@ -285,6 +292,11 @@ namespace MapControl
|
|||
|
||||
await headingAnimation.RunAsync(this, headingCts.Token);
|
||||
|
||||
if (!headingCts.IsCancellationRequested)
|
||||
{
|
||||
UpdateTransform();
|
||||
}
|
||||
|
||||
headingCts.Dispose();
|
||||
headingCts = null;
|
||||
headingAnimation = null;
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
<Compile Include="..\Shared\Location.cs" Link="Location.cs" />
|
||||
<Compile Include="..\Shared\LocationCollection.cs" Link="LocationCollection.cs" />
|
||||
<Compile Include="..\Shared\MapBase.cs" Link="MapBase.cs" />
|
||||
<Compile Include="..\Shared\MapImageLayer.cs" Link="MapImageLayer.cs" />
|
||||
<Compile Include="..\Shared\MapPanel.cs" Link="MapPanel.cs" />
|
||||
<Compile Include="..\Shared\MapProjection.cs" Link="MapProjection.cs" />
|
||||
<Compile Include="..\Shared\MapTileLayer.cs" Link="MapTileLayer.cs" />
|
||||
|
|
|
|||
|
|
@ -372,7 +372,7 @@ namespace MapControl
|
|||
}
|
||||
}
|
||||
|
||||
internal double ConstrainedLongitude(double longitude)
|
||||
internal double CoerceLongitude(double longitude)
|
||||
{
|
||||
var offset = longitude - Center.Longitude;
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,13 @@ using System;
|
|||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
#if WINUI
|
||||
#if AVALONIA
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Threading;
|
||||
using DependencyProperty = Avalonia.AvaloniaProperty;
|
||||
using ImageSource = Avalonia.Media.IImage;
|
||||
#elif WINUI
|
||||
using Windows.Foundation;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
|
|
@ -35,27 +41,27 @@ namespace MapControl
|
|||
/// </summary>
|
||||
public abstract class MapImageLayer : MapPanel, IMapLayer
|
||||
{
|
||||
public static readonly DependencyProperty DescriptionProperty = DependencyProperty.Register(
|
||||
nameof(Description), typeof(string), typeof(MapImageLayer), new PropertyMetadata(null));
|
||||
public static readonly DependencyProperty DescriptionProperty =
|
||||
DependencyPropertyHelper.Register<MapImageLayer, string>(nameof(Description));
|
||||
|
||||
public static readonly DependencyProperty RelativeImageSizeProperty = DependencyProperty.Register(
|
||||
nameof(RelativeImageSize), typeof(double), typeof(MapImageLayer), new PropertyMetadata(1d));
|
||||
public static readonly DependencyProperty RelativeImageSizeProperty =
|
||||
DependencyPropertyHelper.Register<MapImageLayer, double>(nameof(RelativeImageSize), 1d);
|
||||
|
||||
public static readonly DependencyProperty UpdateIntervalProperty = DependencyProperty.Register(
|
||||
nameof(UpdateInterval), typeof(TimeSpan), typeof(MapImageLayer),
|
||||
new PropertyMetadata(TimeSpan.FromSeconds(0.2), (o, e) => ((MapImageLayer)o).updateTimer.Interval = (TimeSpan)e.NewValue));
|
||||
public static readonly DependencyProperty UpdateIntervalProperty =
|
||||
DependencyPropertyHelper.Register<MapImageLayer, TimeSpan>(nameof(UpdateInterval), TimeSpan.FromSeconds(0.2),
|
||||
false, (layer, oldValue, newValue) => layer.updateTimer.Interval = newValue);
|
||||
|
||||
public static readonly DependencyProperty UpdateWhileViewportChangingProperty = DependencyProperty.Register(
|
||||
nameof(UpdateWhileViewportChanging), typeof(bool), typeof(MapImageLayer), new PropertyMetadata(false));
|
||||
public static readonly DependencyProperty UpdateWhileViewportChangingProperty =
|
||||
DependencyPropertyHelper.Register<MapImageLayer, bool>(nameof(UpdateWhileViewportChanging));
|
||||
|
||||
public static readonly DependencyProperty MapBackgroundProperty = DependencyProperty.Register(
|
||||
nameof(MapBackground), typeof(Brush), typeof(MapImageLayer), new PropertyMetadata(null));
|
||||
public static readonly DependencyProperty MapBackgroundProperty =
|
||||
DependencyPropertyHelper.Register<MapImageLayer, Brush>(nameof(MapBackground));
|
||||
|
||||
public static readonly DependencyProperty MapForegroundProperty = DependencyProperty.Register(
|
||||
nameof(MapForeground), typeof(Brush), typeof(MapImageLayer), new PropertyMetadata(null));
|
||||
public static readonly DependencyProperty MapForegroundProperty =
|
||||
DependencyPropertyHelper.Register<MapImageLayer, Brush>(nameof(MapForeground));
|
||||
|
||||
public static readonly DependencyProperty LoadingProgressProperty = DependencyProperty.Register(
|
||||
nameof(LoadingProgress), typeof(double), typeof(MapImageLayer), new PropertyMetadata(1d));
|
||||
public static readonly DependencyProperty LoadingProgressProperty =
|
||||
DependencyPropertyHelper.Register<MapImageLayer, double>( nameof(LoadingProgress), 1d);
|
||||
|
||||
private readonly Progress<double> loadingProgress;
|
||||
private readonly DispatcherTimer updateTimer;
|
||||
|
|
@ -63,7 +69,7 @@ namespace MapControl
|
|||
|
||||
public MapImageLayer()
|
||||
{
|
||||
loadingProgress = new Progress<double>(p => LoadingProgress = p);
|
||||
loadingProgress = new Progress<double>(p => SetValue(LoadingProgressProperty, p));
|
||||
|
||||
updateTimer = this.CreateTimer(UpdateInterval);
|
||||
updateTimer.Tick += async (s, e) => await UpdateImageAsync();
|
||||
|
|
@ -131,7 +137,6 @@ namespace MapControl
|
|||
public double LoadingProgress
|
||||
{
|
||||
get => (double)GetValue(LoadingProgressProperty);
|
||||
private set => SetValue(LoadingProgressProperty, value);
|
||||
}
|
||||
|
||||
protected override void SetParentMap(MapBase map)
|
||||
|
|
@ -249,6 +254,8 @@ namespace MapControl
|
|||
topImage.Source = image;
|
||||
SetBoundingBox(topImage, boundingBox);
|
||||
|
||||
#if AVALONIA
|
||||
#else
|
||||
topImage.BeginAnimation(OpacityProperty, new DoubleAnimation
|
||||
{
|
||||
To = 1d,
|
||||
|
|
@ -261,6 +268,7 @@ namespace MapControl
|
|||
BeginTime = MapBase.ImageFadeDuration,
|
||||
Duration = TimeSpan.Zero
|
||||
});
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -236,7 +236,7 @@ namespace MapControl
|
|||
IsOutsideViewport(position.Value))
|
||||
{
|
||||
position = parentMap.LocationToView(
|
||||
new Location(location.Latitude, parentMap.ConstrainedLongitude(location.Longitude)));
|
||||
new Location(location.Latitude, parentMap.CoerceLongitude(location.Longitude)));
|
||||
}
|
||||
|
||||
return position;
|
||||
|
|
@ -267,7 +267,7 @@ namespace MapControl
|
|||
if (location != null)
|
||||
{
|
||||
var pos = parentMap.LocationToView(
|
||||
new Location(location.Latitude, parentMap.ConstrainedLongitude(location.Longitude)));
|
||||
new Location(location.Latitude, parentMap.CoerceLongitude(location.Longitude)));
|
||||
|
||||
if (pos.HasValue)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ namespace MapControl
|
|||
(point.Value.X < 0d || point.Value.X > parentMap.RenderSize.Width ||
|
||||
point.Value.Y < 0d || point.Value.Y > parentMap.RenderSize.Height))
|
||||
{
|
||||
longitudeOffset = parentMap.ConstrainedLongitude(location.Longitude) - location.Longitude;
|
||||
longitudeOffset = parentMap.CoerceLongitude(location.Longitude) - location.Longitude;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -129,6 +129,8 @@ namespace MapControl
|
|||
{
|
||||
if (!internalPropertyChange && !targetCenter.Equals(Center))
|
||||
{
|
||||
ResetTransformCenter();
|
||||
|
||||
if (centerAnimation != null)
|
||||
{
|
||||
centerAnimation.Completed -= CenterAnimationCompleted;
|
||||
|
|
@ -136,7 +138,7 @@ namespace MapControl
|
|||
|
||||
centerAnimation = new LocationAnimation
|
||||
{
|
||||
To = new Location(targetCenter.Latitude, ConstrainedLongitude(targetCenter.Longitude)),
|
||||
To = new Location(targetCenter.Latitude, CoerceLongitude(targetCenter.Longitude)),
|
||||
Duration = AnimationDuration,
|
||||
EasingFunction = AnimationEasingFunction
|
||||
};
|
||||
|
|
|
|||
|
|
@ -148,6 +148,8 @@ namespace MapControl
|
|||
{
|
||||
if (!internalPropertyChange)
|
||||
{
|
||||
ResetTransformCenter();
|
||||
|
||||
var targetCenter = CoerceCenterProperty(value);
|
||||
|
||||
if (!targetCenter.Equals(value))
|
||||
|
|
@ -165,7 +167,7 @@ namespace MapControl
|
|||
centerAnimation = new PointAnimation
|
||||
{
|
||||
From = new Windows.Foundation.Point(Center.Longitude, Center.Latitude),
|
||||
To = new Windows.Foundation.Point(ConstrainedLongitude(targetCenter.Longitude), targetCenter.Latitude),
|
||||
To = new Windows.Foundation.Point(CoerceLongitude(targetCenter.Longitude), targetCenter.Latitude),
|
||||
Duration = AnimationDuration,
|
||||
EasingFunction = AnimationEasingFunction,
|
||||
EnableDependentAnimation = true
|
||||
|
|
|
|||
Loading…
Reference in a new issue