XAML-Map-Control/MapControl/Shared/EquirectangularProjection.cs
ClemensFischer 218a85316c Reworked MapProjection
Return nullable Point from LocationToMap. Use MapRect instead of WinUI/UWP Rect replacement. Drop Vector. Add Scale struct.
2022-12-02 16:50:10 +01:00

58 lines
1.8 KiB
C#

// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// © 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>
/// 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 string DefaultCrsId = "EPSG:4326";
public EquirectangularProjection()
{
Type = MapProjectionType.NormalCylindrical;
CrsId = DefaultCrsId;
}
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(
Wgs84MeterPerDegree * location.Longitude,
Wgs84MeterPerDegree * location.Latitude);
}
public override Location MapToLocation(Point point)
{
return new Location(
point.Y / Wgs84MeterPerDegree,
point.X / Wgs84MeterPerDegree);
}
public override string GetBboxValue(MapRect rect)
{
return string.Format(CultureInfo.InvariantCulture,
CrsId == "CRS:84" ? "{0},{1},{2},{3}" : "{1},{0},{3},{2}",
rect.X / Wgs84MeterPerDegree, rect.Y / Wgs84MeterPerDegree,
(rect.X + rect.Width) / Wgs84MeterPerDegree, (rect.Y + rect.Height) / Wgs84MeterPerDegree);
}
}
}