mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Added MapProjectionFactory
This commit is contained in:
parent
67b87acb44
commit
e2fcc1db2c
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
|
|
@ -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>
|
||||
|
|
|
|||
51
MapControl/Shared/MapProjectionFactory.cs
Normal file
51
MapControl/Shared/MapProjectionFactory.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue