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

57 lines
1.5 KiB
C#
Raw Normal View History

// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// © 2018 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;
#if !WINDOWS_UWP
using System.Windows;
#endif
namespace MapControl
{
/// <summary>
2018-12-20 21:55:12 +01:00
/// Spherical Azimuthal Equidistant Projection.
/// </summary>
public class AzimuthalEquidistantProjection : AzimuthalProjection
{
public AzimuthalEquidistantProjection()
{
// No known standard or de-facto standard CRS ID
}
public AzimuthalEquidistantProjection(string crsId)
{
CrsId = crsId;
}
public override Point LocationToPoint(Location location)
{
2017-08-16 21:27:12 +02:00
if (location.Equals(ProjectionCenter))
{
return new Point();
}
double azimuth, distance;
2017-08-16 21:27:12 +02:00
GetAzimuthDistance(ProjectionCenter, location, out azimuth, out distance);
2018-12-20 21:55:12 +01:00
distance *= TrueScale * 180d / Math.PI;
return new Point(distance * Math.Sin(azimuth), distance * Math.Cos(azimuth));
}
public override Location PointToLocation(Point point)
{
if (point.X == 0d && point.Y == 0d)
{
2017-08-16 21:27:12 +02:00
return ProjectionCenter;
}
var azimuth = Math.Atan2(point.X, point.Y);
2018-12-20 21:55:12 +01:00
var distance = Math.Sqrt(point.X * point.X + point.Y * point.Y) / (TrueScale * 180d / Math.PI);
2017-08-16 21:27:12 +02:00
return GetLocation(ProjectionCenter, azimuth, distance);
}
}
}