Removed MapProjectionType

This commit is contained in:
ClemensFischer 2026-01-24 17:42:00 +01:00
parent d71d6c6e01
commit 9c02647c59
15 changed files with 29 additions and 71 deletions

View file

@ -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

View file

@ -24,7 +24,7 @@ namespace MapControl
public EquirectangularProjection(string crsId)
{
Type = MapProjectionType.NormalCylindrical;
IsNormalCylindrical = true;
CrsId = crsId;
}

View file

@ -430,7 +430,7 @@ namespace MapControl
{
maxLatitude = 90d;
if (projection.Type <= MapProjectionType.NormalCylindrical)
if (projection.IsNormalCylindrical)
{
var maxLocation = projection.MapToLocation(0d, 180d * MapProjection.Wgs84MeterPerDegree);

View file

@ -151,7 +151,7 @@ namespace MapControl
SetLineDistance();
if (ParentMap.MapProjection.Type <= MapProjectionType.NormalCylindrical)
if (ParentMap.MapProjection.IsNormalCylindrical)
{
DrawCylindricalGraticule(figures, labels);
}

View file

@ -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);

View file

@ -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);

View file

@ -8,17 +8,9 @@ using Avalonia;
namespace MapControl
{
public enum MapProjectionType
{
WebMercator, // normal cylindrical projection compatible with MapTileLayer
NormalCylindrical,
TransverseCylindrical,
Azimuthal,
Other
}
/// <summary>
/// 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.
/// </summary>
#if UWP || WINUI
[Windows.Foundation.Metadata.CreateFromString(MethodName = "Parse")]
@ -45,18 +37,19 @@ namespace MapControl
return Factory.GetProjection(crsId);
}
/// <summary>
/// Gets the type of the projection.
/// </summary>
public MapProjectionType Type { get; protected set; } = MapProjectionType.Other;
/// <summary>
/// Gets the WMS 1.3.0 CRS identifier.
/// </summary>
public string CrsId { get; protected set; } = "";
/// <summary>
/// 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.
/// </summary>
public bool IsNormalCylindrical { get; protected set; }
/// <summary>
/// The earth ellipsoid semi-major axis, or spherical earth radius respectively, in meters.
/// </summary>
public double EquatorialRadius { get; set; } = Wgs84EquatorialRadius;

View file

@ -15,11 +15,6 @@ namespace MapControl
/// </summary>
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;

View file

@ -56,7 +56,6 @@ namespace MapControl
public TransverseMercatorProjection()
{
Type = MapProjectionType.TransverseCylindrical;
Flattening = Wgs84Flattening;
}

View file

@ -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; }

View file

@ -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)
{

View file

@ -23,7 +23,7 @@ namespace MapControl
public WebMercatorProjection(string crsId)
{
Type = MapProjectionType.WebMercator;
IsNormalCylindrical = true;
CrsId = crsId;
}

View file

@ -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);

View file

@ -25,7 +25,7 @@ namespace MapControl
public WorldMercatorProjection(string crsId)
{
Type = MapProjectionType.NormalCylindrical;
IsNormalCylindrical = true;
CrsId = crsId;
}

View file

@ -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;
}
}
}
}