Compare commits

...

4 commits

Author SHA1 Message Date
ClemensFischer ab1695b107 Updated WmtsTileLayer 2025-12-01 19:55:04 +01:00
ClemensFischer 90cc3621bb Updated WmtsTileSource 2025-12-01 18:46:03 +01:00
ClemensFischer 7263e9e1e4 Updated WmtsTileSource 2025-12-01 14:01:35 +01:00
ClemensFischer a223c32466 Updated WmtsTileLayer 2025-12-01 13:59:18 +01:00
2 changed files with 15 additions and 17 deletions

View file

@ -28,8 +28,8 @@ namespace MapControl
public static readonly DependencyProperty CapabilitiesUriProperty =
DependencyPropertyHelper.Register<WmtsTileLayer, Uri>(nameof(CapabilitiesUri));
public static readonly DependencyProperty TileUriTemplateProperty =
DependencyPropertyHelper.Register<WmtsTileLayer, string>(nameof(TileUriTemplate));
public static readonly DependencyProperty UriTemplateProperty =
DependencyPropertyHelper.Register<WmtsTileLayer, string>(nameof(UriTemplate));
public static readonly DependencyProperty LayerProperty =
DependencyPropertyHelper.Register<WmtsTileLayer, string>(nameof(Layer));
@ -55,10 +55,10 @@ namespace MapControl
/// 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 TileUriTemplate
public string UriTemplate
{
get => (string)GetValue(TileUriTemplateProperty);
set => SetValue(TileUriTemplateProperty, value);
get => (string)GetValue(UriTemplateProperty);
set => SetValue(UriTemplateProperty, value);
}
/// <summary>
@ -129,9 +129,9 @@ namespace MapControl
Children.Clear();
CancelLoadTiles();
}
else if (UpdateChildLayers(tileMatrixSet))
else if (UpdateChildLayers(tileMatrixSet.TileMatrixes))
{
var tileSource = new WmtsTileSource(tileMatrixSet, TileUriTemplate);
var tileSource = new WmtsTileSource(UriTemplate, tileMatrixSet);
var cacheName = SourceName;
if (!string.IsNullOrEmpty(cacheName))
@ -151,13 +151,13 @@ namespace MapControl
}
}
private bool UpdateChildLayers(WmtsTileMatrixSet tileMatrixSet)
private bool UpdateChildLayers(IList<WmtsTileMatrix> tileMatrixSet)
{
// Multiply scale by 1.001 to avoid floating point precision issues
// and get all WmtsTileMatrixes with Scale <= maxScale.
//
var maxScale = 1.001 * ParentMap.ViewTransform.Scale;
var tileMatrixes = tileMatrixSet.TileMatrixes.Where(matrix => matrix.Scale <= maxScale).ToList();
var tileMatrixes = tileMatrixSet.Where(matrix => matrix.Scale <= maxScale).ToList();
if (tileMatrixes.Count == 0)
{
@ -189,10 +189,10 @@ namespace MapControl
foreach (var tileMatrix in tileMatrixes)
{
// Pass index of tileMatrix in tileMatrixSet.TileMatrixes as zoom level to WmtsTileMatrixLayer ctor.
// Pass index of tileMatrix in tileMatrixSet as zoom level to WmtsTileMatrixLayer ctor.
//
var layer = layers.FirstOrDefault(layer => layer.WmtsTileMatrix == tileMatrix) ??
new WmtsTileMatrixLayer(tileMatrix, tileMatrixSet.TileMatrixes.IndexOf(tileMatrix));
new WmtsTileMatrixLayer(tileMatrix, tileMatrixSet.IndexOf(tileMatrix));
if (layer.UpdateTiles(ParentMap.ViewTransform, ParentMap.ActualWidth, ParentMap.ActualHeight))
{
@ -226,7 +226,7 @@ namespace MapControl
}
Layer = capabilities.Layer;
TileUriTemplate = capabilities.UriTemplate;
UriTemplate = capabilities.UriTemplate;
UpdateTileCollection();
}

View file

@ -8,19 +8,17 @@ namespace MapControl
{
private readonly IList<WmtsTileMatrix> tileMatrixes;
public WmtsTileSource(WmtsTileMatrixSet tileMatrixSet, string uriTemplate)
public WmtsTileSource(string uriTemplate, WmtsTileMatrixSet tileMatrixSet)
{
tileMatrixes = tileMatrixSet.TileMatrixes;
UriTemplate = uriTemplate.Replace("{TileMatrixSet}", tileMatrixSet.Identifier);
tileMatrixes = tileMatrixSet.TileMatrixes;
}
public override Uri GetUri(int zoomLevel, int column, int row)
{
Uri uri = null;
if (UriTemplate != null &&
tileMatrixes != null &&
tileMatrixes.Count > zoomLevel)
if (zoomLevel < tileMatrixes.Count)
{
var uriBuilder = new StringBuilder(UriTemplate);