diff --git a/MapControl/Shared/WmtsCapabilities.cs b/MapControl/Shared/WmtsCapabilities.cs index 2e733637..6f58e046 100644 --- a/MapControl/Shared/WmtsCapabilities.cs +++ b/MapControl/Shared/WmtsCapabilities.cs @@ -151,7 +151,7 @@ namespace MapControl foreach (var tileMatrixElement in tileMatrixSetElement.Descendants(ns + "TileMatrix")) { - tileMatrixes.Add(ReadTileMatrix(tileMatrixElement)); + tileMatrixes.Add(ReadTileMatrix(tileMatrixElement, supportedCrs)); } if (tileMatrixes.Count <= 0) @@ -162,7 +162,7 @@ namespace MapControl return new WmtsTileMatrixSet(identifier, supportedCrs, tileMatrixes); } - public static WmtsTileMatrix ReadTileMatrix(XElement tileMatrixElement) + public static WmtsTileMatrix ReadTileMatrix(XElement tileMatrixElement, string supportedCrs) { XNamespace ns = tileMatrixElement.Name.Namespace; XNamespace ows = "http://www.opengis.net/ows/1.1"; @@ -221,8 +221,12 @@ namespace MapControl throw new ArgumentException("No MatrixHeight element found in TileMatrix \"" + identifier + "\"."); } + var topLeft = supportedCrs == "EPSG:4326" + ? new Point(MapProjection.Wgs84MetersPerDegree * top, MapProjection.Wgs84MetersPerDegree * left) + : new Point(left, top); + return new WmtsTileMatrix( - identifier, scaleDenominator, new Point(left, top), tileWidth, tileHeight, matrixWidth, matrixHeight); + identifier, scaleDenominator, topLeft, tileWidth, tileHeight, matrixWidth, matrixHeight); } } } diff --git a/MapControl/Shared/WmtsTileLayer.cs b/MapControl/Shared/WmtsTileLayer.cs index f5c3db6a..5395f1ab 100644 --- a/MapControl/Shared/WmtsTileLayer.cs +++ b/MapControl/Shared/WmtsTileLayer.cs @@ -194,8 +194,6 @@ namespace MapControl { var capabilities = await WmtsCapabilities.ReadCapabilities(CapabilitiesUri, LayerIdentifier); - TileMatrixSets.Clear(); - foreach (var tileMatrixSet in capabilities.TileMatrixSets .Where(s => !TileMatrixSets.ContainsKey(s.SupportedCrs))) {