mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Removed OpacityHelper
This commit is contained in:
parent
3afbdadf0c
commit
b9a34fd5e4
|
|
@ -161,21 +161,7 @@ namespace MapControl
|
||||||
|
|
||||||
centerCts?.Cancel();
|
centerCts?.Cancel();
|
||||||
|
|
||||||
centerAnimation = new Animation
|
centerAnimation = CreateAnimation(CenterProperty, new Location(targetCenter.Latitude, CoerceLongitude(targetCenter.Longitude)));
|
||||||
{
|
|
||||||
FillMode = FillMode.Forward,
|
|
||||||
Duration = AnimationDuration,
|
|
||||||
Easing = AnimationEasing,
|
|
||||||
Children =
|
|
||||||
{
|
|
||||||
new KeyFrame
|
|
||||||
{
|
|
||||||
KeyTime = AnimationDuration,
|
|
||||||
Setters = { new Setter(CenterProperty, new Location(targetCenter.Latitude, CoerceLongitude(targetCenter.Longitude))) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
centerCts = new CancellationTokenSource();
|
centerCts = new CancellationTokenSource();
|
||||||
|
|
||||||
await centerAnimation.RunAsync(this, centerCts.Token);
|
await centerAnimation.RunAsync(this, centerCts.Token);
|
||||||
|
|
@ -226,21 +212,7 @@ namespace MapControl
|
||||||
{
|
{
|
||||||
zoomLevelCts?.Cancel();
|
zoomLevelCts?.Cancel();
|
||||||
|
|
||||||
zoomLevelAnimation = new Animation
|
zoomLevelAnimation = CreateAnimation(ZoomLevelProperty, targetZoomLevel);
|
||||||
{
|
|
||||||
FillMode = FillMode.Forward,
|
|
||||||
Duration = AnimationDuration,
|
|
||||||
Easing = AnimationEasing,
|
|
||||||
Children =
|
|
||||||
{
|
|
||||||
new KeyFrame
|
|
||||||
{
|
|
||||||
KeyTime = AnimationDuration,
|
|
||||||
Setters = { new Setter(ZoomLevelProperty, targetZoomLevel) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
zoomLevelCts = new CancellationTokenSource();
|
zoomLevelCts = new CancellationTokenSource();
|
||||||
|
|
||||||
await zoomLevelAnimation.RunAsync(this, zoomLevelCts.Token);
|
await zoomLevelAnimation.RunAsync(this, zoomLevelCts.Token);
|
||||||
|
|
@ -288,21 +260,7 @@ namespace MapControl
|
||||||
|
|
||||||
headingCts?.Cancel();
|
headingCts?.Cancel();
|
||||||
|
|
||||||
headingAnimation = new Animation
|
headingAnimation = CreateAnimation(HeadingProperty, targetHeading);
|
||||||
{
|
|
||||||
FillMode = FillMode.Forward,
|
|
||||||
Duration = AnimationDuration,
|
|
||||||
Easing = AnimationEasing,
|
|
||||||
Children =
|
|
||||||
{
|
|
||||||
new KeyFrame
|
|
||||||
{
|
|
||||||
KeyTime = AnimationDuration,
|
|
||||||
Setters = { new Setter(HeadingProperty, targetHeading) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
headingCts = new CancellationTokenSource();
|
headingCts = new CancellationTokenSource();
|
||||||
|
|
||||||
await headingAnimation.RunAsync(this, headingCts.Token);
|
await headingAnimation.RunAsync(this, headingCts.Token);
|
||||||
|
|
@ -317,5 +275,23 @@ namespace MapControl
|
||||||
headingAnimation = null;
|
headingAnimation = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Animation CreateAnimation(DependencyProperty property, object value)
|
||||||
|
{
|
||||||
|
return new Animation
|
||||||
|
{
|
||||||
|
FillMode = FillMode.Forward,
|
||||||
|
Duration = AnimationDuration,
|
||||||
|
Easing = AnimationEasing,
|
||||||
|
Children =
|
||||||
|
{
|
||||||
|
new KeyFrame
|
||||||
|
{
|
||||||
|
KeyTime = AnimationDuration,
|
||||||
|
Setters = { new Setter(property, value) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
32
MapControl/Avalonia/MapImageLayer.Avalonia.cs
Normal file
32
MapControl/Avalonia/MapImageLayer.Avalonia.cs
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
||||||
|
// Copyright © Clemens Fischer
|
||||||
|
// Licensed under the Microsoft Public License (Ms-PL)
|
||||||
|
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace MapControl
|
||||||
|
{
|
||||||
|
public partial class MapImageLayer
|
||||||
|
{
|
||||||
|
public static void FadeOver(Image topImage, Image bottomImage)
|
||||||
|
{
|
||||||
|
var animation = new Animation
|
||||||
|
{
|
||||||
|
FillMode = FillMode.Forward,
|
||||||
|
Duration = MapBase.ImageFadeDuration,
|
||||||
|
Children =
|
||||||
|
{
|
||||||
|
new KeyFrame
|
||||||
|
{
|
||||||
|
KeyTime = MapBase.ImageFadeDuration,
|
||||||
|
Setters = { new Setter(Visual.OpacityProperty, 1d) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
_ = animation.RunAsync(topImage).ContinueWith(
|
||||||
|
_ => bottomImage.Opacity = 0d,
|
||||||
|
TaskScheduler.FromCurrentSynchronizationContext());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,56 +0,0 @@
|
||||||
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
|
||||||
// Copyright © Clemens Fischer
|
|
||||||
// Licensed under the Microsoft Public License (Ms-PL)
|
|
||||||
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace MapControl
|
|
||||||
{
|
|
||||||
public static class OpacityHelper
|
|
||||||
{
|
|
||||||
public static Task FadeIn(Control element)
|
|
||||||
{
|
|
||||||
var animation = new Animation
|
|
||||||
{
|
|
||||||
Duration = MapBase.ImageFadeDuration,
|
|
||||||
Children =
|
|
||||||
{
|
|
||||||
new KeyFrame
|
|
||||||
{
|
|
||||||
KeyTime = TimeSpan.Zero,
|
|
||||||
Setters = { new Setter(Visual.OpacityProperty, 0d) }
|
|
||||||
},
|
|
||||||
new KeyFrame
|
|
||||||
{
|
|
||||||
KeyTime = MapBase.ImageFadeDuration,
|
|
||||||
Setters = { new Setter(Visual.OpacityProperty, 1d) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return animation.RunAsync(element);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static async Task SwapOpacitiesAsync(Control topElement, Control bottomElement)
|
|
||||||
{
|
|
||||||
var animation = new Animation
|
|
||||||
{
|
|
||||||
FillMode = FillMode.Forward,
|
|
||||||
Duration = MapBase.ImageFadeDuration,
|
|
||||||
Children =
|
|
||||||
{
|
|
||||||
new KeyFrame
|
|
||||||
{
|
|
||||||
KeyTime = MapBase.ImageFadeDuration,
|
|
||||||
Setters = { new Setter(Visual.OpacityProperty, 1d) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
await animation.RunAsync(topElement);
|
|
||||||
|
|
||||||
bottomElement.Opacity = 0d;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -2,13 +2,33 @@
|
||||||
// Copyright © Clemens Fischer
|
// Copyright © Clemens Fischer
|
||||||
// Licensed under the Microsoft Public License (Ms-PL)
|
// Licensed under the Microsoft Public License (Ms-PL)
|
||||||
|
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace MapControl
|
namespace MapControl
|
||||||
{
|
{
|
||||||
public partial class Tile
|
public partial class Tile
|
||||||
{
|
{
|
||||||
private void AnimateImageOpacity()
|
private void AnimateImageOpacity()
|
||||||
{
|
{
|
||||||
_ = OpacityHelper.FadeIn(Image);
|
var animation = new Animation
|
||||||
|
{
|
||||||
|
Duration = MapBase.ImageFadeDuration,
|
||||||
|
Children =
|
||||||
|
{
|
||||||
|
new KeyFrame
|
||||||
|
{
|
||||||
|
KeyTime = TimeSpan.Zero,
|
||||||
|
Setters = { new Setter(Visual.OpacityProperty, 0d) }
|
||||||
|
},
|
||||||
|
new KeyFrame
|
||||||
|
{
|
||||||
|
KeyTime = MapBase.ImageFadeDuration,
|
||||||
|
Setters = { new Setter(Visual.OpacityProperty, 1d) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
_ = animation.RunAsync(Image);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ namespace MapControl
|
||||||
/// Displays a single map image, e.g. from a Web Map Service (WMS).
|
/// Displays a single map image, e.g. from a Web Map Service (WMS).
|
||||||
/// The image must be provided by the abstract GetImageAsync() method.
|
/// The image must be provided by the abstract GetImageAsync() method.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class MapImageLayer : MapPanel, IMapLayer
|
public abstract partial class MapImageLayer : MapPanel, IMapLayer
|
||||||
{
|
{
|
||||||
public static readonly DependencyProperty DescriptionProperty =
|
public static readonly DependencyProperty DescriptionProperty =
|
||||||
DependencyPropertyHelper.Register<MapImageLayer, string>(nameof(Description));
|
DependencyPropertyHelper.Register<MapImageLayer, string>(nameof(Description));
|
||||||
|
|
@ -199,7 +199,7 @@ namespace MapControl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await SwapImages(image, boundingBox);
|
SwapImages(image, boundingBox);
|
||||||
|
|
||||||
updateInProgress = false;
|
updateInProgress = false;
|
||||||
}
|
}
|
||||||
|
|
@ -231,7 +231,7 @@ namespace MapControl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task SwapImages(ImageSource image, BoundingBox boundingBox)
|
private void SwapImages(ImageSource image, BoundingBox boundingBox)
|
||||||
{
|
{
|
||||||
if (Children.Count >= 2)
|
if (Children.Count >= 2)
|
||||||
{
|
{
|
||||||
|
|
@ -244,7 +244,7 @@ namespace MapControl
|
||||||
topImage.Source = image;
|
topImage.Source = image;
|
||||||
SetBoundingBox(topImage, boundingBox);
|
SetBoundingBox(topImage, boundingBox);
|
||||||
|
|
||||||
await OpacityHelper.SwapOpacitiesAsync(topImage, bottomImage);
|
FadeOver(topImage, bottomImage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -242,6 +242,9 @@
|
||||||
<Compile Include="..\WinUI\MapGraticule.WinUI.cs">
|
<Compile Include="..\WinUI\MapGraticule.WinUI.cs">
|
||||||
<Link>MapGraticule.WinUI.cs</Link>
|
<Link>MapGraticule.WinUI.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="..\WinUI\MapImageLayer.WinUI.cs">
|
||||||
|
<Link>MapImageLayer.WinUI.cs</Link>
|
||||||
|
</Compile>
|
||||||
<Compile Include="..\WinUI\MapItem.WinUI.cs">
|
<Compile Include="..\WinUI\MapItem.WinUI.cs">
|
||||||
<Link>MapItem.WinUI.cs</Link>
|
<Link>MapItem.WinUI.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
|
@ -260,9 +263,6 @@
|
||||||
<Compile Include="..\WinUI\Matrix.WinUI.cs">
|
<Compile Include="..\WinUI\Matrix.WinUI.cs">
|
||||||
<Link>Matrix.WinUI.cs</Link>
|
<Link>Matrix.WinUI.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="..\WinUI\OpacityHelper.WinUI.cs">
|
|
||||||
<Link>OpacityHelper.WinUI.cs</Link>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="..\WinUI\Point.WinUI.cs">
|
<Compile Include="..\WinUI\Point.WinUI.cs">
|
||||||
<Link>Point.WinUI.cs</Link>
|
<Link>Point.WinUI.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
|
|
||||||
|
|
@ -3,30 +3,27 @@
|
||||||
// Licensed under the Microsoft Public License (Ms-PL)
|
// Licensed under the Microsoft Public License (Ms-PL)
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Windows.Controls;
|
||||||
using System.Windows;
|
|
||||||
using System.Windows.Media.Animation;
|
using System.Windows.Media.Animation;
|
||||||
|
|
||||||
namespace MapControl
|
namespace MapControl
|
||||||
{
|
{
|
||||||
public static class OpacityHelper
|
public partial class MapImageLayer
|
||||||
{
|
{
|
||||||
public static Task SwapOpacitiesAsync(UIElement topElement, UIElement bottomElement)
|
public static void FadeOver(Image topImage, Image bottomImage)
|
||||||
{
|
{
|
||||||
topElement.BeginAnimation(UIElement.OpacityProperty, new DoubleAnimation
|
topImage.BeginAnimation(OpacityProperty, new DoubleAnimation
|
||||||
{
|
{
|
||||||
To = 1d,
|
To = 1d,
|
||||||
Duration = MapBase.ImageFadeDuration
|
Duration = MapBase.ImageFadeDuration
|
||||||
});
|
});
|
||||||
|
|
||||||
bottomElement.BeginAnimation(UIElement.OpacityProperty, new DoubleAnimation
|
bottomImage.BeginAnimation(OpacityProperty, new DoubleAnimation
|
||||||
{
|
{
|
||||||
To = 0d,
|
To = 0d,
|
||||||
BeginTime = MapBase.ImageFadeDuration,
|
BeginTime = MapBase.ImageFadeDuration,
|
||||||
Duration = TimeSpan.Zero
|
Duration = TimeSpan.Zero
|
||||||
});
|
});
|
||||||
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
45
MapControl/WinUI/MapImageLayer.WinUI.cs
Normal file
45
MapControl/WinUI/MapImageLayer.WinUI.cs
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
||||||
|
// Copyright © Clemens Fischer
|
||||||
|
// Licensed under the Microsoft Public License (Ms-PL)
|
||||||
|
|
||||||
|
using System;
|
||||||
|
#if UWP
|
||||||
|
using Windows.UI.Xaml.Controls;
|
||||||
|
using Windows.UI.Xaml.Media.Animation;
|
||||||
|
#else
|
||||||
|
using Microsoft.UI.Xaml.Controls;
|
||||||
|
using Microsoft.UI.Xaml.Media.Animation;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace MapControl
|
||||||
|
{
|
||||||
|
public partial class MapImageLayer
|
||||||
|
{
|
||||||
|
public static void FadeOver(Image topImage, Image bottomImage)
|
||||||
|
{
|
||||||
|
var topImageAnimation = new DoubleAnimation
|
||||||
|
{
|
||||||
|
To = 1d,
|
||||||
|
Duration = MapBase.ImageFadeDuration
|
||||||
|
};
|
||||||
|
|
||||||
|
var bottomImageAnimation = new DoubleAnimation
|
||||||
|
{
|
||||||
|
To = 0d,
|
||||||
|
BeginTime = MapBase.ImageFadeDuration,
|
||||||
|
Duration = TimeSpan.Zero
|
||||||
|
};
|
||||||
|
|
||||||
|
Storyboard.SetTargetProperty(topImageAnimation, nameof(Opacity));
|
||||||
|
Storyboard.SetTarget(topImageAnimation, topImage);
|
||||||
|
|
||||||
|
Storyboard.SetTargetProperty(bottomImageAnimation, nameof(Opacity));
|
||||||
|
Storyboard.SetTarget(bottomImageAnimation, bottomImage);
|
||||||
|
|
||||||
|
var storyboard = new Storyboard();
|
||||||
|
storyboard.Children.Add(topImageAnimation);
|
||||||
|
storyboard.Children.Add(bottomImageAnimation);
|
||||||
|
storyboard.Begin();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,47 +0,0 @@
|
||||||
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
|
||||||
// Copyright © Clemens Fischer
|
|
||||||
// Licensed under the Microsoft Public License (Ms-PL)
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
#if UWP
|
|
||||||
using Windows.UI.Xaml;
|
|
||||||
using Windows.UI.Xaml.Media.Animation;
|
|
||||||
#else
|
|
||||||
using Microsoft.UI.Xaml;
|
|
||||||
using Microsoft.UI.Xaml.Media.Animation;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace MapControl
|
|
||||||
{
|
|
||||||
public static class OpacityHelper
|
|
||||||
{
|
|
||||||
public static void BeginOpacityAnimation(DependencyObject obj, DoubleAnimation animation)
|
|
||||||
{
|
|
||||||
Storyboard.SetTargetProperty(animation, nameof(UIElement.Opacity));
|
|
||||||
Storyboard.SetTarget(animation, obj);
|
|
||||||
|
|
||||||
var storyboard = new Storyboard();
|
|
||||||
storyboard.Children.Add(animation);
|
|
||||||
storyboard.Begin();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Task SwapOpacitiesAsync(UIElement topElement, UIElement bottomElement)
|
|
||||||
{
|
|
||||||
BeginOpacityAnimation(topElement, new DoubleAnimation
|
|
||||||
{
|
|
||||||
To = 1d,
|
|
||||||
Duration = MapBase.ImageFadeDuration
|
|
||||||
});
|
|
||||||
|
|
||||||
BeginOpacityAnimation(bottomElement, new DoubleAnimation
|
|
||||||
{
|
|
||||||
To = 0d,
|
|
||||||
BeginTime = MapBase.ImageFadeDuration,
|
|
||||||
Duration = TimeSpan.Zero
|
|
||||||
});
|
|
||||||
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -18,13 +18,19 @@ namespace MapControl
|
||||||
{
|
{
|
||||||
private void BeginOpacityAnimation()
|
private void BeginOpacityAnimation()
|
||||||
{
|
{
|
||||||
OpacityHelper.BeginOpacityAnimation(Image,
|
var animation = new DoubleAnimation
|
||||||
new DoubleAnimation
|
{
|
||||||
{
|
From = 0d,
|
||||||
From = 0d,
|
Duration = MapBase.ImageFadeDuration,
|
||||||
Duration = MapBase.ImageFadeDuration,
|
FillBehavior = FillBehavior.Stop
|
||||||
FillBehavior = FillBehavior.Stop
|
};
|
||||||
});
|
|
||||||
|
Storyboard.SetTargetProperty(animation, nameof(UIElement.Opacity));
|
||||||
|
Storyboard.SetTarget(animation, Image);
|
||||||
|
|
||||||
|
var storyboard = new Storyboard();
|
||||||
|
storyboard.Children.Add(animation);
|
||||||
|
storyboard.Begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AnimateImageOpacity()
|
private void AnimateImageOpacity()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue