From 67f319e98c361be2f2d61e6e53d0525662410296 Mon Sep 17 00:00:00 2001 From: ClemensFischer Date: Fri, 22 Aug 2025 22:41:57 +0200 Subject: [PATCH] TileImageLoader --- MapControl/Shared/MapTileLayer.cs | 2 +- MapControl/Shared/MapTileLayerBase.cs | 4 ++-- MapControl/Shared/TileImageLoader.cs | 18 ++++++++++-------- MapControl/Shared/WmtsTileLayer.cs | 4 +--- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/MapControl/Shared/MapTileLayer.cs b/MapControl/Shared/MapTileLayer.cs index afbbbda0..576586a2 100644 --- a/MapControl/Shared/MapTileLayer.cs +++ b/MapControl/Shared/MapTileLayer.cs @@ -130,7 +130,7 @@ namespace MapControl } UpdateTiles(); - LoadTiles(Tiles, SourceName); + BeginLoadTiles(Tiles, SourceName); } } diff --git a/MapControl/Shared/MapTileLayerBase.cs b/MapControl/Shared/MapTileLayerBase.cs index fe1faa2a..1e92620e 100644 --- a/MapControl/Shared/MapTileLayerBase.cs +++ b/MapControl/Shared/MapTileLayerBase.cs @@ -191,11 +191,11 @@ namespace MapControl protected bool IsBaseMapLayer => parentMap != null && parentMap.Children.Count > 0 && parentMap.Children[0] == this; - protected void LoadTiles(IEnumerable tiles, string cacheName) + protected void BeginLoadTiles(IEnumerable tiles, string cacheName) { if (TileSource != null && tiles != null && tiles.Any(tile => tile.IsPending)) { - TileImageLoader.LoadTiles(tiles, TileSource, cacheName, loadingProgress); + TileImageLoader.BeginLoadTiles(tiles, TileSource, cacheName, loadingProgress); } } diff --git a/MapControl/Shared/TileImageLoader.cs b/MapControl/Shared/TileImageLoader.cs index 58a2e4e2..d07a640e 100644 --- a/MapControl/Shared/TileImageLoader.cs +++ b/MapControl/Shared/TileImageLoader.cs @@ -24,7 +24,7 @@ namespace MapControl /// public interface ITileImageLoader { - void LoadTiles(IEnumerable tiles, TileSource tileSource, string cacheName, IProgress progress); + void BeginLoadTiles(IEnumerable tiles, TileSource tileSource, string cacheName, IProgress progress); void CancelLoadTiles(); } @@ -80,7 +80,7 @@ namespace MapControl /// Loads all pending tiles from the tiles collection. Tile image caching is enabled when the Cache /// property is not null and tileSource.UriFormat starts with "http" and cacheName is a non-empty string. /// - public void LoadTiles(IEnumerable tiles, TileSource tileSource, string cacheName, IProgress progress) + public void BeginLoadTiles(IEnumerable tiles, TileSource tileSource, string cacheName, IProgress progress) { if (Cache == null || tileSource.UriTemplate == null || !tileSource.UriTemplate.StartsWith("http")) { @@ -100,13 +100,15 @@ namespace MapControl Interlocked.Increment(ref taskCount); Logger?.LogDebug("Task count: {count}", taskCount); - _ = Task.Run(async () => - { - await LoadTilesFromStack(tileSource, cacheName, progress).ConfigureAwait(false); + _ = Task.Run(LoadTiles); + } - Interlocked.Decrement(ref taskCount); - Logger?.LogDebug("Task count: {count}", taskCount); - }); + async Task LoadTiles() + { + await LoadTilesFromStack(tileSource, cacheName, progress).ConfigureAwait(false); + + Interlocked.Decrement(ref taskCount); + Logger?.LogDebug("Task count: {count}", taskCount); } } diff --git a/MapControl/Shared/WmtsTileLayer.cs b/MapControl/Shared/WmtsTileLayer.cs index 779d78ed..8e6170dc 100644 --- a/MapControl/Shared/WmtsTileLayer.cs +++ b/MapControl/Shared/WmtsTileLayer.cs @@ -121,9 +121,7 @@ namespace MapControl cacheName += "/" + tileMatrixSet.Identifier.Replace(':', '_'); } - var tiles = ChildLayers.SelectMany(layer => layer.Tiles); - - LoadTiles(tiles, cacheName); + BeginLoadTiles(ChildLayers.SelectMany(layer => layer.Tiles), cacheName); } }