2017-06-25 23:05:48 +02:00
|
|
|
|
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
2019-03-27 18:39:59 +01:00
|
|
|
|
// © 2019 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 Gnomonic Projection.
|
2017-06-25 23:05:48 +02:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class GnomonicProjection : AzimuthalProjection
|
|
|
|
|
|
{
|
|
|
|
|
|
public GnomonicProjection()
|
|
|
|
|
|
: this("AUTO2:97001") // GeoServer non-standard CRS ID
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public GnomonicProjection(string crsId)
|
|
|
|
|
|
{
|
|
|
|
|
|
CrsId = crsId;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Point LocationToPoint(Location location)
|
|
|
|
|
|
{
|
2017-08-16 21:27:12 +02:00
|
|
|
|
if (location.Equals(ProjectionCenter))
|
2017-06-25 23:05:48 +02:00
|
|
|
|
{
|
|
|
|
|
|
return new Point();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double azimuth, distance;
|
|
|
|
|
|
|
2017-08-16 21:27:12 +02:00
|
|
|
|
GetAzimuthDistance(ProjectionCenter, location, out azimuth, out distance);
|
2017-06-25 23:05:48 +02:00
|
|
|
|
|
|
|
|
|
|
var mapDistance = distance < Math.PI / 2d
|
2018-12-20 21:55:12 +01:00
|
|
|
|
? Math.Tan(distance) * TrueScale * 180d / Math.PI
|
2017-06-25 23:05:48 +02:00
|
|
|
|
: double.PositiveInfinity;
|
|
|
|
|
|
|
|
|
|
|
|
return new Point(mapDistance * Math.Sin(azimuth), mapDistance * 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;
|
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
|
|
|
|
|
2018-12-20 21:55:12 +01:00
|
|
|
|
var distance = Math.Atan(mapDistance / (TrueScale * 180d / Math.PI));
|
2017-06-25 23:05:48 +02:00
|
|
|
|
|
2017-08-16 21:27:12 +02:00
|
|
|
|
return GetLocation(ProjectionCenter, azimuth, distance);
|
2017-06-25 23:05:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|