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

71 lines
2.6 KiB
C#
Raw Normal View History

2022-01-19 23:40:05 +01:00
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// <20> 2022 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
namespace MapControl.Projections
{
public class GeoApiProjectionFactory : MapProjectionFactory
{
2022-01-21 00:17:01 +01:00
public const int WorldMercator = 3395;
public const int WebMercator = 3857;
2022-01-23 23:43:49 +01:00
public const int Ed50UtmFirst = 23028;
public const int Ed50UtmLast = 23038;
2022-01-23 14:02:04 +01:00
public const int Etrs89UtmFirst = 25828;
public const int Etrs89UtmLast = 25838;
2022-01-21 00:17:01 +01:00
public const int Wgs84UtmNorthFirst = 32601;
public const int Wgs84UtmNorthLast = 32660;
public const int Wgs84UpsNorth = 32661;
public const int Wgs84UtmSouthFirst = 32701;
public const int Wgs84UtmSouthLast = 32760;
public const int Wgs84UpsSouth = 32761;
2022-01-22 20:32:17 +01:00
public override MapProjection GetProjection(string crsId)
2022-01-19 23:40:05 +01:00
{
2022-01-21 00:17:01 +01:00
MapProjection projection = null;
2022-01-19 23:40:05 +01:00
2022-01-21 00:17:01 +01:00
if (crsId.StartsWith("EPSG:") && int.TryParse(crsId.Substring(5), out int epsgCode))
2022-01-19 23:40:05 +01:00
{
2022-01-21 00:17:01 +01:00
switch (epsgCode)
2022-01-19 23:40:05 +01:00
{
2022-01-21 00:17:01 +01:00
case WorldMercator:
projection = new WorldMercatorProjection();
break;
case WebMercator:
projection = new WebMercatorProjection();
break;
2022-01-23 23:43:49 +01:00
case int c when c >= Ed50UtmFirst && c <= Ed50UtmLast:
projection = new Ed50UtmProjection(epsgCode % 100);
break;
2022-01-23 14:02:04 +01:00
case int c when c >= Etrs89UtmFirst && c <= Etrs89UtmLast:
projection = new Etrs89UtmProjection(epsgCode % 100);
2022-01-21 00:17:01 +01:00
break;
case int c when c >= Wgs84UtmNorthFirst && c <= Wgs84UtmNorthLast:
2022-01-23 14:02:04 +01:00
projection = new Wgs84UtmProjection(epsgCode % 100, true);
2022-01-21 00:17:01 +01:00
break;
case int c when c >= Wgs84UtmSouthFirst && c <= Wgs84UtmSouthLast:
2022-01-23 14:02:04 +01:00
projection = new Wgs84UtmProjection(epsgCode % 100, false);
2022-01-21 00:17:01 +01:00
break;
case Wgs84UpsNorth:
projection = new UpsNorthProjection();
break;
case Wgs84UpsSouth:
projection = new UpsSouthProjection();
break;
default:
break;
2022-01-19 23:40:05 +01:00
}
}
2022-01-22 20:32:17 +01:00
return projection ?? base.GetProjection(crsId);
2022-01-21 00:17:01 +01:00
}
2022-01-19 23:40:05 +01:00
}
}