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
|
|
|
|
using System.Windows;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MapControl.Projections
|
|
|
|
|
|
{
|
|
|
|
|
|
public class AutoUtmProjection : GeoApiProjection
|
|
|
|
|
|
{
|
2022-02-23 18:47:45 +01:00
|
|
|
|
public const string DefaultCrsId = "AUTO2:42001";
|
|
|
|
|
|
|
|
|
|
|
|
public int ZoneNumber { get; private set; }
|
|
|
|
|
|
public bool ZoneIsNorth { get; private set; }
|
2022-02-17 22:58:31 +01:00
|
|
|
|
|
|
|
|
|
|
public AutoUtmProjection()
|
|
|
|
|
|
{
|
|
|
|
|
|
UpdateZone();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-20 18:22:42 +01:00
|
|
|
|
public bool UseZoneCrsId { get; set; }
|
|
|
|
|
|
|
2022-12-02 17:45:58 +01:00
|
|
|
|
public override Point? LocationToMap(Location location)
|
2022-02-17 22:58:31 +01:00
|
|
|
|
{
|
|
|
|
|
|
UpdateZone();
|
2022-03-07 17:28:08 +01:00
|
|
|
|
|
2022-02-17 22:58:31 +01:00
|
|
|
|
return base.LocationToMap(location);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Location MapToLocation(Point point)
|
|
|
|
|
|
{
|
|
|
|
|
|
UpdateZone();
|
2022-03-07 17:28:08 +01:00
|
|
|
|
|
2022-02-17 22:58:31 +01:00
|
|
|
|
return base.MapToLocation(point);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void UpdateZone()
|
|
|
|
|
|
{
|
|
|
|
|
|
var north = Center.Latitude >= 0d;
|
|
|
|
|
|
var lon = Location.NormalizeLongitude(Center.Longitude);
|
2022-12-02 17:45:58 +01:00
|
|
|
|
var zone = (int)Math.Floor(lon / 6d) + 31;
|
2022-02-17 22:58:31 +01:00
|
|
|
|
|
2022-02-23 18:47:45 +01:00
|
|
|
|
if (ZoneNumber != zone || ZoneIsNorth != north)
|
2022-02-17 22:58:31 +01:00
|
|
|
|
{
|
2022-02-23 18:47:45 +01:00
|
|
|
|
ZoneNumber = zone;
|
|
|
|
|
|
ZoneIsNorth = north;
|
2022-02-17 22:58:31 +01:00
|
|
|
|
|
2022-02-23 18:47:45 +01:00
|
|
|
|
CoordinateSystem = ProjectedCoordinateSystem.WGS84_UTM(ZoneNumber, ZoneIsNorth);
|
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
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|