mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Updated GeoApiProjectionFactory
This commit is contained in:
parent
e6b25c2f8d
commit
45b5d037bb
|
|
@ -6,7 +6,7 @@ namespace MapControl
|
||||||
{
|
{
|
||||||
public class MapProjectionFactory
|
public class MapProjectionFactory
|
||||||
{
|
{
|
||||||
public virtual MapProjection CreateProjection(string crsId)
|
public virtual MapProjection GetProjection(string crsId)
|
||||||
{
|
{
|
||||||
MapProjection projection = null;
|
MapProjection projection = null;
|
||||||
|
|
||||||
|
|
@ -43,6 +43,9 @@ namespace MapControl
|
||||||
case "EPSG:97003": // proprietary CRS ID
|
case "EPSG:97003": // proprietary CRS ID
|
||||||
projection = new AzimuthalEquidistantProjection { CrsId = crsId };
|
projection = new AzimuthalEquidistantProjection { CrsId = crsId };
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return projection;
|
return projection;
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,6 @@
|
||||||
// © 2022 Clemens Fischer
|
// © 2022 Clemens Fischer
|
||||||
// Licensed under the Microsoft Public License (Ms-PL)
|
// Licensed under the Microsoft Public License (Ms-PL)
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Net.Http;
|
|
||||||
|
|
||||||
namespace MapControl.Projections
|
namespace MapControl.Projections
|
||||||
{
|
{
|
||||||
public class GeoApiProjectionFactory : MapProjectionFactory
|
public class GeoApiProjectionFactory : MapProjectionFactory
|
||||||
|
|
@ -22,10 +17,7 @@ namespace MapControl.Projections
|
||||||
public const int Wgs84UtmSouthLast = 32760;
|
public const int Wgs84UtmSouthLast = 32760;
|
||||||
public const int Wgs84UpsSouth = 32761;
|
public const int Wgs84UpsSouth = 32761;
|
||||||
|
|
||||||
private readonly Dictionary<int, string> wkts = new Dictionary<int, string>();
|
public override MapProjection GetProjection(string crsId)
|
||||||
private readonly HttpClient httpClient = new HttpClient();
|
|
||||||
|
|
||||||
public override MapProjection CreateProjection(string crsId)
|
|
||||||
{
|
{
|
||||||
MapProjection projection = null;
|
MapProjection projection = null;
|
||||||
|
|
||||||
|
|
@ -62,17 +54,16 @@ namespace MapControl.Projections
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
projection = new GeoApiProjection(GetWkt(epsgCode));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return projection ?? base.CreateProjection(crsId);
|
return projection ?? base.GetProjection(crsId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetEtrs89UtmWkt(int epsgCode)
|
private static string GetEtrs89UtmWkt(int epsgCode)
|
||||||
{
|
{
|
||||||
const string etrs89UtmWktFormat
|
const string wktFormat
|
||||||
= "PROJCS[\"ETRS89 / UTM zone {1}N\","
|
= "PROJCS[\"ETRS89 / UTM zone {1}N\","
|
||||||
+ "GEOGCS[\"ETRS89\","
|
+ "GEOGCS[\"ETRS89\","
|
||||||
+ "DATUM[\"European_Terrestrial_Reference_System_1989\","
|
+ "DATUM[\"European_Terrestrial_Reference_System_1989\","
|
||||||
|
|
@ -97,29 +88,10 @@ namespace MapControl.Projections
|
||||||
+ "AXIS[\"Northing\",NORTH],"
|
+ "AXIS[\"Northing\",NORTH],"
|
||||||
+ "AUTHORITY[\"EPSG\",\"{0}\"]]";
|
+ "AUTHORITY[\"EPSG\",\"{0}\"]]";
|
||||||
|
|
||||||
int centralMeridian = 6 * (epsgCode - Etrs89UtmNorthFirst) - 15;
|
var zone = epsgCode % 100;
|
||||||
|
var centralMeridian = 6 * (epsgCode - Etrs89UtmNorthFirst) - 15;
|
||||||
|
|
||||||
return string.Format(etrs89UtmWktFormat, epsgCode, epsgCode - 25800, centralMeridian);
|
return string.Format(wktFormat, epsgCode, zone, centralMeridian);
|
||||||
}
|
|
||||||
|
|
||||||
private string GetWkt(int epsgCode)
|
|
||||||
{
|
|
||||||
if (!wkts.TryGetValue(epsgCode, out string wkt))
|
|
||||||
{
|
|
||||||
var url = string.Format("https://epsg.io/{0}.wkt", epsgCode);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
wkt = httpClient.GetStringAsync(url).Result; // potential deadlock?
|
|
||||||
wkts[epsgCode] = wkt;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Debug.WriteLine($"GeoApiProjectionFactory.GetWkt({epsgCode}): {url}: {ex.Message}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return wkt;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Collections.Specialized;
|
using System.Collections.Specialized;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
#if WINUI
|
#if WINUI
|
||||||
using Microsoft.UI.Xaml;
|
using Microsoft.UI.Xaml;
|
||||||
|
|
@ -14,7 +13,6 @@ using Windows.UI.Xaml;
|
||||||
using Windows.UI.Xaml.Markup;
|
using Windows.UI.Xaml.Markup;
|
||||||
#else
|
#else
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
|
||||||
using System.Windows.Markup;
|
using System.Windows.Markup;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -91,7 +89,7 @@ namespace MapControl.UiTools
|
||||||
if (selectedProjection != projection)
|
if (selectedProjection != projection)
|
||||||
{
|
{
|
||||||
selectedProjection = projection;
|
selectedProjection = projection;
|
||||||
Map.MapProjection = MapProjection.Factory.CreateProjection(selectedProjection);
|
Map.MapProjection = MapProjection.Factory.GetProjection(selectedProjection);
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateCheckedStates();
|
UpdateCheckedStates();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue