mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Implemented LocationAnimator
This commit is contained in:
parent
3706709cfc
commit
abe3bb75f9
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
<PackageId>XAML.MapControl</PackageId>
|
||||
<DefineConstants>AVALONIA</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\Shared\BoundingBox.cs" Link="BoundingBox.cs" />
|
||||
<Compile Include="..\Shared\ImageFileCache.cs" Link="ImageFileCache.cs" />
|
||||
|
|
@ -38,6 +39,10 @@
|
|||
<Compile Include="..\WPF\TypeConverters.WPF.cs" Link="TypeConverters.WPF.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\..\MapControl.snk" Link="MapControl.snk" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Avalonia" Version="11.0.10" />
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="8.0.0" />
|
||||
|
|
|
|||
Loading…
Reference in a new issue