mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
45 lines
1.3 KiB
C#
45 lines
1.3 KiB
C#
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
|
// Copyright © 2024 Clemens Fischer
|
|
// Licensed under the Microsoft Public License (Ms-PL)
|
|
|
|
using Microsoft.UI.Dispatching;
|
|
using Microsoft.UI.Xaml.Media;
|
|
using System;
|
|
using System.IO;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MapControl
|
|
{
|
|
public partial class TileImageLoader
|
|
{
|
|
/// <summary>
|
|
/// Default folder where the Cache instance may save data, i.e. "C:\ProgramData\MapControl\TileCache".
|
|
/// </summary>
|
|
public static string DefaultCacheFolder =>
|
|
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MapControl", "TileCache");
|
|
|
|
|
|
private static Task LoadTileAsync(Tile tile, Func<Task<ImageSource>> loadImageFunc)
|
|
{
|
|
var tcs = new TaskCompletionSource();
|
|
|
|
async void callback()
|
|
{
|
|
try
|
|
{
|
|
tile.SetImageSource(await loadImageFunc());
|
|
tcs.TrySetResult();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
tcs.TrySetException(ex);
|
|
}
|
|
}
|
|
|
|
tile.Image.DispatcherQueue.TryEnqueue(DispatcherQueuePriority.Low, callback);
|
|
|
|
return tcs.Task;
|
|
}
|
|
}
|
|
}
|