mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-05 14:37:01 +00:00
Added MapProjection.Type
This commit is contained in:
parent
a07948be02
commit
16fb98ac86
15 changed files with 126 additions and 77 deletions
|
|
@ -20,8 +20,8 @@ namespace MapControl
|
|||
|
||||
public AutoEquirectangularProjection()
|
||||
{
|
||||
Type = MapProjectionType.NormalCylindrical;
|
||||
CrsId = DefaultCrsId;
|
||||
IsNormalCylindrical = true;
|
||||
}
|
||||
|
||||
public override Point LocationToMap(Location location)
|
||||
|
|
|
|||
|
|
@ -15,6 +15,11 @@ namespace MapControl
|
|||
/// </summary>
|
||||
public class AzimuthalEquidistantProjection : AzimuthalProjection
|
||||
{
|
||||
public AzimuthalEquidistantProjection(string crsId)
|
||||
{
|
||||
CrsId = crsId;
|
||||
}
|
||||
|
||||
public override Point LocationToMap(Location location)
|
||||
{
|
||||
if (location.Equals(Center))
|
||||
|
|
|
|||
|
|
@ -16,6 +16,11 @@ namespace MapControl
|
|||
/// </summary>
|
||||
public abstract class AzimuthalProjection : MapProjection
|
||||
{
|
||||
protected AzimuthalProjection()
|
||||
{
|
||||
Type = MapProjectionType.Azimuthal;
|
||||
}
|
||||
|
||||
public override Rect BoundingBoxToRect(BoundingBox boundingBox)
|
||||
{
|
||||
var center = LocationToMap(boundingBox.Center);
|
||||
|
|
|
|||
|
|
@ -23,8 +23,8 @@ namespace MapControl
|
|||
|
||||
public EquirectangularProjection()
|
||||
{
|
||||
Type = MapProjectionType.NormalCylindrical;
|
||||
CrsId = DefaultCrsId;
|
||||
IsNormalCylindrical = true;
|
||||
}
|
||||
|
||||
public override Vector GetRelativeScale(Location location)
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ namespace MapControl
|
|||
|
||||
public static readonly DependencyProperty MapProjectionProperty = DependencyProperty.Register(
|
||||
nameof(MapProjection), typeof(MapProjection), typeof(MapBase),
|
||||
new PropertyMetadata(new WebMercatorProjection(), (o, e) => ((MapBase)o).MapProjectionPropertyChanged()));
|
||||
new PropertyMetadata(new WebMercatorProjection(), (o, e) => ((MapBase)o).MapProjectionPropertyChanged((MapProjection)e.NewValue)));
|
||||
|
||||
public static readonly DependencyProperty ProjectionCenterProperty = DependencyProperty.Register(
|
||||
nameof(ProjectionCenter), typeof(Location), typeof(MapBase),
|
||||
|
|
@ -72,6 +72,7 @@ namespace MapControl
|
|||
private Location transformCenter;
|
||||
private Point viewCenter;
|
||||
private double centerLongitude;
|
||||
private double maxLatitude = 90d;
|
||||
private bool internalPropertyChange;
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -436,8 +437,23 @@ namespace MapControl
|
|||
}
|
||||
}
|
||||
|
||||
private void MapProjectionPropertyChanged()
|
||||
private void MapProjectionPropertyChanged(MapProjection projection)
|
||||
{
|
||||
maxLatitude = 90d;
|
||||
|
||||
if (projection.Type <= MapProjectionType.NormalCylindrical)
|
||||
{
|
||||
var maxLocation = projection.MapToLocation(new Point(0d, 180d * MapProjection.Wgs84MeterPerDegree));
|
||||
|
||||
if (maxLocation != null && maxLocation.Latitude < 90d)
|
||||
{
|
||||
maxLatitude = maxLocation.Latitude;
|
||||
|
||||
var center = Center;
|
||||
AdjustCenterProperty(CenterProperty, ref center);
|
||||
}
|
||||
}
|
||||
|
||||
ResetTransformCenter();
|
||||
UpdateTransform(false, true);
|
||||
}
|
||||
|
|
@ -450,16 +466,23 @@ namespace MapControl
|
|||
|
||||
private void AdjustCenterProperty(DependencyProperty property, ref Location center)
|
||||
{
|
||||
if (center == null ||
|
||||
center.Longitude < -180d || center.Longitude > 180d ||
|
||||
center.Latitude < -MapProjection.MaxLatitude || center.Latitude > MapProjection.MaxLatitude)
|
||||
{
|
||||
center = (center == null)
|
||||
? new Location()
|
||||
: new Location(
|
||||
Math.Min(Math.Max(center.Latitude, -MapProjection.MaxLatitude), MapProjection.MaxLatitude),
|
||||
Location.NormalizeLongitude(center.Longitude));
|
||||
var c = center;
|
||||
|
||||
if (center == null)
|
||||
{
|
||||
center = new Location();
|
||||
}
|
||||
else if (
|
||||
center.Latitude < -maxLatitude || center.Latitude > maxLatitude ||
|
||||
center.Longitude < -180d || center.Longitude > 180d)
|
||||
{
|
||||
center = new Location(
|
||||
Math.Min(Math.Max(center.Latitude, -maxLatitude), maxLatitude),
|
||||
Location.NormalizeLongitude(center.Longitude));
|
||||
}
|
||||
|
||||
if (center != c)
|
||||
{
|
||||
SetValueInternal(property, center);
|
||||
}
|
||||
}
|
||||
|
|
@ -727,9 +750,9 @@ namespace MapControl
|
|||
{
|
||||
center.Longitude = Location.NormalizeLongitude(center.Longitude);
|
||||
|
||||
if (center.Latitude < -projection.MaxLatitude || center.Latitude > projection.MaxLatitude)
|
||||
if (center.Latitude < -maxLatitude || center.Latitude > maxLatitude)
|
||||
{
|
||||
center.Latitude = Math.Min(Math.Max(center.Latitude, -projection.MaxLatitude), projection.MaxLatitude);
|
||||
center.Latitude = Math.Min(Math.Max(center.Latitude, -maxLatitude), maxLatitude);
|
||||
resetTransformCenter = true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ namespace MapControl
|
|||
|
||||
var position = parentMap.LocationToView(location);
|
||||
|
||||
if (parentMap.MapProjection.IsNormalCylindrical && IsOutsideViewport(position))
|
||||
if (parentMap.MapProjection.Type <= MapProjectionType.NormalCylindrical && IsOutsideViewport(position))
|
||||
{
|
||||
location = new Location(location.Latitude, parentMap.ConstrainedLongitude(location.Longitude));
|
||||
|
||||
|
|
@ -144,7 +144,7 @@ namespace MapControl
|
|||
var center = new Point(rect.X + rect.Width / 2d, rect.Y + rect.Height / 2d);
|
||||
var position = parentMap.ViewTransform.MapToView(center);
|
||||
|
||||
if (parentMap.MapProjection.IsNormalCylindrical && IsOutsideViewport(position))
|
||||
if (parentMap.MapProjection.Type <= MapProjectionType.NormalCylindrical && IsOutsideViewport(position))
|
||||
{
|
||||
var location = parentMap.MapProjection.MapToLocation(center);
|
||||
if (location != null)
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ namespace MapControl
|
|||
{
|
||||
var longitudeOffset = 0d;
|
||||
|
||||
if (location != null && parentMap.MapProjection.IsNormalCylindrical)
|
||||
if (location != null && parentMap.MapProjection.Type <= MapProjectionType.NormalCylindrical)
|
||||
{
|
||||
var pos = parentMap.LocationToView(location);
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,15 @@ using System.Windows;
|
|||
|
||||
namespace MapControl
|
||||
{
|
||||
public enum MapProjectionType
|
||||
{
|
||||
WebMercator, // normal cylindrical projection compatible with MapTileLayer
|
||||
NormalCylindrical,
|
||||
TransverseCylindrical,
|
||||
Azimuthal,
|
||||
Other
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Defines a map projection between geographic coordinates and cartesian map coordinates.
|
||||
/// </summary>
|
||||
|
|
@ -25,30 +34,20 @@ namespace MapControl
|
|||
public static MapProjectionFactory Factory { get; set; } = new MapProjectionFactory();
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the WMS 1.3.0 CRS identifier.
|
||||
/// Gets the type of the projection.
|
||||
/// </summary>
|
||||
public string CrsId { get; set; } = string.Empty;
|
||||
public MapProjectionType Type { get; protected set; } = MapProjectionType.Other;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the WMS 1.3.0 CRS identifier.
|
||||
/// </summary>
|
||||
public string CrsId { get; protected set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the projection center.
|
||||
/// </summary>
|
||||
public Location Center { get; set; } = new Location();
|
||||
|
||||
/// <summary>
|
||||
/// Indicates if this is a normal cylindrical projection.
|
||||
/// </summary>
|
||||
public bool IsNormalCylindrical { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicates if this is a web mercator projection, i.e. compatible with MapTileLayer.
|
||||
/// </summary>
|
||||
public bool IsWebMercator { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the absolute value of the minimum and maximum latitude that can be transformed.
|
||||
/// </summary>
|
||||
public double MaxLatitude { get; protected set; } = 90d;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the relative map scale at the specified Location.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ namespace MapControl
|
|||
break;
|
||||
|
||||
case "EPSG:97003": // proprietary CRS ID
|
||||
projection = new AzimuthalEquidistantProjection { CrsId = crsId };
|
||||
projection = new AzimuthalEquidistantProjection(crsId);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ namespace MapControl
|
|||
{
|
||||
var update = false;
|
||||
|
||||
if (ParentMap == null || !ParentMap.MapProjection.IsWebMercator)
|
||||
if (ParentMap == null || ParentMap.MapProjection.Type != MapProjectionType.WebMercator)
|
||||
{
|
||||
update = TileMatrix != null;
|
||||
TileMatrix = null;
|
||||
|
|
|
|||
|
|
@ -19,10 +19,8 @@ namespace MapControl
|
|||
|
||||
public WebMercatorProjection()
|
||||
{
|
||||
Type = MapProjectionType.WebMercator;
|
||||
CrsId = DefaultCrsId;
|
||||
IsNormalCylindrical = true;
|
||||
IsWebMercator = true;
|
||||
MaxLatitude = YToLatitude(180d);
|
||||
}
|
||||
|
||||
public override Vector GetRelativeScale(Location location)
|
||||
|
|
|
|||
|
|
@ -22,9 +22,8 @@ namespace MapControl
|
|||
|
||||
public WorldMercatorProjection()
|
||||
{
|
||||
Type = MapProjectionType.NormalCylindrical;
|
||||
CrsId = DefaultCrsId;
|
||||
IsNormalCylindrical = true;
|
||||
MaxLatitude = YToLatitude(180d);
|
||||
}
|
||||
|
||||
public override Vector GetRelativeScale(Location location)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue