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

60 lines
1.7 KiB
C#
Raw Normal View History

2026-01-10 08:28:10 +01:00
using System;
namespace MapControl
{
/// <summary>
2026-01-10 16:21:55 +01:00
/// WGS84 Universal Transverse Mercator Projection with automatic zone selection from
/// the projection center. If the CRS Id passed to the constructor is null or empty,
/// appropriate CRS Ids EPSG:32601 to EPSG:32660 and EPSG:32701 to EPSG:32760 are used.
2026-01-10 08:28:10 +01:00
/// </summary>
public class Wgs84AutoUtmProjection : Wgs84UtmProjection
{
public const string DefaultCrsId = "AUTO2:42001";
private readonly string autoCrsId;
public Wgs84AutoUtmProjection()
: this(DefaultCrsId)
{
// XAML needs parameterless constructor
}
public Wgs84AutoUtmProjection(string crsId)
2026-01-10 16:21:55 +01:00
: base(31, Hemisphere.North)
2026-01-10 08:28:10 +01:00
{
autoCrsId = crsId;
if (!string.IsNullOrEmpty(autoCrsId))
{
CrsId = autoCrsId;
}
}
public override Location Center
{
get => base.Center;
protected internal set
{
if (!base.Center.Equals(value))
{
base.Center = value;
var lon = Location.NormalizeLongitude(value.Longitude);
var zone = (int)Math.Floor(lon / 6d) + 31;
2026-01-10 16:21:55 +01:00
var hemisphere = value.Latitude >= 0d ? Hemisphere.North : Hemisphere.South;
2026-01-10 08:28:10 +01:00
2026-01-10 16:21:55 +01:00
if (Zone != zone || Hemisphere != hemisphere)
2026-01-10 08:28:10 +01:00
{
2026-01-10 16:21:55 +01:00
SetZone(zone, hemisphere);
2026-01-10 08:28:10 +01:00
if (!string.IsNullOrEmpty(autoCrsId))
{
CrsId = autoCrsId;
}
}
}
}
}
}
}