From 2b41d298f4913097d9992149412d2cc8e431c8fc Mon Sep 17 00:00:00 2001 From: ClemensF Date: Wed, 1 Apr 2020 18:04:39 +0200 Subject: [PATCH] Version 5.0.1: Reworked MapBase and MapProjection --- .../Shared/EquirectangularProjection.cs | 4 ++-- MapControl/Shared/MapBase.cs | 12 ++++------- MapControl/Shared/MapProjection.cs | 12 +++++------ MapControl/Shared/ViewTransform.cs | 20 +++++++++---------- 4 files changed, 22 insertions(+), 26 deletions(-) diff --git a/MapControl/Shared/EquirectangularProjection.cs b/MapControl/Shared/EquirectangularProjection.cs index ebdb3c0b..6a853388 100644 --- a/MapControl/Shared/EquirectangularProjection.cs +++ b/MapControl/Shared/EquirectangularProjection.cs @@ -14,7 +14,7 @@ namespace MapControl { /// /// Equirectangular Projection. - /// Longitude and Latitude values are transformed linearly to X and Y in meters. + /// Longitude and Latitude values are transformed linearly to X and Y values in meters. /// public class EquirectangularProjection : MapProjection { @@ -47,7 +47,7 @@ namespace MapControl public override string GetBboxValue(Rect rect) { return string.Format(CultureInfo.InvariantCulture, - CrsId != "CRS:84" ? "{1},{0},{3},{2}" : "{0},{1},{2},{3}", + CrsId == "CRS:84" ? "{0},{1},{2},{3}" : "{1},{0},{3},{2}", rect.X / UnitsPerDegree, rect.Y / UnitsPerDegree, (rect.X + rect.Width) / UnitsPerDegree, (rect.Y + rect.Height) / UnitsPerDegree); } diff --git a/MapControl/Shared/MapBase.cs b/MapControl/Shared/MapBase.cs index 66b1e1d8..0d2d131a 100644 --- a/MapControl/Shared/MapBase.cs +++ b/MapControl/Shared/MapBase.cs @@ -692,16 +692,13 @@ namespace MapControl private void UpdateTransform(bool resetTransformCenter = false, bool projectionChanged = false) { + var viewScale = ViewTransform.ZoomLevelToScale(ZoomLevel); + var center = transformCenter ?? Center; var projection = MapProjection; projection.Center = ProjectionCenter ?? Center; - var center = transformCenter ?? Center; - var mapCenter = projection.LocationToMap(center); - - var viewScale = ViewTransform.ZoomLevelToScale(ZoomLevel); - - ViewTransform.SetTransform(mapCenter, viewCenter, viewScale, Heading); + ViewTransform.SetTransform(projection.LocationToMap(center), viewCenter, viewScale, Heading); if (transformCenter != null) { @@ -726,9 +723,8 @@ namespace MapControl ResetTransformCenter(); projection.Center = ProjectionCenter ?? center; - mapCenter = projection.LocationToMap(center); - ViewTransform.SetTransform(mapCenter, viewCenter, viewScale, Heading); + ViewTransform.SetTransform(projection.LocationToMap(center), viewCenter, viewScale, Heading); } } diff --git a/MapControl/Shared/MapProjection.cs b/MapControl/Shared/MapProjection.cs index f13fb09b..640a706f 100644 --- a/MapControl/Shared/MapProjection.cs +++ b/MapControl/Shared/MapProjection.cs @@ -22,15 +22,15 @@ namespace MapControl public const double Wgs84Flattening = 1d / 298.257223563; public static readonly double Wgs84Eccentricity = Math.Sqrt((2d - Wgs84Flattening) * Wgs84Flattening); - /// - /// Gets or sets the projection center. Only relevant for azimuthal projections. - /// - public Location Center { get; set; } = new Location(); - /// /// Gets or sets the WMS 1.3.0 CRS identifier. /// - public string CrsId { get; set; } + public string CrsId { get; set; } = string.Empty; + + /// + /// Gets or sets the projection center. + /// + public Location Center { get; set; } = new Location(); /// /// Indicates if this is a normal cylindrical projection. diff --git a/MapControl/Shared/ViewTransform.cs b/MapControl/Shared/ViewTransform.cs index f7dc0663..36d89193 100644 --- a/MapControl/Shared/ViewTransform.cs +++ b/MapControl/Shared/ViewTransform.cs @@ -19,6 +19,16 @@ namespace MapControl /// public class ViewTransform { + public static double ZoomLevelToScale(double zoomLevel) + { + return 256d * Math.Pow(2d, zoomLevel) / (360d * MapProjection.Wgs84MetersPerDegree); + } + + public static double ScaleToZoomLevel(double scale) + { + return Math.Log(scale * 360d * MapProjection.Wgs84MetersPerDegree / 256d, 2d); + } + /// /// Gets the scaling factor from cartesian map coordinates to view coordinates, /// i.e. pixels per meter. @@ -117,15 +127,5 @@ namespace MapControl return new MatrixTransform { Matrix = transform } .TransformBounds(new Rect(0d, 0d, viewSize.Width, viewSize.Height)); } - - public static double ZoomLevelToScale(double zoomLevel) - { - return 256d * Math.Pow(2d, zoomLevel) / (360d * MapProjection.Wgs84MetersPerDegree); - } - - public static double ScaleToZoomLevel(double scale) - { - return Math.Log(scale * 360d * MapProjection.Wgs84MetersPerDegree / 256d, 2d); - } } }