Moved asynchronous image loading to Tile class

This commit is contained in:
ClemensFischer 2025-09-10 20:09:12 +02:00
parent 2f9c50fb47
commit f4d43eeb44
10 changed files with 114 additions and 184 deletions

View file

@ -1,5 +1,4 @@
using System;
#if WPF
#if WPF
using System.Windows.Controls;
using System.Windows.Media;
#elif UWP
@ -25,25 +24,12 @@ namespace MapControl
Column = ((x % columnCount) + columnCount) % columnCount;
}
public Image Image { get; } = new Image { Stretch = Stretch.Fill };
public int ZoomLevel { get; }
public int X { get; }
public int Y { get; }
public int Column { get; }
public int Row => Y;
public Image Image { get; } = new Image { Stretch = Stretch.Fill };
public bool IsPending { get; set; } = true;
public void SetImageSource(ImageSource image)
{
IsPending = false;
Image.Source = image;
if (image != null && MapBase.ImageFadeDuration > TimeSpan.Zero)
{
FadeIn();
}
}
}
}

View file

@ -7,13 +7,6 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
#if WPF
using System.Windows.Media;
#elif UWP
using Windows.UI.Xaml.Media;
#elif WINUI
using Microsoft.UI.Xaml.Media;
#endif
namespace MapControl
{
@ -27,7 +20,7 @@ namespace MapControl
void CancelLoadTiles();
}
public partial class TileImageLoader : ITileImageLoader
public class TileImageLoader : ITileImageLoader
{
private static ILogger logger;
private static ILogger Logger => logger ?? (logger = ImageLoader.LoggerFactory?.CreateLogger<TileImageLoader>());
@ -161,9 +154,7 @@ namespace MapControl
if (string.IsNullOrEmpty(cacheName))
{
Task<ImageSource> LoadImage() => tileSource.LoadImageAsync(tile.Column, tile.Row, tile.ZoomLevel);
await LoadTileImage(tile, LoadImage).ConfigureAwait(false);
await tile.LoadImageAsync(() => tileSource.LoadImageAsync(tile.Column, tile.Row, tile.ZoomLevel)).ConfigureAwait(false);
}
else
{
@ -175,9 +166,7 @@ namespace MapControl
if (buffer?.Length > 0)
{
Task<ImageSource> LoadImage() => tileSource.LoadImageAsync(buffer);
await LoadTileImage(tile, LoadImage).ConfigureAwait(false);
await tile.LoadImageAsync(() => tileSource.LoadImageAsync(buffer)).ConfigureAwait(false);
}
}
}