XAML-Map-Control/MapControl/Shared/EquirectangularProjection.cs

60 lines
1.9 KiB
C#
Raw Normal View History

// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
2022-01-14 20:22:56 +01:00
// © 2022 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;
using System.Globalization;
2021-11-17 23:17:11 +01:00
#if WINUI || UWP
using Windows.Foundation;
#else
using System.Windows;
#endif
namespace MapControl
{
/// <summary>
2022-02-23 23:19:32 +01:00
/// Equirectangular Projection - EPSG:4326.
/// Equidistant cylindrical projection with zero standard parallel and central meridian.
/// See "Map Projections - A Working Manual" (https://pubs.usgs.gov/pp/1395/report.pdf), p.90-91.
/// </summary>
public class EquirectangularProjection : MapProjection
{
2022-01-19 16:43:00 +01:00
public const string DefaultCrsId = "EPSG:4326";
public EquirectangularProjection()
{
2022-01-19 16:43:00 +01:00
CrsId = DefaultCrsId;
2022-01-21 23:26:21 +01:00
IsNormalCylindrical = true;
2020-04-16 23:15:03 +02:00
}
public override Vector GetRelativeScale(Location location)
{
2018-03-07 22:19:16 +01:00
return new Vector(
1d / Math.Cos(location.Latitude * Math.PI / 180d),
1d);
}
public override Point LocationToMap(Location location)
{
return new Point(
Wgs84MetersPerDegree * location.Longitude,
Wgs84MetersPerDegree * location.Latitude);
}
public override Location MapToLocation(Point point)
{
return new Location(
point.Y / Wgs84MetersPerDegree,
point.X / Wgs84MetersPerDegree);
}
public override string GetBboxValue(Rect rect)
{
return string.Format(CultureInfo.InvariantCulture,
CrsId == "CRS:84" ? "{0},{1},{2},{3}" : "{1},{0},{3},{2}",
rect.X / Wgs84MetersPerDegree, rect.Y / Wgs84MetersPerDegree,
(rect.X + rect.Width) / Wgs84MetersPerDegree, (rect.Y + rect.Height) / Wgs84MetersPerDegree);
}
}
}