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

57 lines
1.5 KiB
C#
Raw Normal View History

2022-02-17 22:58:31 +01:00
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// © 2022 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using ProjNet.CoordinateSystems;
2022-12-02 17:45:58 +01:00
using System;
2022-02-17 22:58:31 +01:00
namespace MapControl.Projections
{
public class Wgs84AutoUtmProjection : GeoApiProjection
2022-02-17 22:58:31 +01:00
{
2022-02-23 18:47:45 +01:00
public const string DefaultCrsId = "AUTO2:42001";
public Wgs84AutoUtmProjection(bool useZoneCrsId = false)
2022-02-17 22:58:31 +01:00
{
UseZoneCrsId = useZoneCrsId;
2022-02-17 22:58:31 +01:00
UpdateZone();
}
public int Zone { get; private set; }
public bool IsNorth { get; private set; }
public bool UseZoneCrsId { get; }
2022-02-17 22:58:31 +01:00
public override Location Center
2022-02-17 22:58:31 +01:00
{
get => base.Center;
set
{
if (!Equals(base.Center, value))
{
base.Center = value;
UpdateZone();
}
}
2022-02-17 22:58:31 +01:00
}
private void UpdateZone()
{
var lon = Location.NormalizeLongitude(Center.Longitude);
2022-12-02 17:45:58 +01:00
var zone = (int)Math.Floor(lon / 6d) + 31;
var north = Center.Latitude >= 0d;
2022-02-17 22:58:31 +01:00
if (Zone != zone || IsNorth != north)
2022-02-17 22:58:31 +01:00
{
Zone = zone;
IsNorth = north;
CoordinateSystem = ProjectedCoordinateSystem.WGS84_UTM(Zone, IsNorth);
2022-02-20 18:22:42 +01:00
if (!UseZoneCrsId)
{
2022-02-23 18:47:45 +01:00
CrsId = DefaultCrsId;
2022-02-20 18:22:42 +01:00
}
2022-02-17 22:58:31 +01:00
}
}
}
}