mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Updated BoundingBox
This commit is contained in:
parent
e8a34b1a9f
commit
8cdc03e411
|
|
@ -18,16 +18,11 @@ namespace MapControl
|
|||
{
|
||||
public override Rect BoundingBoxToRect(BoundingBox boundingBox)
|
||||
{
|
||||
if (boundingBox is CenteredBoundingBox cbbox)
|
||||
{
|
||||
var center = LocationToMap(cbbox.Center);
|
||||
var center = LocationToMap(boundingBox.Center);
|
||||
|
||||
return new Rect(
|
||||
center.X - cbbox.Width / 2d, center.Y - cbbox.Height / 2d,
|
||||
cbbox.Width, cbbox.Height);
|
||||
}
|
||||
|
||||
return base.BoundingBoxToRect(boundingBox);
|
||||
center.X - boundingBox.Width / 2d, center.Y - boundingBox.Height / 2d,
|
||||
boundingBox.Width, boundingBox.Height);
|
||||
}
|
||||
|
||||
public override BoundingBox RectToBoundingBox(Rect rect)
|
||||
|
|
|
|||
|
|
@ -49,16 +49,19 @@ namespace MapControl
|
|||
public virtual double Width
|
||||
{
|
||||
get { return East - West; }
|
||||
protected set { }
|
||||
}
|
||||
|
||||
public virtual double Height
|
||||
{
|
||||
get { return North - South; }
|
||||
protected set { }
|
||||
}
|
||||
|
||||
public virtual BoundingBox Clone()
|
||||
public virtual Location Center
|
||||
{
|
||||
return new BoundingBox(South, West, North, East);
|
||||
get { return new Location((South + North) / 2d, (West + East) / 2d); }
|
||||
protected set { }
|
||||
}
|
||||
|
||||
public static BoundingBox Parse(string s)
|
||||
|
|
|
|||
|
|
@ -8,31 +8,15 @@ namespace MapControl
|
|||
{
|
||||
public class CenteredBoundingBox : BoundingBox
|
||||
{
|
||||
private readonly double width;
|
||||
private readonly double height;
|
||||
|
||||
public CenteredBoundingBox(Location center, double width, double height)
|
||||
{
|
||||
Center = center;
|
||||
this.width = Math.Max(width, 0d);
|
||||
this.height = Math.Max(height, 0d);
|
||||
Width = Math.Max(width, 0d);
|
||||
Height = Math.Max(height, 0d);
|
||||
}
|
||||
|
||||
public Location Center { get; private set; }
|
||||
|
||||
public override double Width
|
||||
{
|
||||
get { return width; }
|
||||
}
|
||||
|
||||
public override double Height
|
||||
{
|
||||
get { return height; }
|
||||
}
|
||||
|
||||
public override BoundingBox Clone()
|
||||
{
|
||||
return new CenteredBoundingBox(Center, Width, Height);
|
||||
}
|
||||
public override double Width { get; protected set; }
|
||||
public override double Height { get; protected set; }
|
||||
public override Location Center { get; protected set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ using System.Windows.Controls;
|
|||
using System.Windows.Media;
|
||||
using System.Windows.Media.Animation;
|
||||
using System.Windows.Threading;
|
||||
using System.Xml.Linq;
|
||||
#endif
|
||||
|
||||
namespace MapControl
|
||||
|
|
@ -39,21 +38,6 @@ namespace MapControl
|
|||
public static readonly DependencyProperty DescriptionProperty = DependencyProperty.Register(
|
||||
nameof(Description), typeof(string), typeof(MapImageLayer), new PropertyMetadata(null));
|
||||
|
||||
public static readonly DependencyProperty MinLatitudeProperty = DependencyProperty.Register(
|
||||
nameof(MinLatitude), typeof(double), typeof(MapImageLayer), new PropertyMetadata(double.NaN));
|
||||
|
||||
public static readonly DependencyProperty MaxLatitudeProperty = DependencyProperty.Register(
|
||||
nameof(MaxLatitude), typeof(double), typeof(MapImageLayer), new PropertyMetadata(double.NaN));
|
||||
|
||||
public static readonly DependencyProperty MinLongitudeProperty = DependencyProperty.Register(
|
||||
nameof(MinLongitude), typeof(double), typeof(MapImageLayer), new PropertyMetadata(double.NaN));
|
||||
|
||||
public static readonly DependencyProperty MaxLongitudeProperty = DependencyProperty.Register(
|
||||
nameof(MaxLongitude), typeof(double), typeof(MapImageLayer), new PropertyMetadata(double.NaN));
|
||||
|
||||
public static readonly DependencyProperty MaxBoundingBoxWidthProperty = DependencyProperty.Register(
|
||||
nameof(MaxBoundingBoxWidth), typeof(double), typeof(MapImageLayer), new PropertyMetadata(double.NaN));
|
||||
|
||||
public static readonly DependencyProperty RelativeImageSizeProperty = DependencyProperty.Register(
|
||||
nameof(RelativeImageSize), typeof(double), typeof(MapImageLayer), new PropertyMetadata(1d));
|
||||
|
||||
|
|
@ -92,51 +76,6 @@ namespace MapControl
|
|||
set { SetValue(DescriptionProperty, value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Optional minimum latitude value. Default is NaN.
|
||||
/// </summary>
|
||||
public double MinLatitude
|
||||
{
|
||||
get { return (double)GetValue(MinLatitudeProperty); }
|
||||
set { SetValue(MinLatitudeProperty, value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Optional maximum latitude value. Default is NaN.
|
||||
/// </summary>
|
||||
public double MaxLatitude
|
||||
{
|
||||
get { return (double)GetValue(MaxLatitudeProperty); }
|
||||
set { SetValue(MaxLatitudeProperty, value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Optional minimum longitude value. Default is NaN.
|
||||
/// </summary>
|
||||
public double MinLongitude
|
||||
{
|
||||
get { return (double)GetValue(MinLongitudeProperty); }
|
||||
set { SetValue(MinLongitudeProperty, value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Optional maximum longitude value. Default is NaN.
|
||||
/// </summary>
|
||||
public double MaxLongitude
|
||||
{
|
||||
get { return (double)GetValue(MaxLongitudeProperty); }
|
||||
set { SetValue(MaxLongitudeProperty, value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Optional maximum width of the map image's bounding box. Default is NaN.
|
||||
/// </summary>
|
||||
public double MaxBoundingBoxWidth
|
||||
{
|
||||
get { return (double)GetValue(MaxBoundingBoxWidthProperty); }
|
||||
set { SetValue(MaxBoundingBoxWidthProperty, value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Relative size of the map image in relation to the current view size.
|
||||
/// Setting a value greater than one will let MapImageLayer request images that
|
||||
|
|
@ -271,46 +210,20 @@ namespace MapControl
|
|||
var rect = new Rect(x, y, width, height);
|
||||
|
||||
BoundingBox = ParentMap.ViewRectToBoundingBox(rect);
|
||||
|
||||
if (BoundingBox != null)
|
||||
{
|
||||
if (!double.IsNaN(MinLatitude) && BoundingBox.South < MinLatitude)
|
||||
{
|
||||
BoundingBox.South = MinLatitude;
|
||||
}
|
||||
|
||||
if (!double.IsNaN(MinLongitude) && BoundingBox.West < MinLongitude)
|
||||
{
|
||||
BoundingBox.West = MinLongitude;
|
||||
}
|
||||
|
||||
if (!double.IsNaN(MaxLatitude) && BoundingBox.North > MaxLatitude)
|
||||
{
|
||||
BoundingBox.North = MaxLatitude;
|
||||
}
|
||||
|
||||
if (!double.IsNaN(MaxLongitude) && BoundingBox.East > MaxLongitude)
|
||||
{
|
||||
BoundingBox.East = MaxLongitude;
|
||||
}
|
||||
|
||||
if (!double.IsNaN(MaxBoundingBoxWidth) && BoundingBox.Width > MaxBoundingBoxWidth)
|
||||
{
|
||||
var margin = (BoundingBox.Width - MaxBoundingBoxWidth) / 2d;
|
||||
BoundingBox.West += margin;
|
||||
BoundingBox.East -= margin;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void AdjustBoundingBox(double longitudeOffset)
|
||||
{
|
||||
if (Math.Abs(longitudeOffset) > 180d && BoundingBox != null)
|
||||
if (Math.Abs(longitudeOffset) > 180d &&
|
||||
BoundingBox != null &&
|
||||
BoundingBox.West < BoundingBox.East && // not an azimuthal projection
|
||||
BoundingBox.South < BoundingBox.North)
|
||||
{
|
||||
var offset = 360d * Math.Sign(longitudeOffset);
|
||||
|
||||
BoundingBox.West += offset;
|
||||
BoundingBox.East += offset;
|
||||
BoundingBox = new BoundingBox(
|
||||
BoundingBox.South, BoundingBox.West + offset,
|
||||
BoundingBox.North, BoundingBox.East + offset);
|
||||
|
||||
foreach (var image in Children.OfType<Image>())
|
||||
{
|
||||
|
|
@ -344,7 +257,7 @@ namespace MapControl
|
|||
Children.Insert(1, topImage);
|
||||
|
||||
topImage.Source = image;
|
||||
SetBoundingBox(topImage, BoundingBox?.Clone());
|
||||
SetBoundingBox(topImage, BoundingBox);
|
||||
|
||||
topImage.BeginAnimation(OpacityProperty, new DoubleAnimation
|
||||
{
|
||||
|
|
|
|||
|
|
@ -197,6 +197,7 @@
|
|||
</tools:MapLayersMenuButton>
|
||||
|
||||
<tools:MapProjectionsMenuButton
|
||||
x:Name="mapProjectionsMenuButton"
|
||||
Margin="2" Padding="8" ToolTipService.ToolTip="Map Projections"
|
||||
Map="{Binding ElementName=map}">
|
||||
<tools:MapProjectionItem Text="Web Mercator" Projection="EPSG:3857"/>
|
||||
|
|
|
|||
|
|
@ -72,8 +72,12 @@ namespace SampleApplication
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
AddChartServerLayer();
|
||||
}
|
||||
|
||||
partial void AddChartServerLayer();
|
||||
|
||||
private void ResetHeadingButtonClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
map.TargetHeading = 0d;
|
||||
|
|
|
|||
Loading…
Reference in a new issue