mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Simplify BoundingBox
This commit is contained in:
parent
142e86da31
commit
d8c416d552
|
|
@ -3,9 +3,6 @@
|
||||||
// Licensed under the Microsoft Public License (Ms-PL)
|
// Licensed under the Microsoft Public License (Ms-PL)
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
#if !WINUI && !UWP
|
|
||||||
using System.Windows;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace MapControl
|
namespace MapControl
|
||||||
{
|
{
|
||||||
|
|
@ -19,23 +16,6 @@ namespace MapControl
|
||||||
Type = MapProjectionType.Azimuthal;
|
Type = MapProjectionType.Azimuthal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override MapRect BoundingBoxToMapRect(BoundingBox boundingBox)
|
|
||||||
{
|
|
||||||
var center = LocationToMap(boundingBox.Center);
|
|
||||||
|
|
||||||
if (!center.HasValue)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
var width = boundingBox.Width * Wgs84MeterPerDegree;
|
|
||||||
var height = boundingBox.Height * Wgs84MeterPerDegree;
|
|
||||||
var x = center.Value.X - width / 2d;
|
|
||||||
var y = center.Value.Y - height / 2d;
|
|
||||||
|
|
||||||
return new MapRect(x, y, x + width, y + height);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override BoundingBox MapRectToBoundingBox(MapRect mapRect)
|
public override BoundingBox MapRectToBoundingBox(MapRect mapRect)
|
||||||
{
|
{
|
||||||
var center = MapToLocation(mapRect.Center);
|
var center = MapToLocation(mapRect.Center);
|
||||||
|
|
|
||||||
|
|
@ -39,9 +39,6 @@ namespace MapControl
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public double West { get; set; }
|
|
||||||
public double East { get; set; }
|
|
||||||
|
|
||||||
public double South
|
public double South
|
||||||
{
|
{
|
||||||
get => south;
|
get => south;
|
||||||
|
|
@ -54,20 +51,16 @@ namespace MapControl
|
||||||
set => north = Math.Min(Math.Max(value, -90d), 90d);
|
set => north = Math.Min(Math.Max(value, -90d), 90d);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual double Width
|
public double West { get; set; }
|
||||||
{
|
public double East { get; set; }
|
||||||
get => East - West;
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual double Height
|
public virtual double Width => East - West;
|
||||||
{
|
public virtual double Height => North - South;
|
||||||
get => North - South;
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual Location Center
|
public virtual Location Center =>
|
||||||
{
|
double.IsNaN(South) || double.IsNaN(North) || double.IsNaN(West) || double.IsNaN(East)
|
||||||
get => new Location((South + North) / 2d, (West + East) / 2d);
|
? null
|
||||||
}
|
: new Location((South + North) / 2d, (West + East) / 2d);
|
||||||
|
|
||||||
public static BoundingBox Parse(string boundingBox)
|
public static BoundingBox Parse(string boundingBox)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -71,11 +71,34 @@ namespace MapControl
|
||||||
/// Returns null when the BoundingBox can not be transformed.
|
/// Returns null when the BoundingBox can not be transformed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual MapRect BoundingBoxToMapRect(BoundingBox boundingBox)
|
public virtual MapRect BoundingBoxToMapRect(BoundingBox boundingBox)
|
||||||
|
{
|
||||||
|
if (!double.IsNaN(boundingBox.South) && !double.IsNaN(boundingBox.West) &&
|
||||||
|
!double.IsNaN(boundingBox.North) && !double.IsNaN(boundingBox.East))
|
||||||
{
|
{
|
||||||
var p1 = LocationToMap(new Location(boundingBox.South, boundingBox.West));
|
var p1 = LocationToMap(new Location(boundingBox.South, boundingBox.West));
|
||||||
var p2 = LocationToMap(new Location(boundingBox.North, boundingBox.East));
|
var p2 = LocationToMap(new Location(boundingBox.North, boundingBox.East));
|
||||||
|
|
||||||
return p1.HasValue && p2.HasValue ? new MapRect(p1.Value, p2.Value) : null;
|
if (p1.HasValue && p2.HasValue)
|
||||||
|
{
|
||||||
|
return new MapRect(p1.Value, p2.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (boundingBox.Center != null)
|
||||||
|
{
|
||||||
|
var center = LocationToMap(boundingBox.Center);
|
||||||
|
|
||||||
|
if (center.HasValue)
|
||||||
|
{
|
||||||
|
var width = boundingBox.Width * Wgs84MeterPerDegree;
|
||||||
|
var height = boundingBox.Height * Wgs84MeterPerDegree;
|
||||||
|
var x = center.Value.X - width / 2d;
|
||||||
|
var y = center.Value.Y - height / 2d;
|
||||||
|
|
||||||
|
return new MapRect(x, y, x + width, y + height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -84,10 +107,12 @@ namespace MapControl
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual BoundingBox MapRectToBoundingBox(MapRect mapRect)
|
public virtual BoundingBox MapRectToBoundingBox(MapRect mapRect)
|
||||||
{
|
{
|
||||||
var sw = MapToLocation(new Point(mapRect.XMin, mapRect.YMin));
|
var southWest = MapToLocation(new Point(mapRect.XMin, mapRect.YMin));
|
||||||
var ne = MapToLocation(new Point(mapRect.XMax, mapRect.YMax));
|
var northEast = MapToLocation(new Point(mapRect.XMax, mapRect.YMax));
|
||||||
|
|
||||||
return sw != null && ne != null ? new BoundingBox(sw, ne) : null;
|
return southWest != null && northEast != null
|
||||||
|
? new BoundingBox(southWest, northEast)
|
||||||
|
: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue