XAML-Map-Control/MapControl/Shared/OrthographicProjection.cs

57 lines
1.5 KiB
C#
Raw Normal View History

2025-02-27 18:46:32 +01:00
using System;
2024-05-22 11:25:32 +02:00
#if WPF
using System.Windows;
using System.Windows.Media;
2025-08-19 19:43:02 +02:00
#elif AVALONIA
using Avalonia;
#endif
namespace MapControl
{
/// <summary>
2022-02-23 23:19:32 +01:00
/// Spherical Orthographic Projection - AUTO2:42003.
2025-02-24 11:22:17 +01:00
/// See "Map Projections - A Working Manual" (https://pubs.usgs.gov/publication/pp1395), p.148-150.
/// </summary>
2026-01-19 21:38:18 +01:00
public class OrthographicProjection : AzimuthalProjection
{
2022-01-19 16:43:00 +01:00
public const string DefaultCrsId = "AUTO2:42003";
2026-01-10 23:29:42 +01:00
public OrthographicProjection() // parameterless constructor for XAML
: this(DefaultCrsId)
{
}
public OrthographicProjection(string crsId)
{
2024-07-12 13:57:27 +02:00
CrsId = crsId;
}
public override Matrix RelativeScale(double latitude, double longitude)
{
var p = GetProjectedPoint(latitude, longitude);
2026-01-21 14:15:26 +01:00
return p.RelativeScale(p.CosC, 1d); // p.149 (20-5), k == 1
2026-01-19 21:38:18 +01:00
}
2026-01-19 21:38:18 +01:00
public override Point? LocationToMap(double latitude, double longitude)
{
var p = GetProjectedPoint(latitude, longitude);
2022-03-04 22:28:18 +01:00
2026-01-21 12:08:12 +01:00
if (p.CosC < 0d) // p.149 "If cos c is negative, the point is not to be plotted."
{
return null;
}
return new Point(EarthRadius * p.X, EarthRadius * p.Y); // p.149 (20-3/4)
}
public override Location MapToLocation(double x, double y)
{
2026-01-19 21:38:18 +01:00
var rho = Math.Sqrt(x * x + y * y);
var sinC = rho / EarthRadius; // p.150 (20-19)
2026-01-13 23:24:48 +01:00
2026-01-21 12:08:12 +01:00
return GetLocation(x, y, rho, sinC);
}
}
}