Update Tile class

This commit is contained in:
ClemensFischer 2022-11-19 18:00:26 +01:00
parent caf6a9c8a4
commit 5c17a1c36f
4 changed files with 26 additions and 42 deletions

View file

@ -239,7 +239,7 @@ namespace MapControl
if (equivalentTile != null)
{
tile.SetImageSource(equivalentTile);
tile.SetImageSource(equivalentTile.Image.Source, false);
}
}

View file

@ -2,6 +2,7 @@
// © 2022 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;
#if WINUI
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
@ -52,14 +53,22 @@ namespace MapControl
public bool Pending { get; set; } = true;
public void SetImageSource(Tile tile)
public void SetImageSource(ImageSource image, bool animateOpacity = true)
{
Pending = false;
Image.Opacity = 1d;
Image.Source = tile.Image.Source;
Image.Source = image;
if (image != null && animateOpacity && MapBase.ImageFadeDuration > TimeSpan.Zero)
{
AnimateImageOpacity();
}
else
{
Image.Opacity = 1d;
}
}
private void FadeIn()
private void BeginOpacityAnimation()
{
Image.BeginAnimation(UIElement.OpacityProperty, new DoubleAnimation
{

View file

@ -11,28 +11,17 @@ namespace MapControl
{
public partial class Tile
{
public void SetImageSource(ImageSource image)
private void AnimateImageOpacity()
{
Pending = false;
if (image != null && MapBase.ImageFadeDuration > TimeSpan.Zero)
if (Image.Source is BitmapSource bitmap && !bitmap.IsFrozen && bitmap.IsDownloading)
{
if (image is BitmapSource bitmap && !bitmap.IsFrozen && bitmap.IsDownloading)
{
bitmap.DownloadCompleted += BitmapDownloadCompleted;
bitmap.DownloadFailed += BitmapDownloadFailed;
}
else
{
FadeIn();
}
bitmap.DownloadCompleted += BitmapDownloadCompleted;
bitmap.DownloadFailed += BitmapDownloadFailed;
}
else
{
Image.Opacity = 1d;
BeginOpacityAnimation();
}
Image.Source = image;
}
private void BitmapDownloadCompleted(object sender, EventArgs e)
@ -42,7 +31,7 @@ namespace MapControl
bitmap.DownloadCompleted -= BitmapDownloadCompleted;
bitmap.DownloadFailed -= BitmapDownloadFailed;
FadeIn();
BeginOpacityAnimation();
}
private void BitmapDownloadFailed(object sender, ExceptionEventArgs e)

View file

@ -2,14 +2,11 @@
// © 2022 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;
#if WINUI
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Media.Imaging;
#else
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
#endif
@ -17,28 +14,17 @@ namespace MapControl
{
public partial class Tile
{
public void SetImageSource(ImageSource image)
private void AnimateImageOpacity()
{
Pending = false;
if (image != null && MapBase.ImageFadeDuration > TimeSpan.Zero)
if (Image.Source is BitmapImage bitmap && bitmap.UriSource != null)
{
if (image is BitmapImage bitmap && bitmap.UriSource != null)
{
bitmap.ImageOpened += BitmapImageOpened;
bitmap.ImageFailed += BitmapImageFailed;
}
else
{
FadeIn();
}
bitmap.ImageOpened += BitmapImageOpened;
bitmap.ImageFailed += BitmapImageFailed;
}
else
{
Image.Opacity = 1d;
BeginOpacityAnimation();
}
Image.Source = image;
}
private void BitmapImageOpened(object sender, RoutedEventArgs e)
@ -48,7 +34,7 @@ namespace MapControl
bitmap.ImageOpened -= BitmapImageOpened;
bitmap.ImageFailed -= BitmapImageFailed;
FadeIn();
BeginOpacityAnimation();
}
private void BitmapImageFailed(object sender, ExceptionRoutedEventArgs e)