XAML-Map-Control/MapProjections/Shared/WebMercatorProjection.cs

36 lines
1 KiB
C#
Raw Normal View History

2018-12-20 21:55:12 +01:00
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
2024-02-03 21:01:53 +01:00
// Copyright © 2024 Clemens Fischer
2018-12-20 21:55:12 +01:00
// Licensed under the Microsoft Public License (Ms-PL)
2021-07-07 16:52:31 +02:00
using ProjNet.CoordinateSystems;
2018-12-20 21:55:12 +01:00
using System;
2024-05-22 11:25:32 +02:00
#if WPF
using System.Windows;
#elif AVALONIA
using Avalonia;
#endif
2018-12-20 21:55:12 +01:00
namespace MapControl.Projections
{
/// <summary>
/// Spherical Mercator Projection implemented by setting the CoordinateSystem property of a GeoApiProjection.
/// See "Map Projections - A Working Manual" (https://pubs.usgs.gov/pp/1395/report.pdf), p.41-44.
/// </summary>
public class WebMercatorProjection : GeoApiProjection
{
2024-07-12 13:57:27 +02:00
public const int EpsgCode = 3857;
2022-12-14 18:02:19 +01:00
2018-12-20 21:55:12 +01:00
public WebMercatorProjection()
{
CoordinateSystem = ProjectedCoordinateSystem.WebMercator;
}
public override Point GetRelativeScale(Location location)
2018-12-20 21:55:12 +01:00
{
var k = 1d / Math.Cos(location.Latitude * Math.PI / 180d); // p.44 (7-3)
return new Point(k, k);
2018-12-20 21:55:12 +01:00
}
}
}