Added MapProjectionFactory

This commit is contained in:
Clemens 2022-01-19 16:43:00 +01:00
parent 67b87acb44
commit e2fcc1db2c
12 changed files with 87 additions and 17 deletions

View file

@ -11,9 +11,11 @@ namespace MapControl
{
public class AutoEquirectangularProjection : MapProjection
{
public const string DefaultCrsId = "AUTO2:42004";
public AutoEquirectangularProjection()
{
CrsId = "AUTO2:42004";
CrsId = DefaultCrsId;
}
public override Point LocationToMap(Location location)

View file

@ -18,9 +18,11 @@ namespace MapControl
/// </summary>
public class EquirectangularProjection : MapProjection
{
public const string DefaultCrsId = "EPSG:4326";
public EquirectangularProjection()
{
CrsId = "EPSG:4326";
CrsId = DefaultCrsId;
}
public override bool IsNormalCylindrical

View file

@ -14,9 +14,11 @@ namespace MapControl
/// </summary>
public class GnomonicProjection : AzimuthalProjection
{
public const string DefaultCrsId = "AUTO2:97001"; // GeoServer non-standard CRS ID
public GnomonicProjection()
{
CrsId = "AUTO2:97001"; // GeoServer non-standard CRS ID
CrsId = DefaultCrsId;
}
public override Point LocationToMap(Location location)

View file

@ -27,7 +27,7 @@ using System.Windows.Media;
namespace MapControl
{
public class GroundOverlayPanel : MapPanel
public class GroundOverlay : MapPanel
{
class LatLonBox : BoundingBox
{
@ -56,8 +56,8 @@ namespace MapControl
}
public static readonly DependencyProperty SourcePathProperty = DependencyProperty.Register(
nameof(SourcePath), typeof(string), typeof(GroundOverlayPanel),
new PropertyMetadata(null, async (o, e) => await ((GroundOverlayPanel)o).SourcePathPropertyChanged((string)e.NewValue)));
nameof(SourcePath), typeof(string), typeof(GroundOverlay),
new PropertyMetadata(null, async (o, e) => await ((GroundOverlay)o).SourcePathPropertyChanged((string)e.NewValue)));
public string SourcePath
{

View file

@ -22,6 +22,8 @@ namespace MapControl
public const double Wgs84Flattening = 1d / 298.257223563;
public static readonly double Wgs84Eccentricity = Math.Sqrt((2d - Wgs84Flattening) * Wgs84Flattening);
public static MapProjectionFactory Factory { get; set; } = new MapProjectionFactory();
/// <summary>
/// Gets or sets the WMS 1.3.0 CRS identifier.
/// </summary>

View file

@ -0,0 +1,51 @@
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// © 2022 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
namespace MapControl
{
public class MapProjectionFactory
{
public virtual MapProjection CreateProjection(string projectionDefinition)
{
MapProjection projection = null;
switch (projectionDefinition)
{
case WorldMercatorProjection.DefaultCrsId:
projection = new WorldMercatorProjection();
break;
case WebMercatorProjection.DefaultCrsId:
projection = new WebMercatorProjection();
break;
case EquirectangularProjection.DefaultCrsId:
projection = new EquirectangularProjection();
break;
case OrthographicProjection.DefaultCrsId:
projection = new OrthographicProjection();
break;
case AutoEquirectangularProjection.DefaultCrsId:
projection = new AutoEquirectangularProjection();
break;
case GnomonicProjection.DefaultCrsId:
projection = new GnomonicProjection();
break;
case StereographicProjection.DefaultCrsId:
projection = new StereographicProjection();
break;
case "EPSG:97003": // proprietary CRS ID
projection = new AzimuthalEquidistantProjection { CrsId = projectionDefinition };
break;
}
return projection;
}
}
}

View file

@ -14,9 +14,11 @@ namespace MapControl
/// </summary>
public class OrthographicProjection : AzimuthalProjection
{
public const string DefaultCrsId = "AUTO2:42003";
public OrthographicProjection()
{
CrsId = "AUTO2:42003";
CrsId = DefaultCrsId;
}
public override Point LocationToMap(Location location)

View file

@ -14,9 +14,11 @@ namespace MapControl
/// </summary>
public class StereographicProjection : AzimuthalProjection
{
public const string DefaultCrsId = "AUTO2:97002"; // GeoServer non-standard CRS ID
public StereographicProjection()
{
CrsId = "AUTO2:97002"; // GeoServer non-standard CRS ID
CrsId = DefaultCrsId;
}
public override Point LocationToMap(Location location)

View file

@ -15,11 +15,13 @@ namespace MapControl
/// </summary>
public class WebMercatorProjection : MapProjection
{
public const string DefaultCrsId = "EPSG:3857";
private static readonly double maxLatitude = YToLatitude(180d);
public WebMercatorProjection()
{
CrsId = "EPSG:3857";
CrsId = DefaultCrsId;
}
public override bool IsNormalCylindrical

View file

@ -15,6 +15,8 @@ namespace MapControl
/// </summary>
public class WorldMercatorProjection : MapProjection
{
public const string DefaultCrsId = "EPSG:3395";
public static double ConvergenceTolerance { get; set; } = 1e-6;
public static int MaxIterations { get; set; } = 10;
@ -22,7 +24,7 @@ namespace MapControl
public WorldMercatorProjection()
{
CrsId = "EPSG:3395";
CrsId = DefaultCrsId;
}
public override bool IsNormalCylindrical

View file

@ -77,8 +77,8 @@
<Compile Include="..\Shared\GnomonicProjection.cs">
<Link>GnomonicProjection.cs</Link>
</Compile>
<Compile Include="..\Shared\GroundOverlayPanel.cs">
<Link>GroundOverlayPanel.cs</Link>
<Compile Include="..\Shared\GroundOverlay.cs">
<Link>GroundOverlay.cs</Link>
</Compile>
<Compile Include="..\Shared\ImageFileCache.cs">
<Link>ImageFileCache.cs</Link>
@ -125,6 +125,9 @@
<Compile Include="..\Shared\MapProjection.cs">
<Link>MapProjection.cs</Link>
</Compile>
<Compile Include="..\Shared\MapProjectionFactory.cs">
<Link>MapProjectionFactory.cs</Link>
</Compile>
<Compile Include="..\Shared\MapScale.cs">
<Link>MapScale.cs</Link>
</Compile>

View file

@ -26,7 +26,7 @@ namespace MapControl.UiTools
public class MapProjectionItem
{
public string Text { get; set; }
public MapProjection Projection { get; set; }
public string Projection { get; set; }
}
#if WINUI || UWP
@ -77,18 +77,18 @@ namespace MapControl.UiTools
private void MapProjectionClicked(object sender, RoutedEventArgs e)
{
var item = (FrameworkElement)sender;
var projection = (MapProjection)item.Tag;
var projection = (string)item.Tag;
SetMapProjection(projection);
}
private void SetMapProjection(MapProjection projection)
private void SetMapProjection(string projection)
{
Map.MapProjection = projection;
Map.MapProjection = MapProjection.Factory.CreateProjection(projection);
foreach (var item in GetMenuItems())
{
item.IsChecked = Map.MapProjection == (MapProjection)item.Tag;
item.IsChecked = projection == (string)item.Tag;
}
}
}