2017-06-25 23:05:48 +02:00
|
|
|
|
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
2020-01-09 19:40:10 +01:00
|
|
|
|
// © 2020 Clemens Fischer
|
2017-06-25 23:05:48 +02:00
|
|
|
|
// Licensed under the Microsoft Public License (Ms-PL)
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
2018-03-06 22:22:58 +01:00
|
|
|
|
#if !WINDOWS_UWP
|
2017-06-25 23:05:48 +02:00
|
|
|
|
using System.Windows;
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
namespace MapControl
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
2018-12-20 21:55:12 +01:00
|
|
|
|
/// Spherical Stereographic Projection.
|
2017-06-25 23:05:48 +02:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class StereographicProjection : AzimuthalProjection
|
|
|
|
|
|
{
|
|
|
|
|
|
public StereographicProjection()
|
|
|
|
|
|
{
|
2019-12-12 19:23:41 +01:00
|
|
|
|
CrsId = "AUTO2:97002"; // GeoServer non-standard CRS ID
|
2017-06-25 23:05:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-03-26 19:08:20 +01:00
|
|
|
|
public override Point LocationToMap(Location location)
|
2017-06-25 23:05:48 +02:00
|
|
|
|
{
|
2020-03-26 19:08:20 +01:00
|
|
|
|
if (location.Equals(Center))
|
2017-06-25 23:05:48 +02:00
|
|
|
|
{
|
|
|
|
|
|
return new Point();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-16 19:24:38 +02:00
|
|
|
|
GetAzimuthDistance(Center, location, out double azimuth, out double distance);
|
2017-06-25 23:05:48 +02:00
|
|
|
|
|
2020-04-02 18:06:39 +02:00
|
|
|
|
var mapDistance = Math.Tan(distance / 2d) * 2d * Wgs84EquatorialRadius;
|
2017-06-25 23:05:48 +02:00
|
|
|
|
|
|
|
|
|
|
return new Point(mapDistance * Math.Sin(azimuth), mapDistance * Math.Cos(azimuth));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-03-26 19:08:20 +01:00
|
|
|
|
public override Location MapToLocation(Point point)
|
2017-06-25 23:05:48 +02:00
|
|
|
|
{
|
|
|
|
|
|
if (point.X == 0d && point.Y == 0d)
|
|
|
|
|
|
{
|
2020-03-26 19:08:20 +01:00
|
|
|
|
return new Location(Center.Latitude, Center.Longitude);
|
2017-06-25 23:05:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var azimuth = Math.Atan2(point.X, point.Y);
|
|
|
|
|
|
var mapDistance = Math.Sqrt(point.X * point.X + point.Y * point.Y);
|
2019-04-05 19:13:58 +02:00
|
|
|
|
|
2020-04-02 18:06:39 +02:00
|
|
|
|
var distance = 2d * Math.Atan(mapDistance / (2d * Wgs84EquatorialRadius));
|
2017-06-25 23:05:48 +02:00
|
|
|
|
|
2020-03-26 19:08:20 +01:00
|
|
|
|
return GetLocation(Center, azimuth, distance);
|
2017-06-25 23:05:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|