From 9c02647c59ead1ab201c3c15861884887a561c9f Mon Sep 17 00:00:00 2001 From: ClemensFischer Date: Sat, 24 Jan 2026 17:42:00 +0100 Subject: [PATCH] Removed MapProjectionType --- MapControl/Shared/AzimuthalProjection.cs | 4 +- .../Shared/EquirectangularProjection.cs | 2 +- MapControl/Shared/MapBase.cs | 2 +- MapControl/Shared/MapGraticule.cs | 2 +- MapControl/Shared/MapPanel.cs | 4 +- MapControl/Shared/MapPath.cs | 2 +- MapControl/Shared/MapProjection.cs | 25 +++++------- .../Shared/PolarStereographicProjection.cs | 5 --- .../Shared/TransverseMercatorProjection.cs | 1 - .../TransverseMercatorProjectionSnyder.cs | 5 --- MapControl/Shared/ViewTransform.cs | 2 +- MapControl/Shared/WebMercatorProjection.cs | 2 +- MapControl/Shared/WmsImageLayer.cs | 3 +- MapControl/Shared/WorldMercatorProjection.cs | 2 +- MapProjections/Shared/ProjNetMapProjection.cs | 39 +++++-------------- 15 files changed, 29 insertions(+), 71 deletions(-) diff --git a/MapControl/Shared/AzimuthalProjection.cs b/MapControl/Shared/AzimuthalProjection.cs index 0979fdc6..c4826d56 100644 --- a/MapControl/Shared/AzimuthalProjection.cs +++ b/MapControl/Shared/AzimuthalProjection.cs @@ -7,10 +7,8 @@ namespace MapControl { public abstract class AzimuthalProjection : MapProjection { - protected AzimuthalProjection() - : base(true) + protected AzimuthalProjection() : base(true) { - Type = MapProjectionType.Azimuthal; } public readonly struct ProjectedPoint diff --git a/MapControl/Shared/EquirectangularProjection.cs b/MapControl/Shared/EquirectangularProjection.cs index 9644112b..b34270b2 100644 --- a/MapControl/Shared/EquirectangularProjection.cs +++ b/MapControl/Shared/EquirectangularProjection.cs @@ -24,7 +24,7 @@ namespace MapControl public EquirectangularProjection(string crsId) { - Type = MapProjectionType.NormalCylindrical; + IsNormalCylindrical = true; CrsId = crsId; } diff --git a/MapControl/Shared/MapBase.cs b/MapControl/Shared/MapBase.cs index 3fcec022..47d5cc79 100644 --- a/MapControl/Shared/MapBase.cs +++ b/MapControl/Shared/MapBase.cs @@ -430,7 +430,7 @@ namespace MapControl { maxLatitude = 90d; - if (projection.Type <= MapProjectionType.NormalCylindrical) + if (projection.IsNormalCylindrical) { var maxLocation = projection.MapToLocation(0d, 180d * MapProjection.Wgs84MeterPerDegree); diff --git a/MapControl/Shared/MapGraticule.cs b/MapControl/Shared/MapGraticule.cs index a8a2e5c3..af18927d 100644 --- a/MapControl/Shared/MapGraticule.cs +++ b/MapControl/Shared/MapGraticule.cs @@ -151,7 +151,7 @@ namespace MapControl SetLineDistance(); - if (ParentMap.MapProjection.Type <= MapProjectionType.NormalCylindrical) + if (ParentMap.MapProjection.IsNormalCylindrical) { DrawCylindricalGraticule(figures, labels); } diff --git a/MapControl/Shared/MapPanel.cs b/MapControl/Shared/MapPanel.cs index 7975fc3c..841a2927 100644 --- a/MapControl/Shared/MapPanel.cs +++ b/MapControl/Shared/MapPanel.cs @@ -202,7 +202,7 @@ namespace MapControl { var position = parentMap.LocationToView(location); - if (parentMap.MapProjection.Type <= MapProjectionType.NormalCylindrical && + if (parentMap.MapProjection.IsNormalCylindrical && position.HasValue && !parentMap.InsideViewBounds(position.Value)) { var coercedPosition = parentMap.LocationToView( @@ -222,7 +222,7 @@ namespace MapControl var center = new Point(mapRect.X + mapRect.Width / 2d, mapRect.Y + mapRect.Height / 2d); var position = parentMap.ViewTransform.MapToView(center); - if (parentMap.MapProjection.Type <= MapProjectionType.NormalCylindrical && + if (parentMap.MapProjection.IsNormalCylindrical && !parentMap.InsideViewBounds(position)) { var location = parentMap.MapProjection.MapToLocation(center); diff --git a/MapControl/Shared/MapPath.cs b/MapControl/Shared/MapPath.cs index ed8fca86..c27f91bf 100644 --- a/MapControl/Shared/MapPath.cs +++ b/MapControl/Shared/MapPath.cs @@ -76,7 +76,7 @@ namespace MapControl { var longitudeOffset = 0d; - if (ParentMap.MapProjection.Type <= MapProjectionType.NormalCylindrical && location != null) + if (ParentMap.MapProjection.IsNormalCylindrical && location != null) { var position = ParentMap.LocationToView(location); diff --git a/MapControl/Shared/MapProjection.cs b/MapControl/Shared/MapProjection.cs index 9ee4a17e..6a9f04fd 100644 --- a/MapControl/Shared/MapProjection.cs +++ b/MapControl/Shared/MapProjection.cs @@ -8,17 +8,9 @@ using Avalonia; namespace MapControl { - public enum MapProjectionType - { - WebMercator, // normal cylindrical projection compatible with MapTileLayer - NormalCylindrical, - TransverseCylindrical, - Azimuthal, - Other - } - /// - /// Defines a map projection between geographic coordinates and cartesian map coordinates. + /// Implements a map projection, a transformation between geographic coordinates, + /// i.e. latitude and longitude in degrees, and cartesian map coordinates in meters. /// #if UWP || WINUI [Windows.Foundation.Metadata.CreateFromString(MethodName = "Parse")] @@ -45,18 +37,19 @@ namespace MapControl return Factory.GetProjection(crsId); } - /// - /// Gets the type of the projection. - /// - public MapProjectionType Type { get; protected set; } = MapProjectionType.Other; - /// /// Gets the WMS 1.3.0 CRS identifier. /// public string CrsId { get; protected set; } = ""; /// - /// The earth ellipsoid semi-major axis, or spherical earth radius, in meters. + /// Indicates whether the projection is normal cylindrical, see + /// https://en.wikipedia.org/wiki/Map_projection#Normal_cylindrical. + /// + public bool IsNormalCylindrical { get; protected set; } + + /// + /// The earth ellipsoid semi-major axis, or spherical earth radius respectively, in meters. /// public double EquatorialRadius { get; set; } = Wgs84EquatorialRadius; diff --git a/MapControl/Shared/PolarStereographicProjection.cs b/MapControl/Shared/PolarStereographicProjection.cs index ac80be70..71276c1d 100644 --- a/MapControl/Shared/PolarStereographicProjection.cs +++ b/MapControl/Shared/PolarStereographicProjection.cs @@ -15,11 +15,6 @@ namespace MapControl /// public class PolarStereographicProjection : MapProjection { - public PolarStereographicProjection() - { - Type = MapProjectionType.Azimuthal; - } - public double Flattening { get; set; } = Wgs84Flattening; public double ScaleFactor { get; set; } = 0.994; public double FalseEasting { get; set; } = 2e6; diff --git a/MapControl/Shared/TransverseMercatorProjection.cs b/MapControl/Shared/TransverseMercatorProjection.cs index 0e341ddb..831b769e 100644 --- a/MapControl/Shared/TransverseMercatorProjection.cs +++ b/MapControl/Shared/TransverseMercatorProjection.cs @@ -56,7 +56,6 @@ namespace MapControl public TransverseMercatorProjection() { - Type = MapProjectionType.TransverseCylindrical; Flattening = Wgs84Flattening; } diff --git a/MapControl/Shared/TransverseMercatorProjectionSnyder.cs b/MapControl/Shared/TransverseMercatorProjectionSnyder.cs index 18e6ed1f..68e06e51 100644 --- a/MapControl/Shared/TransverseMercatorProjectionSnyder.cs +++ b/MapControl/Shared/TransverseMercatorProjectionSnyder.cs @@ -16,11 +16,6 @@ namespace MapControl { private double M0; - public TransverseMercatorProjectionSnyder() - { - Type = MapProjectionType.TransverseCylindrical; - } - public double Flattening { get; set; } = Wgs84Flattening; public double ScaleFactor { get; set; } = 0.9996; public double CentralMeridian { get; set; } diff --git a/MapControl/Shared/ViewTransform.cs b/MapControl/Shared/ViewTransform.cs index b2cfd67c..38c645c3 100644 --- a/MapControl/Shared/ViewTransform.cs +++ b/MapControl/Shared/ViewTransform.cs @@ -117,7 +117,7 @@ namespace MapControl return TransformBounds(transform, 0d, 0d, viewWidth, viewHeight); } - private static Rect TransformBounds(Matrix transform, double x, double y, double width, double height) + public static Rect TransformBounds(Matrix transform, double x, double y, double width, double height) { if (transform.M12 == 0d && transform.M21 == 0d) { diff --git a/MapControl/Shared/WebMercatorProjection.cs b/MapControl/Shared/WebMercatorProjection.cs index f86cfe4e..528a0200 100644 --- a/MapControl/Shared/WebMercatorProjection.cs +++ b/MapControl/Shared/WebMercatorProjection.cs @@ -23,7 +23,7 @@ namespace MapControl public WebMercatorProjection(string crsId) { - Type = MapProjectionType.WebMercator; + IsNormalCylindrical = true; CrsId = crsId; } diff --git a/MapControl/Shared/WmsImageLayer.cs b/MapControl/Shared/WmsImageLayer.cs index 90de646f..ca830d59 100644 --- a/MapControl/Shared/WmsImageLayer.cs +++ b/MapControl/Shared/WmsImageLayer.cs @@ -191,8 +191,7 @@ namespace MapControl var xMin = -180d * MapProjection.Wgs84MeterPerDegree; var xMax = 180d * MapProjection.Wgs84MeterPerDegree; - if (ParentMap.MapProjection.Type > MapProjectionType.NormalCylindrical || - bbox.X >= xMin && bbox.X + bbox.Width <= xMax) + if (bbox.X >= xMin && bbox.X + bbox.Width <= xMax || !ParentMap.MapProjection.IsNormalCylindrical) { var uri = GetMapRequestUri(bbox); diff --git a/MapControl/Shared/WorldMercatorProjection.cs b/MapControl/Shared/WorldMercatorProjection.cs index 77b645c8..7f06dee9 100644 --- a/MapControl/Shared/WorldMercatorProjection.cs +++ b/MapControl/Shared/WorldMercatorProjection.cs @@ -25,7 +25,7 @@ namespace MapControl public WorldMercatorProjection(string crsId) { - Type = MapProjectionType.NormalCylindrical; + IsNormalCylindrical = true; CrsId = crsId; } diff --git a/MapProjections/Shared/ProjNetMapProjection.cs b/MapProjections/Shared/ProjNetMapProjection.cs index 1518df1f..0342051c 100644 --- a/MapProjections/Shared/ProjNetMapProjection.cs +++ b/MapProjections/Shared/ProjNetMapProjection.cs @@ -43,7 +43,15 @@ namespace MapControl.Projections get; protected set { - field = value ?? throw new ArgumentNullException(nameof(value)); + field = value ?? + throw new ArgumentNullException(nameof(value)); + + var name = field.Projection?.Name ?? + throw new ArgumentException("CoordinateSystem.Projection must not be null.", nameof(value)); + + IsNormalCylindrical = name.StartsWith("Mercator") || + name.StartsWith("Equirectangular") || + name.Contains("Pseudo-Mercator"); var transformFactory = new CoordinateTransformationFactory(); @@ -58,35 +66,6 @@ namespace MapControl.Projections CrsId = !string.IsNullOrEmpty(field.Authority) && field.AuthorityCode > 0 ? $"{field.Authority}:{field.AuthorityCode}" : string.Empty; - - if (CrsId == MapControl.WebMercatorProjection.DefaultCrsId) - { - Type = MapProjectionType.WebMercator; - } - else - { - var name = field.Projection?.Name ?? - throw new ArgumentException("CoordinateSystem.Projection must not be null.", nameof(value)); - - if (name.StartsWith("Mercator") || - name.StartsWith("Equirectangular")) - { - Type = MapProjectionType.NormalCylindrical; - } - else if (name.StartsWith("Transverse")) - { - Type = MapProjectionType.TransverseCylindrical; - } - else if (name.Contains("Orthographic") || - name.Contains("Stereographic")) - { - Type = MapProjectionType.Azimuthal; - } - else - { - Type = MapProjectionType.Other; - } - } } }