2021-07-02 21:18:39 +02:00
|
|
|
|
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
2025-01-01 18:57:55 +01:00
|
|
|
|
// Copyright © 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.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MapControl
|
|
|
|
|
|
{
|
|
|
|
|
|
public partial class TileImageLoader
|
|
|
|
|
|
{
|
2023-08-19 17:48:52 +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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|