2017-06-25 23:05:48 +02:00
|
|
|
|
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
2024-02-03 21:01:53 +01:00
|
|
|
|
// Copyright © 2024 Clemens Fischer
|
2017-06-25 23:05:48 +02:00
|
|
|
|
// Licensed under the Microsoft Public License (Ms-PL)
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
2019-12-12 19:23:41 +01:00
|
|
|
|
using System.Globalization;
|
2022-12-01 23:49:57 +01:00
|
|
|
|
#if !WINUI && !UWP
|
2017-06-25 23:05:48 +02:00
|
|
|
|
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.
|
2017-06-25 23:05:48 +02:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class EquirectangularProjection : MapProjection
|
|
|
|
|
|
{
|
2022-12-13 18:22:18 +01:00
|
|
|
|
public const int DefaultEpsgCode = 4326;
|
|
|
|
|
|
public static readonly string DefaultCrsId = $"EPSG:{DefaultEpsgCode}";
|
2022-01-19 16:43:00 +01:00
|
|
|
|
|
2017-06-25 23:05:48 +02: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
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-19 17:24:18 +02:00
|
|
|
|
public override Point GetRelativeScale(Location location)
|
2017-06-25 23:05:48 +02:00
|
|
|
|
{
|
2024-05-19 17:24:18 +02:00
|
|
|
|
return new Point(
|
2020-03-26 19:08:20 +01:00
|
|
|
|
1d / Math.Cos(location.Latitude * Math.PI / 180d),
|
|
|
|
|
|
1d);
|
2017-06-25 23:05:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-02 16:50:10 +01:00
|
|
|
|
public override Point? LocationToMap(Location location)
|
2017-06-25 23:05:48 +02:00
|
|
|
|
{
|
2020-03-26 19:08:20 +01:00
|
|
|
|
return new Point(
|
2022-03-02 22:03:18 +01:00
|
|
|
|
Wgs84MeterPerDegree * location.Longitude,
|
|
|
|
|
|
Wgs84MeterPerDegree * location.Latitude);
|
2017-06-25 23:05:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-03-26 19:08:20 +01:00
|
|
|
|
public override Location MapToLocation(Point point)
|
2017-06-25 23:05:48 +02:00
|
|
|
|
{
|
2020-03-26 19:08:20 +01:00
|
|
|
|
return new Location(
|
2022-03-02 22:03:18 +01:00
|
|
|
|
point.Y / Wgs84MeterPerDegree,
|
|
|
|
|
|
point.X / Wgs84MeterPerDegree);
|
2017-06-25 23:05:48 +02:00
|
|
|
|
}
|
2019-12-12 19:23:41 +01:00
|
|
|
|
|
2024-05-19 17:24:18 +02:00
|
|
|
|
public override string GetBboxValue(Rect rect)
|
2019-12-12 19:23:41 +01:00
|
|
|
|
{
|
|
|
|
|
|
return string.Format(CultureInfo.InvariantCulture,
|
2020-04-01 18:04:39 +02:00
|
|
|
|
CrsId == "CRS:84" ? "{0},{1},{2},{3}" : "{1},{0},{3},{2}",
|
2024-05-19 17:24:18 +02:00
|
|
|
|
rect.X / Wgs84MeterPerDegree,
|
|
|
|
|
|
rect.Y / Wgs84MeterPerDegree,
|
|
|
|
|
|
(rect.X + rect.Width) / Wgs84MeterPerDegree,
|
|
|
|
|
|
(rect.Y + rect.Height) / Wgs84MeterPerDegree);
|
2019-12-12 19:23:41 +01:00
|
|
|
|
}
|
2017-06-25 23:05:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|