2017-06-25 23:05:48 +02:00
|
|
|
|
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
2021-01-13 21:19:27 +01:00
|
|
|
|
// © 2021 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;
|
2021-06-14 21:41:37 +02:00
|
|
|
|
#if WINUI || WINDOWS_UWP
|
2019-12-13 16:59:31 +01:00
|
|
|
|
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-04-01 18:04:39 +02:00
|
|
|
|
/// Longitude and Latitude values are transformed linearly to X and Y values 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-04-16 23:15:03 +02:00
|
|
|
|
public override bool IsNormalCylindrical
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return true; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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(
|
2020-04-02 18:06:39 +02:00
|
|
|
|
Wgs84MetersPerDegree * location.Longitude,
|
|
|
|
|
|
Wgs84MetersPerDegree * location.Latitude);
|
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(
|
2020-04-02 18:06:39 +02:00
|
|
|
|
point.Y / Wgs84MetersPerDegree,
|
|
|
|
|
|
point.X / Wgs84MetersPerDegree);
|
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,
|
2020-04-01 18:04:39 +02:00
|
|
|
|
CrsId == "CRS:84" ? "{0},{1},{2},{3}" : "{1},{0},{3},{2}",
|
2020-04-02 18:06:39 +02:00
|
|
|
|
rect.X / Wgs84MetersPerDegree, rect.Y / Wgs84MetersPerDegree,
|
|
|
|
|
|
(rect.X + rect.Width) / Wgs84MetersPerDegree, (rect.Y + rect.Height) / Wgs84MetersPerDegree);
|
2019-12-12 19:23:41 +01:00
|
|
|
|
}
|
2017-06-25 23:05:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|