mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
49 lines
1.4 KiB
C#
49 lines
1.4 KiB
C#
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
|
// © 2021 Clemens Fischer
|
|
// Licensed under the Microsoft Public License (Ms-PL)
|
|
|
|
using System;
|
|
#if !WINUI && !WINDOWS_UWP
|
|
using System.Windows;
|
|
#endif
|
|
|
|
namespace MapControl
|
|
{
|
|
/// <summary>
|
|
/// Spherical Azimuthal Equidistant Projection.
|
|
/// </summary>
|
|
public class AzimuthalEquidistantProjection : AzimuthalProjection
|
|
{
|
|
// No standard CRS ID
|
|
|
|
public override Point LocationToMap(Location location)
|
|
{
|
|
if (location.Equals(Center))
|
|
{
|
|
return new Point();
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|