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

55 lines
1.8 KiB
C#
Raw Normal View History

// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
2025-01-01 18:57:55 +01:00
// Copyright © Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;
2024-05-22 11:25:32 +02:00
#if WPF
using System.Windows;
#endif
namespace MapControl
{
2022-02-23 23:19:32 +01:00
/// <summary>
/// Auto-Equirectangular Projection - AUTO2:42004.
/// Equidistant cylindrical projection with standard parallel and central meridian set by the Center property.
/// See "Map Projections - A Working Manual" (https://pubs.usgs.gov/pp/1395/report.pdf), p.90-91.
/// </summary>
public class AutoEquirectangularProjection : MapProjection
{
2022-01-19 16:43:00 +01:00
public const string DefaultCrsId = "AUTO2:42004";
public AutoEquirectangularProjection()
: this(DefaultCrsId)
{
// XAML needs parameterless constructor
}
public AutoEquirectangularProjection(string crsId)
{
2022-03-05 18:40:57 +01:00
Type = MapProjectionType.NormalCylindrical;
2024-07-12 13:57:27 +02:00
CrsId = crsId;
}
2024-08-03 23:42:09 +02:00
public override Point GetRelativeScale(Location location)
{
return new Point(
Math.Cos(Center.Latitude * Math.PI / 180d) / 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 - Center.Longitude) * Math.Cos(Center.Latitude * Math.PI / 180d),
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 * Math.Cos(Center.Latitude * Math.PI / 180d)) + Center.Longitude);
}
}
}