From dd738c85a4c0759a664cef87010e54b6341cda44 Mon Sep 17 00:00:00 2001 From: ClemensFischer Date: Fri, 17 Jan 2025 08:25:10 +0100 Subject: [PATCH] WmtsTileSource factory method --- MapControl/Shared/WmtsCapabilities.cs | 4 +- MapControl/Shared/WmtsTileLayer.cs | 49 +++++++++++------------- MapControl/WinUI/MapControl.WinUI.csproj | 1 - 3 files changed, 25 insertions(+), 29 deletions(-) diff --git a/MapControl/Shared/WmtsCapabilities.cs b/MapControl/Shared/WmtsCapabilities.cs index ab27ff2a..2c772a74 100644 --- a/MapControl/Shared/WmtsCapabilities.cs +++ b/MapControl/Shared/WmtsCapabilities.cs @@ -24,7 +24,7 @@ namespace MapControl private static readonly XNamespace xlink = "http://www.w3.org/1999/xlink"; public string Layer { get; private set; } - public WmtsTileSource TileSource { get; private set; } + public string UriTemplate { get; private set; } public List TileMatrixSets { get; private set; } public static async Task ReadCapabilitiesAsync(Uri capabilitiesUri, string layer) @@ -117,7 +117,7 @@ namespace MapControl return new WmtsCapabilities { Layer = layer, - TileSource = new WmtsTileSource { UriTemplate = urlTemplate }, + UriTemplate = urlTemplate, TileMatrixSets = tileMatrixSets }; } diff --git a/MapControl/Shared/WmtsTileLayer.cs b/MapControl/Shared/WmtsTileLayer.cs index 6f9d9912..32b56631 100644 --- a/MapControl/Shared/WmtsTileLayer.cs +++ b/MapControl/Shared/WmtsTileLayer.cs @@ -71,6 +71,8 @@ namespace MapControl public Dictionary TileMatrixSets { get; } = new Dictionary(); + protected virtual WmtsTileSource CreateTileSource(string uriTemplate) => new WmtsTileSource { UriTemplate = uriTemplate }; + protected override Size MeasureOverride(Size availableSize) { foreach (var layer in ChildLayers) @@ -104,7 +106,26 @@ namespace MapControl } else if (UpdateChildLayers(tileMatrixSet)) { - await LoadTiles(tileMatrixSet); + var cacheName = SourceName; + + if (TileSource is WmtsTileSource tileSource) + { + tileSource.TileMatrixSet = tileMatrixSet; + + if (!string.IsNullOrEmpty(cacheName)) + { + if (!string.IsNullOrEmpty(Layer)) + { + cacheName += "/" + Layer.Replace(':', '_'); + } + + cacheName += "/" + tileMatrixSet.Identifier.Replace(':', '_'); + } + } + + var tiles = ChildLayers.SelectMany(layer => layer.Tiles); + + await LoadTiles(tiles, cacheName); } } @@ -164,30 +185,6 @@ namespace MapControl return tilesChanged; } - private Task LoadTiles(WmtsTileMatrixSet tileMatrixSet) - { - var cacheName = SourceName; - - if (TileSource is WmtsTileSource tileSource) - { - tileSource.TileMatrixSet = tileMatrixSet; - - if (!string.IsNullOrEmpty(cacheName)) - { - if (!string.IsNullOrEmpty(Layer)) - { - cacheName += "/" + Layer.Replace(':', '_'); - } - - cacheName += "/" + tileMatrixSet.Identifier.Replace(':', '_'); - } - } - - var tiles = ChildLayers.SelectMany(layer => layer.Tiles); - - return LoadTiles(tiles, cacheName); - } - private async void OnLoaded(object sender, RoutedEventArgs e) { Loaded -= OnLoaded; @@ -206,7 +203,7 @@ namespace MapControl } Layer = capabilities.Layer; - TileSource = capabilities.TileSource; + TileSource = CreateTileSource(capabilities.UriTemplate); } catch (Exception ex) { diff --git a/MapControl/WinUI/MapControl.WinUI.csproj b/MapControl/WinUI/MapControl.WinUI.csproj index dec94bca..e1458837 100644 --- a/MapControl/WinUI/MapControl.WinUI.csproj +++ b/MapControl/WinUI/MapControl.WinUI.csproj @@ -2,7 +2,6 @@ net8.0-windows10.0.17763.0 win-x86;win-x64;win-arm64 - true true WINUI MapControl