mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-05 14:37:01 +00:00
BoundingBox now immutable
This commit is contained in:
parent
dc9932a0cf
commit
2685792758
8 changed files with 61 additions and 105 deletions
|
|
@ -10,26 +10,21 @@ namespace MapControl
|
|||
/// <summary>
|
||||
/// A geographic bounding box with south and north latitude and west and east longitude values in degrees.
|
||||
/// </summary>
|
||||
#if !UWP
|
||||
#if WINUI || UWP
|
||||
[Windows.Foundation.Metadata.CreateFromString(MethodName = "MapControl.BoundingBox.Parse")]
|
||||
#else
|
||||
[System.ComponentModel.TypeConverter(typeof(BoundingBoxConverter))]
|
||||
#endif
|
||||
public class BoundingBox
|
||||
{
|
||||
private double south;
|
||||
private double north;
|
||||
|
||||
public BoundingBox()
|
||||
{
|
||||
south = double.NaN;
|
||||
north = double.NaN;
|
||||
West = double.NaN;
|
||||
East = double.NaN;
|
||||
}
|
||||
|
||||
public BoundingBox(double latitude1, double longitude1, double latitude2, double longitude2)
|
||||
{
|
||||
South = Math.Min(latitude1, latitude2);
|
||||
North = Math.Max(latitude1, latitude2);
|
||||
South = Math.Min(Math.Max(Math.Min(latitude1, latitude2), -90d), 90d);
|
||||
North = Math.Min(Math.Max(Math.Max(latitude1, latitude2), -90d), 90d);
|
||||
West = Math.Min(longitude1, longitude2);
|
||||
East = Math.Max(longitude1, longitude2);
|
||||
}
|
||||
|
|
@ -39,28 +34,15 @@ namespace MapControl
|
|||
{
|
||||
}
|
||||
|
||||
public double South
|
||||
{
|
||||
get => south;
|
||||
set => south = Math.Min(Math.Max(value, -90d), 90d);
|
||||
}
|
||||
|
||||
public double North
|
||||
{
|
||||
get => north;
|
||||
set => north = Math.Min(Math.Max(value, -90d), 90d);
|
||||
}
|
||||
|
||||
public double West { get; set; }
|
||||
public double East { get; set; }
|
||||
public double South { get; }
|
||||
public double North { get; }
|
||||
public double West { get; }
|
||||
public double East { get; }
|
||||
|
||||
public virtual double Width => East - West;
|
||||
public virtual double Height => North - South;
|
||||
|
||||
public virtual Location Center =>
|
||||
HasValidBounds ? new Location((South + North) / 2d, (West + East) / 2d) : null;
|
||||
|
||||
public virtual bool HasValidBounds => South < North && West < East;
|
||||
public virtual Location Center => new Location((South + North) / 2d, (West + East) / 2d);
|
||||
|
||||
public static BoundingBox Parse(string boundingBox)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ namespace MapControl
|
|||
height = Math.Max(h, 0d);
|
||||
}
|
||||
|
||||
public override bool HasValidBounds => false;
|
||||
public override Location Center => center;
|
||||
public override double Width => width;
|
||||
public override double Height => height;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,9 @@ namespace MapControl
|
|||
/// A collection of Locations with support for string parsing
|
||||
/// and calculation of great circle and rhumb line locations.
|
||||
/// </summary>
|
||||
#if !UWP
|
||||
#if WINUI || UWP
|
||||
[Windows.Foundation.Metadata.CreateFromString(MethodName = "MapControl.LocationCollection.Parse")]
|
||||
#else
|
||||
[System.ComponentModel.TypeConverter(typeof(LocationCollectionConverter))]
|
||||
#endif
|
||||
public class LocationCollection : List<Location>
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ namespace MapControl
|
|||
{
|
||||
MapRect mapRect = null;
|
||||
|
||||
if (boundingBox.HasValidBounds)
|
||||
if (boundingBox.South < boundingBox.North && boundingBox.West < boundingBox.East)
|
||||
{
|
||||
var p1 = LocationToMap(new Location(boundingBox.South, boundingBox.West));
|
||||
var p2 = LocationToMap(new Location(boundingBox.North, boundingBox.East));
|
||||
|
|
|
|||
|
|
@ -17,7 +17,9 @@ namespace MapControl
|
|||
/// <summary>
|
||||
/// Provides the download Uri or ImageSource of map tiles.
|
||||
/// </summary>
|
||||
#if !UWP
|
||||
#if WINUI || UWP
|
||||
[Windows.Foundation.Metadata.CreateFromString(MethodName = "MapControl.TileSource.Parse")]
|
||||
#else
|
||||
[System.ComponentModel.TypeConverter(typeof(TileSourceConverter))]
|
||||
#endif
|
||||
public class TileSource
|
||||
|
|
@ -81,6 +83,11 @@ namespace MapControl
|
|||
|
||||
return uri != null ? ImageLoader.LoadImageAsync(uri) : Task.FromResult((ImageSource)null);
|
||||
}
|
||||
|
||||
public static TileSource Parse(string uriTemplate)
|
||||
{
|
||||
return new TileSource { UriTemplate = uriTemplate };
|
||||
}
|
||||
}
|
||||
|
||||
public class TmsTileSource : TileSource
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ namespace MapControl
|
|||
|
||||
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
|
||||
{
|
||||
return new TileSource { UriTemplate = (string)value };
|
||||
return TileSource.Parse((string)value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue