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

61 lines
1.8 KiB
C#
Raw Normal View History

// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
2025-01-01 18:57:55 +01:00
// Copyright © Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;
2024-05-22 11:25:32 +02:00
#if WPF
using System.Windows;
#endif
namespace MapControl
{
/// <summary>
2022-02-23 23:19:32 +01:00
/// Spherical Azimuthal Equidistant Projection - No standard CRS ID.
/// See "Map Projections - A Working Manual" (https://pubs.usgs.gov/pp/1395/report.pdf), p.195-197.
/// </summary>
public class AzimuthalEquidistantProjection : AzimuthalProjection
{
2024-07-12 13:57:27 +02:00
public const string DefaultCrsId = "AUTO2:97003"; // proprietary CRS ID
public AzimuthalEquidistantProjection()
: this(DefaultCrsId)
{
// XAML needs parameterless constructor
}
public AzimuthalEquidistantProjection(string crsId)
2022-03-05 18:40:57 +01:00
{
CrsId = crsId;
}
public override Point? LocationToMap(Location location)
{
if (location.Equals(Center))
{
return new Point();
}
2020-04-16 19:24:38 +02:00
GetAzimuthDistance(Center, location, out double azimuth, out double distance);
var mapDistance = distance * Wgs84EquatorialRadius;
return new Point(mapDistance * Math.Sin(azimuth), mapDistance * Math.Cos(azimuth));
}
public override Location MapToLocation(Point point)
{
if (point.X == 0d && point.Y == 0d)
{
return new Location(Center.Latitude, Center.Longitude);
}
var azimuth = Math.Atan2(point.X, point.Y);
var mapDistance = Math.Sqrt(point.X * point.X + point.Y * point.Y);
var distance = mapDistance / Wgs84EquatorialRadius;
return GetLocation(Center, azimuth, distance);
}
}
}