2025-02-27 18:46:32 +01:00
|
|
|
|
using System;
|
2020-04-15 20:46:16 +02:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Globalization;
|
2025-09-19 11:53:25 +02:00
|
|
|
|
using System.IO;
|
2020-04-15 20:46:16 +02:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Threading.Tasks;
|
2022-08-23 17:20:16 +02:00
|
|
|
|
using System.Xml.Linq;
|
2024-05-22 11:25:32 +02:00
|
|
|
|
#if WPF
|
2020-04-15 20:46:16 +02:00
|
|
|
|
using System.Windows;
|
2025-08-19 19:43:02 +02:00
|
|
|
|
#elif AVALONIA
|
|
|
|
|
|
using Avalonia;
|
2020-04-15 20:46:16 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
namespace MapControl
|
|
|
|
|
|
{
|
2022-08-22 22:09:49 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// For reference see https://www.ogc.org/standards/wmts, 07-057r7_Web_Map_Tile_Service_Standard.pdf
|
|
|
|
|
|
/// </summary>
|
2020-04-15 20:46:16 +02:00
|
|
|
|
public class WmtsCapabilities
|
|
|
|
|
|
{
|
2022-08-23 17:20:16 +02:00
|
|
|
|
private static readonly XNamespace ows = "http://www.opengis.net/ows/1.1";
|
|
|
|
|
|
private static readonly XNamespace wmts = "http://www.opengis.net/wmts/1.0";
|
|
|
|
|
|
private static readonly XNamespace xlink = "http://www.w3.org/1999/xlink";
|
|
|
|
|
|
|
2023-03-07 17:54:11 +01:00
|
|
|
|
public string Layer { get; private set; }
|
2025-10-29 18:59:19 +01:00
|
|
|
|
public string UriTemplate { get; private set; }
|
2020-04-15 20:46:16 +02:00
|
|
|
|
public List<WmtsTileMatrixSet> TileMatrixSets { get; private set; }
|
|
|
|
|
|
|
2025-09-19 11:53:25 +02:00
|
|
|
|
public static async Task<WmtsCapabilities> ReadCapabilitiesAsync(Uri uri, string layer)
|
2020-04-15 20:46:16 +02:00
|
|
|
|
{
|
2025-09-19 11:53:25 +02:00
|
|
|
|
Stream xmlStream;
|
2025-10-29 18:59:19 +01:00
|
|
|
|
string defaultUri = null;
|
2020-04-15 20:46:16 +02:00
|
|
|
|
|
2025-09-19 14:06:23 +02:00
|
|
|
|
if (!uri.IsAbsoluteUri)
|
|
|
|
|
|
{
|
|
|
|
|
|
xmlStream = File.OpenRead(uri.OriginalString);
|
|
|
|
|
|
}
|
2025-10-29 18:59:19 +01:00
|
|
|
|
else if (uri.IsFile)
|
|
|
|
|
|
{
|
|
|
|
|
|
xmlStream = File.OpenRead(uri.LocalPath);
|
|
|
|
|
|
}
|
2025-09-19 14:06:23 +02:00
|
|
|
|
else if (uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps)
|
2020-04-15 20:46:16 +02:00
|
|
|
|
{
|
2025-10-29 18:59:19 +01:00
|
|
|
|
defaultUri = uri.OriginalString.Split('?')[0];
|
2025-09-14 21:02:21 +02:00
|
|
|
|
|
2025-09-19 11:53:25 +02:00
|
|
|
|
xmlStream = await ImageLoader.HttpClient.GetStreamAsync(uri);
|
2020-04-15 20:46:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2025-11-28 23:22:10 +01:00
|
|
|
|
throw new ArgumentException($"Invalid Capabilities Uri: {uri}");
|
2020-04-15 20:46:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-19 11:53:25 +02:00
|
|
|
|
using var stream = xmlStream;
|
|
|
|
|
|
|
|
|
|
|
|
var element = await XDocument.LoadRootElementAsync(stream);
|
|
|
|
|
|
|
2025-10-29 18:59:19 +01:00
|
|
|
|
return ReadCapabilities(element, layer, defaultUri);
|
2020-04-15 20:46:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-29 18:59:19 +01:00
|
|
|
|
public static WmtsCapabilities ReadCapabilities(XElement capabilitiesElement, string layer, string defaultUri)
|
2020-04-15 20:46:16 +02:00
|
|
|
|
{
|
2025-09-14 21:57:19 +02:00
|
|
|
|
var contentsElement = capabilitiesElement.Element(wmts + "Contents") ??
|
|
|
|
|
|
throw new ArgumentException("Contents element not found.");
|
2020-04-15 20:46:16 +02:00
|
|
|
|
|
|
|
|
|
|
XElement layerElement;
|
|
|
|
|
|
|
2023-03-07 17:54:11 +01:00
|
|
|
|
if (!string.IsNullOrEmpty(layer))
|
2020-04-15 20:46:16 +02:00
|
|
|
|
{
|
2022-09-01 17:32:43 +02:00
|
|
|
|
layerElement = contentsElement
|
|
|
|
|
|
.Elements(wmts + "Layer")
|
2025-10-29 18:59:19 +01:00
|
|
|
|
.FirstOrDefault(l => l.Element(ows + "Identifier")?.Value == layer) ??
|
2023-03-07 17:54:11 +01:00
|
|
|
|
throw new ArgumentException($"Layer element \"{layer}\" not found.");
|
2020-04-15 20:46:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2022-09-01 17:32:43 +02:00
|
|
|
|
layerElement = contentsElement
|
|
|
|
|
|
.Elements(wmts + "Layer")
|
2025-10-29 18:59:19 +01:00
|
|
|
|
.FirstOrDefault() ??
|
2020-04-15 20:46:16 +02:00
|
|
|
|
throw new ArgumentException("No Layer element found.");
|
|
|
|
|
|
|
2023-03-07 17:54:11 +01:00
|
|
|
|
layer = layerElement.Element(ows + "Identifier")?.Value ?? "";
|
2020-04-15 20:46:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-09-01 17:32:43 +02:00
|
|
|
|
var styleElement = layerElement
|
|
|
|
|
|
.Elements(wmts + "Style")
|
2025-09-14 21:57:19 +02:00
|
|
|
|
.FirstOrDefault(s => s.Attribute("isDefault")?.Value == "true") ??
|
|
|
|
|
|
layerElement
|
2024-07-12 18:42:18 +02:00
|
|
|
|
.Elements(wmts + "Style")
|
|
|
|
|
|
.FirstOrDefault();
|
2020-04-15 20:46:16 +02:00
|
|
|
|
|
2024-07-12 20:46:35 +02:00
|
|
|
|
var style = styleElement?.Element(ows + "Identifier")?.Value ?? "";
|
2020-04-15 20:46:16 +02:00
|
|
|
|
|
2025-10-29 18:59:19 +01:00
|
|
|
|
var uriTemplate = ReadUriTemplate(capabilitiesElement, layerElement, layer, style, defaultUri);
|
2020-11-03 13:27:50 +01:00
|
|
|
|
|
2020-04-15 20:46:16 +02:00
|
|
|
|
var tileMatrixSetIds = layerElement
|
2022-08-23 17:20:16 +02:00
|
|
|
|
.Elements(wmts + "TileMatrixSetLink")
|
2023-03-07 17:54:11 +01:00
|
|
|
|
.Select(l => l.Element(wmts + "TileMatrixSet")?.Value)
|
|
|
|
|
|
.Where(v => !string.IsNullOrEmpty(v));
|
2020-04-15 20:46:16 +02:00
|
|
|
|
|
|
|
|
|
|
var tileMatrixSets = new List<WmtsTileMatrixSet>();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var tileMatrixSetId in tileMatrixSetIds)
|
|
|
|
|
|
{
|
2022-09-01 17:32:43 +02:00
|
|
|
|
var tileMatrixSetElement = contentsElement
|
|
|
|
|
|
.Elements(wmts + "TileMatrixSet")
|
2025-09-14 21:57:19 +02:00
|
|
|
|
.FirstOrDefault(s => s.Element(ows + "Identifier")?.Value == tileMatrixSetId) ??
|
|
|
|
|
|
throw new ArgumentException($"Linked TileMatrixSet element not found in Layer \"{layer}\".");
|
2020-04-15 20:46:16 +02:00
|
|
|
|
|
2020-11-03 13:27:50 +01:00
|
|
|
|
tileMatrixSets.Add(ReadTileMatrixSet(tileMatrixSetElement));
|
2020-04-15 20:46:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return new WmtsCapabilities
|
|
|
|
|
|
{
|
2023-03-07 17:54:11 +01:00
|
|
|
|
Layer = layer,
|
2025-10-29 18:59:19 +01:00
|
|
|
|
UriTemplate = uriTemplate,
|
2020-04-15 20:46:16 +02:00
|
|
|
|
TileMatrixSets = tileMatrixSets
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-29 18:59:19 +01:00
|
|
|
|
public static string ReadUriTemplate(XElement capabilitiesElement, XElement layerElement, string layer, string style, string defaultUri)
|
2020-11-03 12:47:50 +01:00
|
|
|
|
{
|
|
|
|
|
|
const string formatPng = "image/png";
|
|
|
|
|
|
const string formatJpg = "image/jpeg";
|
2025-10-29 18:59:19 +01:00
|
|
|
|
string uriTemplate = null;
|
2020-11-03 12:47:50 +01:00
|
|
|
|
|
2022-09-01 17:32:43 +02:00
|
|
|
|
var resourceUrls = layerElement
|
|
|
|
|
|
.Elements(wmts + "ResourceURL")
|
2023-03-07 17:54:11 +01:00
|
|
|
|
.Where(r => r.Attribute("resourceType")?.Value == "tile" &&
|
|
|
|
|
|
r.Attribute("format")?.Value != null &&
|
|
|
|
|
|
r.Attribute("template")?.Value != null)
|
|
|
|
|
|
.ToLookup(r => r.Attribute("format").Value,
|
|
|
|
|
|
r => r.Attribute("template").Value);
|
2020-11-03 12:47:50 +01:00
|
|
|
|
|
2025-09-14 21:02:21 +02:00
|
|
|
|
if (resourceUrls.Count != 0)
|
2020-11-03 12:47:50 +01:00
|
|
|
|
{
|
2025-10-29 18:59:19 +01:00
|
|
|
|
var uriTemplates = resourceUrls.Contains(formatPng) ? resourceUrls[formatPng]
|
2022-08-22 21:13:45 +02:00
|
|
|
|
: resourceUrls.Contains(formatJpg) ? resourceUrls[formatJpg]
|
|
|
|
|
|
: resourceUrls.First();
|
2020-11-03 12:47:50 +01:00
|
|
|
|
|
2025-10-29 18:59:19 +01:00
|
|
|
|
uriTemplate = uriTemplates.First().Replace("{Style}", style);
|
2020-11-03 12:47:50 +01:00
|
|
|
|
}
|
2022-08-23 17:20:16 +02:00
|
|
|
|
else
|
2020-11-03 12:47:50 +01:00
|
|
|
|
{
|
2025-10-29 18:59:19 +01:00
|
|
|
|
uriTemplate = capabilitiesElement
|
2022-08-23 17:20:16 +02:00
|
|
|
|
.Elements(ows + "OperationsMetadata")
|
2022-09-01 17:32:43 +02:00
|
|
|
|
.Elements(ows + "Operation")
|
2023-03-07 17:54:11 +01:00
|
|
|
|
.Where(o => o.Attribute("name")?.Value == "GetTile")
|
2022-08-23 17:20:16 +02:00
|
|
|
|
.Elements(ows + "DCP")
|
|
|
|
|
|
.Elements(ows + "HTTP")
|
2022-09-01 17:32:43 +02:00
|
|
|
|
.Elements(ows + "Get")
|
2023-03-07 17:54:11 +01:00
|
|
|
|
.Where(g => g.Elements(ows + "Constraint")
|
|
|
|
|
|
.Any(con => con.Attribute("name")?.Value == "GetEncoding" &&
|
|
|
|
|
|
con.Element(ows + "AllowedValues")?.Element(ows + "Value")?.Value == "KVP"))
|
|
|
|
|
|
.Select(g => g.Attribute(xlink + "href")?.Value)
|
|
|
|
|
|
.Where(h => !string.IsNullOrEmpty(h))
|
|
|
|
|
|
.Select(h => h.Split('?')[0])
|
2025-09-19 11:53:25 +02:00
|
|
|
|
.FirstOrDefault() ??
|
2025-10-29 18:59:19 +01:00
|
|
|
|
defaultUri;
|
2022-08-22 21:13:45 +02:00
|
|
|
|
|
2025-10-29 18:59:19 +01:00
|
|
|
|
if (uriTemplate != null)
|
2022-08-23 17:20:16 +02:00
|
|
|
|
{
|
2022-09-01 17:32:43 +02:00
|
|
|
|
var formats = layerElement
|
|
|
|
|
|
.Elements(wmts + "Format")
|
2023-03-07 17:54:11 +01:00
|
|
|
|
.Select(f => f.Value);
|
2022-09-01 17:32:43 +02:00
|
|
|
|
|
2022-08-23 17:20:16 +02:00
|
|
|
|
var format = formats.Contains(formatPng) ? formatPng
|
|
|
|
|
|
: formats.Contains(formatJpg) ? formatJpg
|
|
|
|
|
|
: formats.FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(format))
|
|
|
|
|
|
{
|
|
|
|
|
|
format = formatPng;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-29 18:59:19 +01:00
|
|
|
|
uriTemplate += "?Service=WMTS"
|
2022-09-01 17:32:43 +02:00
|
|
|
|
+ "&Request=GetTile"
|
|
|
|
|
|
+ "&Version=1.0.0"
|
2023-03-07 17:54:11 +01:00
|
|
|
|
+ "&Layer=" + layer
|
|
|
|
|
|
+ "&Style=" + style
|
2022-09-01 17:32:43 +02:00
|
|
|
|
+ "&Format=" + format
|
|
|
|
|
|
+ "&TileMatrixSet={TileMatrixSet}"
|
|
|
|
|
|
+ "&TileMatrix={TileMatrix}"
|
|
|
|
|
|
+ "&TileRow={TileRow}"
|
|
|
|
|
|
+ "&TileCol={TileCol}";
|
2022-08-23 17:20:16 +02:00
|
|
|
|
}
|
2020-11-03 12:47:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-29 18:59:19 +01:00
|
|
|
|
if (string.IsNullOrEmpty(uriTemplate))
|
2020-11-03 12:47:50 +01:00
|
|
|
|
{
|
2023-03-07 17:54:11 +01:00
|
|
|
|
throw new ArgumentException($"No ResourceURL element in Layer \"{layer}\" and no GetTile KVP Operation Metadata found.");
|
2020-11-03 12:47:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-29 18:59:19 +01:00
|
|
|
|
return uriTemplate;
|
2020-11-03 12:47:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-15 20:46:16 +02:00
|
|
|
|
public static WmtsTileMatrixSet ReadTileMatrixSet(XElement tileMatrixSetElement)
|
|
|
|
|
|
{
|
|
|
|
|
|
var identifier = tileMatrixSetElement.Element(ows + "Identifier")?.Value;
|
|
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(identifier))
|
|
|
|
|
|
{
|
2022-08-23 17:20:16 +02:00
|
|
|
|
throw new ArgumentException("No Identifier element found in TileMatrixSet.");
|
2020-04-15 20:46:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var supportedCrs = tileMatrixSetElement.Element(ows + "SupportedCRS")?.Value;
|
|
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(supportedCrs))
|
|
|
|
|
|
{
|
2022-08-23 17:20:16 +02:00
|
|
|
|
throw new ArgumentException($"No SupportedCRS element found in TileMatrixSet \"{identifier}\".");
|
2020-04-15 20:46:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-13 11:02:29 +01:00
|
|
|
|
const string urnPrefix = "urn:ogc:def:crs:";
|
2022-08-12 13:38:15 +02:00
|
|
|
|
|
|
|
|
|
|
if (supportedCrs.StartsWith(urnPrefix)) // e.g. "urn:ogc:def:crs:EPSG:6.18:3857")
|
2022-08-03 18:01:02 +02:00
|
|
|
|
{
|
2025-02-13 11:02:29 +01:00
|
|
|
|
var crsComponents = supportedCrs.Substring(urnPrefix.Length).Split(':');
|
|
|
|
|
|
|
|
|
|
|
|
supportedCrs = crsComponents.First() + ":" + crsComponents.Last();
|
2022-08-03 18:01:02 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-15 20:46:16 +02:00
|
|
|
|
var tileMatrixes = new List<WmtsTileMatrix>();
|
|
|
|
|
|
|
2022-08-23 17:20:16 +02:00
|
|
|
|
foreach (var tileMatrixElement in tileMatrixSetElement.Elements(wmts + "TileMatrix"))
|
2020-04-15 20:46:16 +02:00
|
|
|
|
{
|
2020-06-19 00:00:32 +02:00
|
|
|
|
tileMatrixes.Add(ReadTileMatrix(tileMatrixElement, supportedCrs));
|
2020-04-15 20:46:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (tileMatrixes.Count <= 0)
|
|
|
|
|
|
{
|
2022-01-20 22:15:43 +01:00
|
|
|
|
throw new ArgumentException($"No TileMatrix elements found in TileMatrixSet \"{identifier}\".");
|
2020-04-15 20:46:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return new WmtsTileMatrixSet(identifier, supportedCrs, tileMatrixes);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-19 00:00:32 +02:00
|
|
|
|
public static WmtsTileMatrix ReadTileMatrix(XElement tileMatrixElement, string supportedCrs)
|
2020-04-15 20:46:16 +02:00
|
|
|
|
{
|
|
|
|
|
|
var identifier = tileMatrixElement.Element(ows + "Identifier")?.Value;
|
|
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(identifier))
|
|
|
|
|
|
{
|
2022-08-23 17:20:16 +02:00
|
|
|
|
throw new ArgumentException("No Identifier element found in TileMatrix.");
|
2020-04-15 20:46:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-08-23 17:20:16 +02:00
|
|
|
|
var valueString = tileMatrixElement.Element(wmts + "ScaleDenominator")?.Value;
|
2020-04-15 20:46:16 +02:00
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(valueString) ||
|
2020-04-16 19:24:38 +02:00
|
|
|
|
!double.TryParse(valueString, NumberStyles.Float, CultureInfo.InvariantCulture, out double scaleDenominator))
|
2020-04-15 20:46:16 +02:00
|
|
|
|
{
|
2022-01-20 22:15:43 +01:00
|
|
|
|
throw new ArgumentException($"No ScaleDenominator element found in TileMatrix \"{identifier}\".");
|
2020-04-15 20:46:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-08-23 17:20:16 +02:00
|
|
|
|
valueString = tileMatrixElement.Element(wmts + "TopLeftCorner")?.Value;
|
2020-04-16 19:24:38 +02:00
|
|
|
|
string[] topLeftCornerStrings;
|
2020-04-15 20:46:16 +02:00
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(valueString) ||
|
2025-09-19 11:53:25 +02:00
|
|
|
|
(topLeftCornerStrings = valueString.Split([' '], StringSplitOptions.RemoveEmptyEntries)).Length < 2 ||
|
2020-04-16 19:24:38 +02:00
|
|
|
|
!double.TryParse(topLeftCornerStrings[0], NumberStyles.Float, CultureInfo.InvariantCulture, out double left) ||
|
|
|
|
|
|
!double.TryParse(topLeftCornerStrings[1], NumberStyles.Float, CultureInfo.InvariantCulture, out double top))
|
2020-04-15 20:46:16 +02:00
|
|
|
|
{
|
2022-01-20 22:15:43 +01:00
|
|
|
|
throw new ArgumentException($"No TopLeftCorner element found in TileMatrix \"{identifier}\".");
|
2020-04-15 20:46:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-08-23 17:20:16 +02:00
|
|
|
|
valueString = tileMatrixElement.Element(wmts + "TileWidth")?.Value;
|
2020-04-15 20:46:16 +02:00
|
|
|
|
|
2020-04-16 19:24:38 +02:00
|
|
|
|
if (string.IsNullOrEmpty(valueString) || !int.TryParse(valueString, out int tileWidth))
|
2020-04-15 20:46:16 +02:00
|
|
|
|
{
|
2022-01-20 22:15:43 +01:00
|
|
|
|
throw new ArgumentException($"No TileWidth element found in TileMatrix \"{identifier}\".");
|
2020-04-15 20:46:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-08-23 17:20:16 +02:00
|
|
|
|
valueString = tileMatrixElement.Element(wmts + "TileHeight")?.Value;
|
2020-04-15 20:46:16 +02:00
|
|
|
|
|
2020-04-16 19:24:38 +02:00
|
|
|
|
if (string.IsNullOrEmpty(valueString) || !int.TryParse(valueString, out int tileHeight))
|
2020-04-15 20:46:16 +02:00
|
|
|
|
{
|
2022-01-20 22:15:43 +01:00
|
|
|
|
throw new ArgumentException($"No TileHeight element found in TileMatrix \"{identifier}\".");
|
2020-04-15 20:46:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-08-23 17:20:16 +02:00
|
|
|
|
valueString = tileMatrixElement.Element(wmts + "MatrixWidth")?.Value;
|
2020-04-15 20:46:16 +02:00
|
|
|
|
|
2020-04-16 19:24:38 +02:00
|
|
|
|
if (string.IsNullOrEmpty(valueString) || !int.TryParse(valueString, out int matrixWidth))
|
2020-04-15 20:46:16 +02:00
|
|
|
|
{
|
2022-01-20 22:15:43 +01:00
|
|
|
|
throw new ArgumentException($"No MatrixWidth element found in TileMatrix \"{identifier}\".");
|
2020-04-15 20:46:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-08-23 17:20:16 +02:00
|
|
|
|
valueString = tileMatrixElement.Element(wmts + "MatrixHeight")?.Value;
|
2020-04-15 20:46:16 +02:00
|
|
|
|
|
2020-04-16 19:24:38 +02:00
|
|
|
|
if (string.IsNullOrEmpty(valueString) || !int.TryParse(valueString, out int matrixHeight))
|
2020-04-15 20:46:16 +02:00
|
|
|
|
{
|
2022-01-20 22:15:43 +01:00
|
|
|
|
throw new ArgumentException($"No MatrixHeight element found in TileMatrix \"{identifier}\".");
|
2020-04-15 20:46:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-19 00:00:32 +02:00
|
|
|
|
var topLeft = supportedCrs == "EPSG:4326"
|
2022-03-02 22:03:18 +01:00
|
|
|
|
? new Point(MapProjection.Wgs84MeterPerDegree * top, MapProjection.Wgs84MeterPerDegree * left)
|
2020-06-19 00:00:32 +02:00
|
|
|
|
: new Point(left, top);
|
|
|
|
|
|
|
2025-10-29 18:59:19 +01:00
|
|
|
|
// See 07-057r7_Web_Map_Tile_Service_Standard.pdf, section 6.1.a, page 8:
|
|
|
|
|
|
// "standardized rendering pixel size" is 0.28 mm.
|
|
|
|
|
|
//
|
|
|
|
|
|
return new WmtsTileMatrix(identifier,
|
|
|
|
|
|
1d / (scaleDenominator * 0.00028),
|
|
|
|
|
|
topLeft, tileWidth, tileHeight, matrixWidth, matrixHeight);
|
2020-04-15 20:46:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|