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;
|
2019-12-12 19:23:41 +01:00
|
|
|
|
using System.Globalization;
|
2019-12-13 16:59:31 +01:00
|
|
|
|
#if WINDOWS_UWP
|
|
|
|
|
|
using Windows.Foundation;
|
|
|
|
|
|
#else
|
2017-06-25 23:05:48 +02:00
|
|
|
|
using System.Windows;
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
namespace MapControl
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
2018-12-20 21:55:12 +01:00
|
|
|
|
/// Equirectangular Projection.
|
2020-03-26 19:08:20 +01:00
|
|
|
|
/// Longitude and Latitude values are transformed linearly to X and Y in meters.
|
2017-06-25 23:05:48 +02:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class EquirectangularProjection : MapProjection
|
|
|
|
|
|
{
|
|
|
|
|
|
public EquirectangularProjection()
|
|
|
|
|
|
{
|
2019-12-12 19:23:41 +01:00
|
|
|
|
CrsId = "EPSG:4326";
|
2017-06-25 23:05:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-03-26 19:08:20 +01:00
|
|
|
|
public override Vector GetRelativeScale(Location location)
|
2017-06-25 23:05:48 +02:00
|
|
|
|
{
|
2018-03-07 22:19:16 +01:00
|
|
|
|
return new Vector(
|
2020-03-26 19:08:20 +01:00
|
|
|
|
1d / Math.Cos(location.Latitude * Math.PI / 180d),
|
|
|
|
|
|
1d);
|
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
|
|
|
|
return new Point(
|
|
|
|
|
|
location.Longitude * UnitsPerDegree,
|
|
|
|
|
|
location.Latitude * UnitsPerDegree);
|
2017-06-25 23:05:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-03-26 19:08:20 +01:00
|
|
|
|
public override Location MapToLocation(Point point)
|
2017-06-25 23:05:48 +02:00
|
|
|
|
{
|
2020-03-26 19:08:20 +01:00
|
|
|
|
return new Location(
|
|
|
|
|
|
point.Y / UnitsPerDegree,
|
|
|
|
|
|
point.X / UnitsPerDegree);
|
2017-06-25 23:05:48 +02:00
|
|
|
|
}
|
2019-12-12 19:23:41 +01:00
|
|
|
|
|
|
|
|
|
|
public override string GetBboxValue(Rect rect)
|
|
|
|
|
|
{
|
|
|
|
|
|
return string.Format(CultureInfo.InvariantCulture,
|
|
|
|
|
|
CrsId != "CRS:84" ? "{1},{0},{3},{2}" : "{0},{1},{2},{3}",
|
2020-03-26 19:08:20 +01:00
|
|
|
|
rect.X / UnitsPerDegree, rect.Y / UnitsPerDegree,
|
|
|
|
|
|
(rect.X + rect.Width) / UnitsPerDegree, (rect.Y + rect.Height) / UnitsPerDegree);
|
2019-12-12 19:23:41 +01:00
|
|
|
|
}
|
2017-06-25 23:05:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|