XAML-Map-Control/MapControl/WinUI/TileImageLoader.WinUI.cs

45 lines
1.3 KiB
C#
Raw Normal View History

2021-07-02 21:18:39 +02:00
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
2024-02-03 21:01:53 +01:00
// Copyright © 2024 Clemens Fischer
2021-07-02 21:18:39 +02:00
// Licensed under the Microsoft Public License (Ms-PL)
2021-07-05 00:03:44 +02:00
using Microsoft.UI.Dispatching;
using Microsoft.UI.Xaml.Media;
2021-07-02 21:18:39 +02:00
using System;
using System.IO;
using System.Threading.Tasks;
namespace MapControl
{
public partial class TileImageLoader
{
/// <summary>
/// Default folder path where an IImageCache instance may save cached data, i.e. C:\ProgramData\MapControl\TileCache
/// </summary>
2022-08-06 10:40:59 +02:00
public static string DefaultCacheFolder =>
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MapControl", "TileCache");
2021-07-02 21:18:39 +02:00
private static Task LoadTileAsync(Tile tile, Func<Task<ImageSource>> loadImageFunc)
2021-07-02 21:18:39 +02:00
{
var tcs = new TaskCompletionSource();
2021-07-05 00:03:44 +02:00
async void callback()
2021-07-02 21:18:39 +02:00
{
try
{
2022-11-17 23:11:40 +01:00
tile.SetImageSource(await loadImageFunc());
2021-07-02 21:18:39 +02:00
tcs.TrySetResult();
}
catch (Exception ex)
{
tcs.TrySetException(ex);
}
2021-07-05 00:03:44 +02:00
}
2023-08-12 17:36:37 +02:00
tile.Image.DispatcherQueue.TryEnqueue(DispatcherQueuePriority.Low, callback);
2021-07-02 21:18:39 +02:00
return tcs.Task;
}
}
}