2025-02-27 18:46:32 +01:00
|
|
|
|
using System;
|
2024-05-22 11:25:32 +02:00
|
|
|
|
#if WPF
|
2017-06-25 23:05:48 +02:00
|
|
|
|
using System.Windows;
|
2025-08-19 19:43:02 +02:00
|
|
|
|
#elif AVALONIA
|
|
|
|
|
|
using Avalonia;
|
2017-06-25 23:05:48 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
namespace MapControl
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
2022-02-23 23:19:32 +01:00
|
|
|
|
/// Spherical Azimuthal Equidistant Projection - No standard CRS ID.
|
2025-02-24 11:22:17 +01:00
|
|
|
|
/// See "Map Projections - A Working Manual" (https://pubs.usgs.gov/publication/pp1395), p.195-197.
|
2017-06-25 23:05:48 +02:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class AzimuthalEquidistantProjection : AzimuthalProjection
|
|
|
|
|
|
{
|
2024-07-12 13:57:27 +02:00
|
|
|
|
public const string DefaultCrsId = "AUTO2:97003"; // proprietary CRS ID
|
|
|
|
|
|
|
2024-08-28 14:58:06 +02:00
|
|
|
|
public AzimuthalEquidistantProjection()
|
|
|
|
|
|
: this(DefaultCrsId)
|
|
|
|
|
|
{
|
|
|
|
|
|
// XAML needs parameterless constructor
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public AzimuthalEquidistantProjection(string crsId)
|
2022-03-05 18:40:57 +01:00
|
|
|
|
{
|
|
|
|
|
|
CrsId = crsId;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-12 21:28:45 +01:00
|
|
|
|
public override Point? LocationToMap(double latitude, double longitude)
|
2017-06-25 23:05:48 +02:00
|
|
|
|
{
|
2025-12-12 21:28:45 +01:00
|
|
|
|
if (Location.Equals(latitude, Center.Latitude) &&
|
|
|
|
|
|
Location.Equals(longitude, Center.Longitude))
|
2017-06-25 23:05:48 +02:00
|
|
|
|
{
|
|
|
|
|
|
return new Point();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-12 21:28:45 +01:00
|
|
|
|
Center.GetAzimuthDistance(latitude, longitude, out double azimuth, out double distance);
|
2017-06-25 23:05:48 +02:00
|
|
|
|
|
2020-04-02 18:06:39 +02:00
|
|
|
|
var mapDistance = distance * Wgs84EquatorialRadius;
|
2017-06-25 23:05:48 +02:00
|
|
|
|
|
2019-04-05 19:13:58 +02:00
|
|
|
|
return new Point(mapDistance * Math.Sin(azimuth), mapDistance * Math.Cos(azimuth));
|
2017-06-25 23:05:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-12 21:28:45 +01:00
|
|
|
|
public override Location MapToLocation(double x, double y)
|
2017-06-25 23:05:48 +02:00
|
|
|
|
{
|
2025-12-12 21:28:45 +01:00
|
|
|
|
if (x == 0d && y == 0d)
|
2017-06-25 23:05:48 +02:00
|
|
|
|
{
|
2020-03-26 19:08:20 +01:00
|
|
|
|
return new Location(Center.Latitude, Center.Longitude);
|
2017-06-25 23:05:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-12 21:28:45 +01:00
|
|
|
|
var azimuth = Math.Atan2(x, y);
|
|
|
|
|
|
var mapDistance = Math.Sqrt(x * x + y * y);
|
2020-04-02 18:06:39 +02:00
|
|
|
|
var distance = mapDistance / Wgs84EquatorialRadius;
|
2017-06-25 23:05:48 +02:00
|
|
|
|
|
2025-03-10 15:47:33 +01:00
|
|
|
|
return Center.GetLocation(azimuth, distance);
|
2017-06-25 23:05:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|