diff --git a/MapControl/Shared/WmtsCapabilities.cs b/MapControl/Shared/WmtsCapabilities.cs index 9e152a7e..f11baf30 100644 --- a/MapControl/Shared/WmtsCapabilities.cs +++ b/MapControl/Shared/WmtsCapabilities.cs @@ -13,10 +13,11 @@ using Avalonia; namespace MapControl { - public class WmtsTileMatrixSet(string identifier, string supportedCrsId, IEnumerable tileMatrixes) + public class WmtsTileMatrixSet(string identifier, string supportedCrsId, string uriTemplate, IEnumerable tileMatrixes) { public string Identifier => identifier; public string SupportedCrsId => supportedCrsId; + public string UriTemplate => uriTemplate; public List TileMatrixes { get; } = tileMatrixes.OrderBy(m => m.Scale).ToList(); } @@ -30,7 +31,6 @@ namespace MapControl private static readonly XNamespace xlink = "http://www.w3.org/1999/xlink"; public string Layer { get; private set; } - public string UriTemplate { get; private set; } public List TileMatrixSets { get; private set; } public static async Task ReadCapabilitiesAsync(Uri uri, string layer) @@ -113,13 +113,12 @@ namespace MapControl .FirstOrDefault(s => s.Element(ows + "Identifier")?.Value == tileMatrixSetId) ?? throw new ArgumentException($"Linked TileMatrixSet element not found in Layer \"{layer}\"."); - tileMatrixSets.Add(ReadTileMatrixSet(tileMatrixSetElement)); + tileMatrixSets.Add(ReadTileMatrixSet(tileMatrixSetElement, uriTemplate)); } return new WmtsCapabilities { Layer = layer, - UriTemplate = uriTemplate, TileMatrixSets = tileMatrixSets }; } @@ -200,7 +199,7 @@ namespace MapControl return uriTemplate; } - public static WmtsTileMatrixSet ReadTileMatrixSet(XElement tileMatrixSetElement) + public static WmtsTileMatrixSet ReadTileMatrixSet(XElement tileMatrixSetElement, string uriTemplate) { var identifier = tileMatrixSetElement.Element(ows + "Identifier")?.Value; @@ -237,7 +236,7 @@ namespace MapControl throw new ArgumentException($"No TileMatrix elements found in TileMatrixSet \"{identifier}\"."); } - return new WmtsTileMatrixSet(identifier, supportedCrs, tileMatrixes); + return new WmtsTileMatrixSet(identifier, supportedCrs, uriTemplate.Replace("{TileMatrixSet}", identifier), tileMatrixes); } public static WmtsTileMatrix ReadTileMatrix(XElement tileMatrixElement, string supportedCrs) diff --git a/MapControl/Shared/WmtsTileLayer.cs b/MapControl/Shared/WmtsTileLayer.cs index 03bd3fbd..569a86d0 100644 --- a/MapControl/Shared/WmtsTileLayer.cs +++ b/MapControl/Shared/WmtsTileLayer.cs @@ -28,9 +28,6 @@ namespace MapControl public static readonly DependencyProperty CapabilitiesUriProperty = DependencyPropertyHelper.Register(nameof(CapabilitiesUri)); - public static readonly DependencyProperty UriTemplateProperty = - DependencyPropertyHelper.Register(nameof(UriTemplate)); - public static readonly DependencyProperty LayerProperty = DependencyPropertyHelper.Register(nameof(Layer)); @@ -51,19 +48,9 @@ namespace MapControl set => SetValue(CapabilitiesUriProperty, value); } - /// - /// The Uri template string used for the UriTemplate property of WmtsTileSource instances. - /// Usually set internally from WmtsCapabilities requested by a Loaded event handler. - /// - public string UriTemplate - { - get => (string)GetValue(UriTemplateProperty); - set => SetValue(UriTemplateProperty, value); - } - /// /// The Identifier of the Layer that should be displayed. - /// If not set, the value is defined by WmtsCapabilities. + /// If not set, the first Layer defined in WMTS Capabilities is displayed. /// public string Layer { @@ -131,7 +118,7 @@ namespace MapControl } else if (UpdateChildLayers(tileMatrixSet.TileMatrixes)) { - var tileSource = new WmtsTileSource(UriTemplate, tileMatrixSet); + var tileSource = new WmtsTileSource(tileMatrixSet); var cacheName = SourceName; if (!string.IsNullOrEmpty(cacheName)) @@ -218,7 +205,6 @@ namespace MapControl var capabilities = await WmtsCapabilities.ReadCapabilitiesAsync(CapabilitiesUri, Layer); Layer = capabilities.Layer; - UriTemplate = capabilities.UriTemplate; foreach (var tms in capabilities.TileMatrixSets .Where(tms => !TileMatrixSets.ContainsKey(tms.SupportedCrsId) || diff --git a/MapControl/Shared/WmtsTileSource.cs b/MapControl/Shared/WmtsTileSource.cs index 985917c3..3fb372c0 100644 --- a/MapControl/Shared/WmtsTileSource.cs +++ b/MapControl/Shared/WmtsTileSource.cs @@ -6,11 +6,11 @@ namespace MapControl { public class WmtsTileSource : UriTileSource { - private readonly IList tileMatrixes; + private readonly List tileMatrixes; - public WmtsTileSource(string uriTemplate, WmtsTileMatrixSet tileMatrixSet) + public WmtsTileSource(WmtsTileMatrixSet tileMatrixSet) { - UriTemplate = uriTemplate.Replace("{TileMatrixSet}", tileMatrixSet.Identifier); + UriTemplate = tileMatrixSet.UriTemplate; tileMatrixes = tileMatrixSet.TileMatrixes; }