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

61 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;
#if !WINUI && !UWP
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
{
public const int DefaultEpsgCode = 4326;
public static readonly string DefaultCrsId = $"EPSG:{DefaultEpsgCode}";
2022-01-19 16:43:00 +01:00
public EquirectangularProjection()
{
2022-03-05 18:40:57 +01:00
Type = MapProjectionType.NormalCylindrical;
2022-01-19 16:43:00 +01:00
CrsId = DefaultCrsId;
2020-04-16 23:15:03 +02:00
}
public override Scale GetRelativeScale(Location location)
{
return new Scale(
1d / Math.Cos(location.Latitude * Math.PI / 180d),
1d);
}
public override Point? LocationToMap(Location location)
{
return new Point(
2022-03-02 22:03:18 +01:00
Wgs84MeterPerDegree * location.Longitude,
Wgs84MeterPerDegree * location.Latitude);
}
public override Location MapToLocation(Point point)
{
return new Location(
2022-03-02 22:03:18 +01:00
point.Y / Wgs84MeterPerDegree,
point.X / Wgs84MeterPerDegree);
}
2022-12-07 17:00:25 +01:00
public override string GetBboxValue(MapRect mapRect)
{
return string.Format(CultureInfo.InvariantCulture,
CrsId == "CRS:84" ? "{0},{1},{2},{3}" : "{1},{0},{3},{2}",
2022-12-07 17:00:25 +01:00
mapRect.XMin / Wgs84MeterPerDegree,
mapRect.YMin / Wgs84MeterPerDegree,
mapRect.XMax / Wgs84MeterPerDegree,
mapRect.YMax / Wgs84MeterPerDegree);
}
}
}