Version 4.9.0: Reworked MapPanel child arrangement.

This commit is contained in:
ClemensF 2018-05-01 12:45:19 +02:00
parent ea2cd438fa
commit 452e2a5454
9 changed files with 104 additions and 172 deletions

View file

@ -10,7 +10,9 @@ using Windows.UI.Xaml.Media;
#else
using System.Windows;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Shapes;
#endif
namespace MapControl
@ -20,10 +22,15 @@ namespace MapControl
/// </summary>
public partial class MapOverlay : MapPanel
{
public double FontSize
public MapOverlay()
{
get { return (double)GetValue(FontSizeProperty); }
set { SetValue(FontSizeProperty, value); }
Loaded += (s, e) =>
{
if (Stroke == null)
{
SetBinding(StrokeProperty, GetBinding(ForegroundProperty, nameof(Foreground)));
}
};
}
public FontFamily FontFamily
@ -32,6 +39,12 @@ namespace MapControl
set { SetValue(FontFamilyProperty, value); }
}
public double FontSize
{
get { return (double)GetValue(FontSizeProperty); }
set { SetValue(FontSizeProperty, value); }
}
public FontStyle FontStyle
{
get { return (FontStyle)GetValue(FontStyleProperty); }
@ -110,103 +123,7 @@ namespace MapControl
set { SetValue(StrokeMiterLimitProperty, value); }
}
public Binding FontSizeBinding
{
get { return GetBinding(FontSizeProperty, nameof(FontSize)); }
}
public Binding FontFamilyBinding
{
get { return GetBinding(FontFamilyProperty, nameof(FontFamily)); }
}
public Binding FontStyleBinding
{
get { return GetBinding(FontStyleProperty, nameof(FontStyle)); }
}
public Binding FontStretchBinding
{
get { return GetBinding(FontStretchProperty, nameof(FontStretch)); }
}
public Binding FontWeightBinding
{
get { return GetBinding(FontWeightProperty, nameof(FontWeight)); }
}
public Binding ForegroundBinding
{
get { return GetBinding(ForegroundProperty, nameof(Foreground)); }
}
public Binding StrokeBinding
{
get { return GetBinding(StrokeProperty, nameof(Stroke)); }
}
public Binding StrokeThicknessBinding
{
get { return GetBinding(StrokeThicknessProperty, nameof(StrokeThickness)); }
}
public Binding StrokeDashArrayBinding
{
get { return GetBinding(StrokeDashArrayProperty, nameof(StrokeDashArray)); }
}
public Binding StrokeDashOffsetBinding
{
get { return GetBinding(StrokeDashOffsetProperty, nameof(StrokeDashOffset)); }
}
public Binding StrokeDashCapBinding
{
get { return GetBinding(StrokeDashCapProperty, nameof(StrokeDashCap)); }
}
public Binding StrokeStartLineCapBinding
{
get { return GetBinding(StrokeStartLineCapProperty, nameof(StrokeStartLineCap)); }
}
public Binding StrokeEndLineCapBinding
{
get { return GetBinding(StrokeEndLineCapProperty, nameof(StrokeEndLineCap)); }
}
public Binding StrokeLineJoinBinding
{
get { return GetBinding(StrokeLineJoinProperty, nameof(StrokeLineJoin)); }
}
public Binding StrokeMiterLimitBinding
{
get { return GetBinding(StrokeMiterLimitProperty, nameof(StrokeMiterLimit)); }
}
protected override void SetParentMap(MapBase map)
{
if (map != null)
{
#if WINDOWS_UWP
if (Foreground == null)
{
SetBinding(ForegroundProperty,
map.GetBindingExpression(MapBase.ForegroundProperty)?.ParentBinding ??
new Binding { Source = map, Path = new PropertyPath("Foreground") });
}
#endif
if (Stroke == null)
{
SetBinding(StrokeProperty, ForegroundBinding);
}
}
base.SetParentMap(map);
}
private Binding GetBinding(DependencyProperty property, string propertyName)
protected Binding GetBinding(DependencyProperty property, string propertyName)
{
return GetBindingExpression(property)?.ParentBinding ??
new Binding { Source = this, Path = new PropertyPath(propertyName) };

View file

@ -92,6 +92,16 @@ namespace MapControl
}
}
private void OnViewportChanged(object sender, ViewportChangedEventArgs e)
{
OnViewportChanged(e);
}
protected virtual void OnViewportChanged(ViewportChangedEventArgs e)
{
InvalidateArrange();
}
protected override Size MeasureOverride(Size availableSize)
{
availableSize = new Size(double.PositiveInfinity, double.PositiveInfinity);
@ -131,16 +141,6 @@ namespace MapControl
return finalSize;
}
protected virtual void OnViewportChanged(ViewportChangedEventArgs e)
{
InvalidateArrange();
}
private void OnViewportChanged(object sender, ViewportChangedEventArgs e)
{
OnViewportChanged(e);
}
private static void ParentMapPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
{
var mapElement = obj as IMapElement;

View file

@ -28,21 +28,22 @@ namespace MapControl
public static readonly DependencyProperty PaddingProperty = DependencyProperty.Register(
nameof(Padding), typeof(Thickness), typeof(MapScale), new PropertyMetadata(new Thickness(4)));
private TextBlock label = new TextBlock();
private Polyline line = new Polyline();
private readonly Polyline line = new Polyline();
private readonly TextBlock label = new TextBlock
{
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Top,
TextAlignment = TextAlignment.Center
};
public MapScale()
{
IsHitTestVisible = false;
MinWidth = 100d;
label.HorizontalAlignment = HorizontalAlignment.Left;
label.VerticalAlignment = VerticalAlignment.Top;
label.TextAlignment = TextAlignment.Center;
label.SetBinding(TextBlock.ForegroundProperty, ForegroundBinding);
line.SetBinding(Shape.StrokeProperty, StrokeBinding);
line.SetBinding(Shape.StrokeThicknessProperty, StrokeThicknessBinding);
line.SetBinding(Shape.StrokeProperty, GetBinding(StrokeProperty, nameof(Stroke)));
line.SetBinding(Shape.StrokeThicknessProperty, GetBinding(StrokeThicknessProperty, nameof(StrokeThickness)));
Children.Add(line);
Children.Add(label);
@ -91,18 +92,8 @@ namespace MapControl
new Point(x2, y2),
new Point(x2, y1)
};
line.Measure(size);
if (FontFamily != null)
{
label.FontFamily = FontFamily;
}
label.FontSize = FontSize;
label.FontStyle = FontStyle;
label.FontStretch = FontStretch;
label.FontWeight = FontWeight;
label.Text = length >= 1000d ? string.Format("{0:0} km", length / 1000d) : string.Format("{0:0} m", length);
label.Width = size.Width;
label.Height = size.Height;