From 407f786640d58feff8398629031b553cb9b81186 Mon Sep 17 00:00:00 2001 From: ClemensFischer Date: Mon, 18 Aug 2025 22:23:19 +0200 Subject: [PATCH] MapTileLayer implementation --- MapControl/Shared/MapTileLayer.cs | 29 +++++++++------------------ MapControl/Shared/MapTileLayerBase.cs | 6 +++--- MapControl/Shared/TileImageLoader.cs | 4 ++-- MapControl/Shared/WmtsTileLayer.cs | 4 ++-- 4 files changed, 17 insertions(+), 26 deletions(-) diff --git a/MapControl/Shared/MapTileLayer.cs b/MapControl/Shared/MapTileLayer.cs index 232a47e6..7eb3c7b3 100644 --- a/MapControl/Shared/MapTileLayer.cs +++ b/MapControl/Shared/MapTileLayer.cs @@ -109,33 +109,24 @@ namespace MapControl return finalSize; } - protected override async Task UpdateTileLayerAsync(bool tileSourceChanged) + protected override async Task UpdateTileLayerAsync(bool resetTiles) { - var updateTiles = false; - if (ParentMap == null || ParentMap.MapProjection.Type != MapProjectionType.WebMercator) { - updateTiles = TileMatrix != null; TileMatrix = null; + Children.Clear(); + + await LoadTilesAsync(null, null); // stop TileImageLoader } - else + else if (SetTileMatrix() || resetTiles) { - if (tileSourceChanged) - { - Tiles = new TileCollection(); // clear all - updateTiles = true; - } - - if (SetTileMatrix()) - { - updateTiles = true; - } - SetRenderTransform(); - } - if (updateTiles) - { + if (resetTiles) + { + Tiles.Clear(); + } + UpdateTiles(); await LoadTilesAsync(Tiles, SourceName); diff --git a/MapControl/Shared/MapTileLayerBase.cs b/MapControl/Shared/MapTileLayerBase.cs index f04621b2..26fbc784 100644 --- a/MapControl/Shared/MapTileLayerBase.cs +++ b/MapControl/Shared/MapTileLayerBase.cs @@ -194,13 +194,13 @@ namespace MapControl protected abstract void SetRenderTransform(); - protected abstract Task UpdateTileLayerAsync(bool tileSourceChanged); + protected abstract Task UpdateTileLayerAsync(bool resetTiles); - private Task UpdateTileLayer(bool tileSourceChanged) + private Task UpdateTileLayer(bool resetTiles) { updateTimer.Stop(); - return UpdateTileLayerAsync(tileSourceChanged); + return UpdateTileLayerAsync(resetTiles); } private async void OnViewportChanged(object sender, ViewportChangedEventArgs e) diff --git a/MapControl/Shared/TileImageLoader.cs b/MapControl/Shared/TileImageLoader.cs index 64eb7f0c..57eb2ce0 100644 --- a/MapControl/Shared/TileImageLoader.cs +++ b/MapControl/Shared/TileImageLoader.cs @@ -79,9 +79,9 @@ namespace MapControl { pendingTiles?.Clear(); - if (tiles != null && tileSource != null) + if (tileSource != null && tiles != null && (tiles = tiles.Where(tile => tile.IsPending)).Any()) { - pendingTiles = new ConcurrentStack(tiles.Where(tile => tile.IsPending).Reverse()); + pendingTiles = new ConcurrentStack(tiles.Reverse()); var tileCount = pendingTiles.Count; var taskCount = Math.Min(tileCount, MaxLoadTasks); diff --git a/MapControl/Shared/WmtsTileLayer.cs b/MapControl/Shared/WmtsTileLayer.cs index 3d8a7a51..131b4404 100644 --- a/MapControl/Shared/WmtsTileLayer.cs +++ b/MapControl/Shared/WmtsTileLayer.cs @@ -89,9 +89,9 @@ namespace MapControl return finalSize; } - protected override async Task UpdateTileLayerAsync(bool tileSourceChanged) + protected override async Task UpdateTileLayerAsync(bool resetTiles) { - // tileSourceChanged is ignored here because it is always false. + // resetTiles is ignored here because it is always false. if (ParentMap == null || !TileMatrixSets.TryGetValue(ParentMap.MapProjection.CrsId, out WmtsTileMatrixSet tileMatrixSet))