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 virtual MapProjection CreateProjection(string crsId)
|
||||
public virtual MapProjection GetProjection(string crsId)
|
||||
{
|
||||
MapProjection projection = null;
|
||||
|
||||
|
|
@ -43,6 +43,9 @@ namespace MapControl
|
|||
case "EPSG:97003": // proprietary CRS ID
|
||||
projection = new AzimuthalEquidistantProjection { CrsId = crsId };
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return projection;
|
||||
|
|
|
|||
|
|
@ -2,11 +2,6 @@
|
|||
// © 2022 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Net.Http;
|
||||
|
||||
namespace MapControl.Projections
|
||||
{
|
||||
public class GeoApiProjectionFactory : MapProjectionFactory
|
||||
|
|
@ -22,10 +17,7 @@ namespace MapControl.Projections
|
|||
public const int Wgs84UtmSouthLast = 32760;
|
||||
public const int Wgs84UpsSouth = 32761;
|
||||
|
||||
private readonly Dictionary<int, string> wkts = new Dictionary<int, string>();
|
||||
private readonly HttpClient httpClient = new HttpClient();
|
||||
|
||||
public override MapProjection CreateProjection(string crsId)
|
||||
public override MapProjection GetProjection(string crsId)
|
||||
{
|
||||
MapProjection projection = null;
|
||||
|
||||
|
|
@ -62,17 +54,16 @@ namespace MapControl.Projections
|
|||
break;
|
||||
|
||||
default:
|
||||
projection = new GeoApiProjection(GetWkt(epsgCode));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return projection ?? base.CreateProjection(crsId);
|
||||
return projection ?? base.GetProjection(crsId);
|
||||
}
|
||||
|
||||
private static string GetEtrs89UtmWkt(int epsgCode)
|
||||
{
|
||||
const string etrs89UtmWktFormat
|
||||
const string wktFormat
|
||||
= "PROJCS[\"ETRS89 / UTM zone {1}N\","
|
||||
+ "GEOGCS[\"ETRS89\","
|
||||
+ "DATUM[\"European_Terrestrial_Reference_System_1989\","
|
||||
|
|
@ -97,29 +88,10 @@ namespace MapControl.Projections
|
|||
+ "AXIS[\"Northing\",NORTH],"
|
||||
+ "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);
|
||||
}
|
||||
|
||||
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;
|
||||
return string.Format(wktFormat, epsgCode, zone, centralMeridian);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
#if WINUI
|
||||
using Microsoft.UI.Xaml;
|
||||
|
|
@ -14,7 +13,6 @@ using Windows.UI.Xaml;
|
|||
using Windows.UI.Xaml.Markup;
|
||||
#else
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Markup;
|
||||
#endif
|
||||
|
||||
|
|
@ -91,7 +89,7 @@ namespace MapControl.UiTools
|
|||
if (selectedProjection != projection)
|
||||
{
|
||||
selectedProjection = projection;
|
||||
Map.MapProjection = MapProjection.Factory.CreateProjection(selectedProjection);
|
||||
Map.MapProjection = MapProjection.Factory.GetProjection(selectedProjection);
|
||||
}
|
||||
|
||||
UpdateCheckedStates();
|
||||
|
|
|
|||
Loading…
Reference in a new issue