From 115525cbfc9a8ddfb7d3fa6f23d3d556989606a0 Mon Sep 17 00:00:00 2001 From: ClemensFischer Date: Mon, 20 Jan 2025 19:28:59 +0100 Subject: [PATCH] Update TileImageLoader.cs --- MapControl/Shared/TileImageLoader.cs | 43 ++++++++++++++-------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/MapControl/Shared/TileImageLoader.cs b/MapControl/Shared/TileImageLoader.cs index 3afd1635..fefc0d21 100644 --- a/MapControl/Shared/TileImageLoader.cs +++ b/MapControl/Shared/TileImageLoader.cs @@ -91,7 +91,14 @@ namespace MapControl progress?.Report((double)(tileCount - tileStack.Count) / tileCount); - await LoadTileAsync(tile, tileSource, cacheName).ConfigureAwait(false); + try + { + await LoadTileAsync(tile, tileSource, cacheName).ConfigureAwait(false); + } + catch (Exception ex) + { + Debug.WriteLine($"{nameof(TileImageLoader)}: {tile.ZoomLevel}/{tile.Column}/{tile.Row}: {ex.Message}"); + } } } @@ -107,33 +114,27 @@ namespace MapControl private static async Task LoadTileAsync(Tile tile, TileSource tileSource, string cacheName) { - // Both tileSource.LoadImageAsync calls below are executed in the UI thread in WinUI and UWP. + // Pass tileSource.LoadImageAsync calls to platform-specific method + // LoadTileAsync(Tile, Func>) for execution on the UI thread in WinUI/UWP. - try + if (string.IsNullOrEmpty(cacheName)) { - if (string.IsNullOrEmpty(cacheName)) - { - await LoadTileAsync(tile, () => tileSource.LoadImageAsync(tile.Column, tile.Row, tile.ZoomLevel)).ConfigureAwait(false); - } - else - { - var uri = tileSource.GetUri(tile.Column, tile.Row, tile.ZoomLevel); + await LoadTileAsync(tile, () => tileSource.LoadImageAsync(tile.Column, tile.Row, tile.ZoomLevel)).ConfigureAwait(false); + } + else + { + var uri = tileSource.GetUri(tile.Column, tile.Row, tile.ZoomLevel); - if (uri != null) + if (uri != null) + { + var buffer = await LoadCachedBufferAsync(tile, uri, cacheName).ConfigureAwait(false); + + if (buffer != null && buffer.Length > 0) { - var buffer = await LoadCachedBufferAsync(tile, uri, cacheName).ConfigureAwait(false); - - if (buffer != null && buffer.Length > 0) - { - await LoadTileAsync(tile, () => tileSource.LoadImageAsync(buffer)).ConfigureAwait(false); - } + await LoadTileAsync(tile, () => tileSource.LoadImageAsync(buffer)).ConfigureAwait(false); } } } - catch (Exception ex) - { - Debug.WriteLine($"{nameof(TileImageLoader)}: {tile.ZoomLevel}/{tile.Column}/{tile.Row}: {ex.Message}"); - } } private static async Task LoadCachedBufferAsync(Tile tile, Uri uri, string cacheName)