2017-08-04 21:38:58 +02:00
|
|
|
|
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
2024-02-03 21:01:53 +01:00
|
|
|
|
// Copyright © 2024 Clemens Fischer
|
2017-08-04 21:38:58 +02:00
|
|
|
|
// Licensed under the Microsoft Public License (Ms-PL)
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Threading.Tasks;
|
2024-02-13 20:51:22 +01:00
|
|
|
|
using Windows.Storage;
|
2021-06-28 23:35:03 +02:00
|
|
|
|
using Windows.UI.Core;
|
|
|
|
|
|
using Windows.UI.Xaml.Media;
|
2017-08-04 21:38:58 +02:00
|
|
|
|
|
|
|
|
|
|
namespace MapControl
|
|
|
|
|
|
{
|
2018-08-08 23:31:52 +02:00
|
|
|
|
public partial class TileImageLoader
|
2017-08-04 21:38:58 +02:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
2024-02-08 21:36:46 +01:00
|
|
|
|
/// Default folder where the Cache instance may save data.
|
2017-08-04 21:38:58 +02:00
|
|
|
|
/// </summary>
|
2024-02-13 20:51:22 +01:00
|
|
|
|
public static string DefaultCacheFolder => ApplicationData.Current.TemporaryFolder.Path;
|
2017-08-04 21:38:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
2023-08-19 17:48:52 +02:00
|
|
|
|
private static async Task LoadTileAsync(Tile tile, Func<Task<ImageSource>> loadImageFunc)
|
2021-06-28 23:35:03 +02:00
|
|
|
|
{
|
|
|
|
|
|
var tcs = new TaskCompletionSource<object>();
|
|
|
|
|
|
|
2021-07-05 00:03:44 +02:00
|
|
|
|
async void callback()
|
2021-06-28 23:35:03 +02:00
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2022-11-17 23:11:40 +01:00
|
|
|
|
tile.SetImageSource(await loadImageFunc());
|
2021-06-28 23:35:03 +02:00
|
|
|
|
tcs.TrySetResult(null);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
tcs.TrySetException(ex);
|
|
|
|
|
|
}
|
2021-07-05 00:03:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
await tile.Image.Dispatcher.RunAsync(CoreDispatcherPriority.Low, callback);
|
2021-06-28 23:35:03 +02:00
|
|
|
|
|
|
|
|
|
|
await tcs.Task.ConfigureAwait(false);
|
|
|
|
|
|
}
|
2017-08-04 21:38:58 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|