mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-06 06:55:04 +00:00
Version 4.17.0: Added support for WMTS
This commit is contained in:
parent
b687487be2
commit
e06e910126
4 changed files with 204 additions and 173 deletions
|
|
@ -2,6 +2,9 @@
|
|||
// © 2020 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Xml.Linq;
|
||||
#if !WINDOWS_UWP
|
||||
using System.Windows;
|
||||
#endif
|
||||
|
|
@ -10,6 +13,14 @@ namespace MapControl
|
|||
{
|
||||
public class WmtsTileMatrix
|
||||
{
|
||||
public string Identifier { get; }
|
||||
public double Scale { get; }
|
||||
public Point TopLeft { get; }
|
||||
public int TileWidth { get; }
|
||||
public int TileHeight { get; }
|
||||
public int MatrixWidth { get; }
|
||||
public int MatrixHeight { get; }
|
||||
|
||||
public WmtsTileMatrix(string identifier, double scaleDenominator, Point topLeft,
|
||||
int tileWidth, int tileHeight, int matrixWidth, int matrixHeight)
|
||||
{
|
||||
|
|
@ -22,12 +33,70 @@ namespace MapControl
|
|||
MatrixHeight = matrixHeight;
|
||||
}
|
||||
|
||||
public string Identifier { get; }
|
||||
public double Scale { get; }
|
||||
public Point TopLeft { get; }
|
||||
public int TileWidth { get; }
|
||||
public int TileHeight { get; }
|
||||
public int MatrixWidth { get; }
|
||||
public int MatrixHeight { get; }
|
||||
public static WmtsTileMatrix Create(XElement tileMatrixElement)
|
||||
{
|
||||
XNamespace ns = tileMatrixElement.Name.Namespace;
|
||||
XNamespace ows = "http://www.opengis.net/ows/1.1";
|
||||
|
||||
var identifier = tileMatrixElement.Element(ows + "Identifier")?.Value;
|
||||
|
||||
if (string.IsNullOrEmpty(identifier))
|
||||
{
|
||||
throw new ArgumentException("ows:Identifier element not found in TileMatrix.");
|
||||
}
|
||||
|
||||
string[] topLeftCornerStrings;
|
||||
double scaleDenominator, top, left;
|
||||
int tileWidth, tileHeight, matrixWidth, matrixHeight;
|
||||
|
||||
var valueString = tileMatrixElement.Element(ns + "ScaleDenominator")?.Value;
|
||||
|
||||
if (string.IsNullOrEmpty(valueString) ||
|
||||
!double.TryParse(valueString, NumberStyles.Float, CultureInfo.InvariantCulture, out scaleDenominator))
|
||||
{
|
||||
throw new ArgumentException("ScaleDenominator element not found in TileMatrix \"" + identifier + "\".");
|
||||
}
|
||||
|
||||
valueString = tileMatrixElement.Element(ns + "TopLeftCorner")?.Value;
|
||||
|
||||
if (string.IsNullOrEmpty(valueString) ||
|
||||
(topLeftCornerStrings = valueString.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)).Length < 2 ||
|
||||
!double.TryParse(topLeftCornerStrings[0], NumberStyles.Float, CultureInfo.InvariantCulture, out left) ||
|
||||
!double.TryParse(topLeftCornerStrings[1], NumberStyles.Float, CultureInfo.InvariantCulture, out top))
|
||||
{
|
||||
throw new ArgumentException("TopLeftCorner element not found in TileMatrix \"" + identifier + "\".");
|
||||
}
|
||||
|
||||
valueString = tileMatrixElement.Element(ns + "TileWidth")?.Value;
|
||||
|
||||
if (string.IsNullOrEmpty(valueString) || !int.TryParse(valueString, out tileWidth))
|
||||
{
|
||||
throw new ArgumentException("TileWidth element not found in TileMatrix \"" + identifier + "\".");
|
||||
}
|
||||
|
||||
valueString = tileMatrixElement.Element(ns + "TileHeight")?.Value;
|
||||
|
||||
if (string.IsNullOrEmpty(valueString) || !int.TryParse(valueString, out tileHeight))
|
||||
{
|
||||
throw new ArgumentException("TileHeight element not found in TileMatrix \"" + identifier + "\".");
|
||||
}
|
||||
|
||||
valueString = tileMatrixElement.Element(ns + "MatrixWidth")?.Value;
|
||||
|
||||
if (string.IsNullOrEmpty(valueString) || !int.TryParse(valueString, out matrixWidth))
|
||||
{
|
||||
throw new ArgumentException("MatrixWidth element not found in TileMatrix \"" + identifier + "\".");
|
||||
}
|
||||
|
||||
valueString = tileMatrixElement.Element(ns + "MatrixHeight")?.Value;
|
||||
|
||||
if (string.IsNullOrEmpty(valueString) || !int.TryParse(valueString, out matrixHeight))
|
||||
{
|
||||
throw new ArgumentException("MatrixHeight element not found in TileMatrix \"" + identifier + "\".");
|
||||
}
|
||||
|
||||
return new WmtsTileMatrix(
|
||||
identifier, scaleDenominator, new Point(left, top), tileWidth, tileHeight, matrixWidth, matrixHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue