mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-05 06:26:41 +00:00
Implemented LocationAnimator
This commit is contained in:
parent
3706709cfc
commit
abe3bb75f9
3 changed files with 68 additions and 21 deletions
|
|
@ -59,11 +59,16 @@ namespace MapControl
|
|||
|
||||
static MapBase()
|
||||
{
|
||||
Animation.RegisterCustomAnimator<Location, LocationAnimator>();
|
||||
|
||||
ClipToBoundsProperty.OverrideDefaultValue(typeof(MapBase), true);
|
||||
|
||||
CenterProperty.Changed.AddClassHandler<MapBase, Location>(
|
||||
(map, args) => map.CenterPropertyChanged(args.NewValue.Value));
|
||||
|
||||
TargetCenterProperty.Changed.AddClassHandler<MapBase, Location>(
|
||||
async (map, args) => await map.TargetCenterPropertyChanged(args.NewValue.Value));
|
||||
|
||||
ZoomLevelProperty.Changed.AddClassHandler<MapBase, double>(
|
||||
(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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue