mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Move UriTemplate to WmtsTileMatrixSet
This commit is contained in:
parent
baea814df0
commit
44d48eadde
|
|
@ -13,10 +13,11 @@ using Avalonia;
|
||||||
|
|
||||||
namespace MapControl
|
namespace MapControl
|
||||||
{
|
{
|
||||||
public class WmtsTileMatrixSet(string identifier, string supportedCrsId, IEnumerable<WmtsTileMatrix> tileMatrixes)
|
public class WmtsTileMatrixSet(string identifier, string supportedCrsId, string uriTemplate, IEnumerable<WmtsTileMatrix> tileMatrixes)
|
||||||
{
|
{
|
||||||
public string Identifier => identifier;
|
public string Identifier => identifier;
|
||||||
public string SupportedCrsId => supportedCrsId;
|
public string SupportedCrsId => supportedCrsId;
|
||||||
|
public string UriTemplate => uriTemplate;
|
||||||
public List<WmtsTileMatrix> TileMatrixes { get; } = tileMatrixes.OrderBy(m => m.Scale).ToList();
|
public List<WmtsTileMatrix> 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";
|
private static readonly XNamespace xlink = "http://www.w3.org/1999/xlink";
|
||||||
|
|
||||||
public string Layer { get; private set; }
|
public string Layer { get; private set; }
|
||||||
public string UriTemplate { get; private set; }
|
|
||||||
public List<WmtsTileMatrixSet> TileMatrixSets { get; private set; }
|
public List<WmtsTileMatrixSet> TileMatrixSets { get; private set; }
|
||||||
|
|
||||||
public static async Task<WmtsCapabilities> ReadCapabilitiesAsync(Uri uri, string layer)
|
public static async Task<WmtsCapabilities> ReadCapabilitiesAsync(Uri uri, string layer)
|
||||||
|
|
@ -113,13 +113,12 @@ namespace MapControl
|
||||||
.FirstOrDefault(s => s.Element(ows + "Identifier")?.Value == tileMatrixSetId) ??
|
.FirstOrDefault(s => s.Element(ows + "Identifier")?.Value == tileMatrixSetId) ??
|
||||||
throw new ArgumentException($"Linked TileMatrixSet element not found in Layer \"{layer}\".");
|
throw new ArgumentException($"Linked TileMatrixSet element not found in Layer \"{layer}\".");
|
||||||
|
|
||||||
tileMatrixSets.Add(ReadTileMatrixSet(tileMatrixSetElement));
|
tileMatrixSets.Add(ReadTileMatrixSet(tileMatrixSetElement, uriTemplate));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new WmtsCapabilities
|
return new WmtsCapabilities
|
||||||
{
|
{
|
||||||
Layer = layer,
|
Layer = layer,
|
||||||
UriTemplate = uriTemplate,
|
|
||||||
TileMatrixSets = tileMatrixSets
|
TileMatrixSets = tileMatrixSets
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -200,7 +199,7 @@ namespace MapControl
|
||||||
return uriTemplate;
|
return uriTemplate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static WmtsTileMatrixSet ReadTileMatrixSet(XElement tileMatrixSetElement)
|
public static WmtsTileMatrixSet ReadTileMatrixSet(XElement tileMatrixSetElement, string uriTemplate)
|
||||||
{
|
{
|
||||||
var identifier = tileMatrixSetElement.Element(ows + "Identifier")?.Value;
|
var identifier = tileMatrixSetElement.Element(ows + "Identifier")?.Value;
|
||||||
|
|
||||||
|
|
@ -237,7 +236,7 @@ namespace MapControl
|
||||||
throw new ArgumentException($"No TileMatrix elements found in TileMatrixSet \"{identifier}\".");
|
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)
|
public static WmtsTileMatrix ReadTileMatrix(XElement tileMatrixElement, string supportedCrs)
|
||||||
|
|
|
||||||
|
|
@ -28,9 +28,6 @@ namespace MapControl
|
||||||
public static readonly DependencyProperty CapabilitiesUriProperty =
|
public static readonly DependencyProperty CapabilitiesUriProperty =
|
||||||
DependencyPropertyHelper.Register<WmtsTileLayer, Uri>(nameof(CapabilitiesUri));
|
DependencyPropertyHelper.Register<WmtsTileLayer, Uri>(nameof(CapabilitiesUri));
|
||||||
|
|
||||||
public static readonly DependencyProperty UriTemplateProperty =
|
|
||||||
DependencyPropertyHelper.Register<WmtsTileLayer, string>(nameof(UriTemplate));
|
|
||||||
|
|
||||||
public static readonly DependencyProperty LayerProperty =
|
public static readonly DependencyProperty LayerProperty =
|
||||||
DependencyPropertyHelper.Register<WmtsTileLayer, string>(nameof(Layer));
|
DependencyPropertyHelper.Register<WmtsTileLayer, string>(nameof(Layer));
|
||||||
|
|
||||||
|
|
@ -51,19 +48,9 @@ namespace MapControl
|
||||||
set => SetValue(CapabilitiesUriProperty, value);
|
set => SetValue(CapabilitiesUriProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The Uri template string used for the UriTemplate property of WmtsTileSource instances.
|
|
||||||
/// Usually set internally from WmtsCapabilities requested by a Loaded event handler.
|
|
||||||
/// </summary>
|
|
||||||
public string UriTemplate
|
|
||||||
{
|
|
||||||
get => (string)GetValue(UriTemplateProperty);
|
|
||||||
set => SetValue(UriTemplateProperty, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The Identifier of the Layer that should be displayed.
|
/// 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.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Layer
|
public string Layer
|
||||||
{
|
{
|
||||||
|
|
@ -131,7 +118,7 @@ namespace MapControl
|
||||||
}
|
}
|
||||||
else if (UpdateChildLayers(tileMatrixSet.TileMatrixes))
|
else if (UpdateChildLayers(tileMatrixSet.TileMatrixes))
|
||||||
{
|
{
|
||||||
var tileSource = new WmtsTileSource(UriTemplate, tileMatrixSet);
|
var tileSource = new WmtsTileSource(tileMatrixSet);
|
||||||
var cacheName = SourceName;
|
var cacheName = SourceName;
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(cacheName))
|
if (!string.IsNullOrEmpty(cacheName))
|
||||||
|
|
@ -218,7 +205,6 @@ namespace MapControl
|
||||||
var capabilities = await WmtsCapabilities.ReadCapabilitiesAsync(CapabilitiesUri, Layer);
|
var capabilities = await WmtsCapabilities.ReadCapabilitiesAsync(CapabilitiesUri, Layer);
|
||||||
|
|
||||||
Layer = capabilities.Layer;
|
Layer = capabilities.Layer;
|
||||||
UriTemplate = capabilities.UriTemplate;
|
|
||||||
|
|
||||||
foreach (var tms in capabilities.TileMatrixSets
|
foreach (var tms in capabilities.TileMatrixSets
|
||||||
.Where(tms => !TileMatrixSets.ContainsKey(tms.SupportedCrsId) ||
|
.Where(tms => !TileMatrixSets.ContainsKey(tms.SupportedCrsId) ||
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,11 @@ namespace MapControl
|
||||||
{
|
{
|
||||||
public class WmtsTileSource : UriTileSource
|
public class WmtsTileSource : UriTileSource
|
||||||
{
|
{
|
||||||
private readonly IList<WmtsTileMatrix> tileMatrixes;
|
private readonly List<WmtsTileMatrix> tileMatrixes;
|
||||||
|
|
||||||
public WmtsTileSource(string uriTemplate, WmtsTileMatrixSet tileMatrixSet)
|
public WmtsTileSource(WmtsTileMatrixSet tileMatrixSet)
|
||||||
{
|
{
|
||||||
UriTemplate = uriTemplate.Replace("{TileMatrixSet}", tileMatrixSet.Identifier);
|
UriTemplate = tileMatrixSet.UriTemplate;
|
||||||
tileMatrixes = tileMatrixSet.TileMatrixes;
|
tileMatrixes = tileMatrixSet.TileMatrixes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue