mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Version 4.9.0: Reworked MapPanel child arrangement.
This commit is contained in:
parent
56d376c4d0
commit
5a05e9284a
|
|
@ -20,31 +20,6 @@ namespace MapControl
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class MapOverlay : MapPanel
|
public partial class MapOverlay : MapPanel
|
||||||
{
|
{
|
||||||
public MapOverlay()
|
|
||||||
{
|
|
||||||
Loaded += (s, e) =>
|
|
||||||
{
|
|
||||||
#if WINDOWS_UWP
|
|
||||||
if (Foreground == null)
|
|
||||||
{
|
|
||||||
SetBinding(ForegroundProperty, new Binding
|
|
||||||
{
|
|
||||||
Source = this,
|
|
||||||
Path = new PropertyPath("ParentMap.Foreground")
|
|
||||||
});
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if (Stroke == null)
|
|
||||||
{
|
|
||||||
SetBinding(StrokeProperty, new Binding
|
|
||||||
{
|
|
||||||
Source = this,
|
|
||||||
Path = new PropertyPath("Foreground")
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public double FontSize
|
public double FontSize
|
||||||
{
|
{
|
||||||
get { return (double)GetValue(FontSizeProperty); }
|
get { return (double)GetValue(FontSizeProperty); }
|
||||||
|
|
@ -134,5 +109,82 @@ namespace MapControl
|
||||||
get { return (double)GetValue(StrokeMiterLimitProperty); }
|
get { return (double)GetValue(StrokeMiterLimitProperty); }
|
||||||
set { SetValue(StrokeMiterLimitProperty, value); }
|
set { SetValue(StrokeMiterLimitProperty, value); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
return GetBindingExpression(property)?.ParentBinding ??
|
||||||
|
new Binding { Source = this, Path = new PropertyPath(propertyName) };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -72,21 +72,23 @@ namespace MapControl
|
||||||
public MapBase ParentMap
|
public MapBase ParentMap
|
||||||
{
|
{
|
||||||
get { return parentMap; }
|
get { return parentMap; }
|
||||||
set
|
set { SetParentMap(value); }
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void SetParentMap(MapBase map)
|
||||||
|
{
|
||||||
|
if (parentMap != null && parentMap != this)
|
||||||
{
|
{
|
||||||
if (parentMap != null && parentMap != this)
|
parentMap.ViewportChanged -= OnViewportChanged;
|
||||||
{
|
}
|
||||||
parentMap.ViewportChanged -= OnViewportChanged;
|
|
||||||
}
|
|
||||||
|
|
||||||
parentMap = value;
|
parentMap = map;
|
||||||
|
|
||||||
if (parentMap != null && parentMap != this)
|
if (parentMap != null && parentMap != this)
|
||||||
{
|
{
|
||||||
parentMap.ViewportChanged += OnViewportChanged;
|
parentMap.ViewportChanged += OnViewportChanged;
|
||||||
|
|
||||||
OnViewportChanged(new ViewportChangedEventArgs());
|
OnViewportChanged(new ViewportChangedEventArgs());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,32 +34,15 @@ namespace MapControl
|
||||||
public MapScale()
|
public MapScale()
|
||||||
{
|
{
|
||||||
IsHitTestVisible = false;
|
IsHitTestVisible = false;
|
||||||
#if WINDOWS_UWP
|
|
||||||
MinWidth = 100d;
|
MinWidth = 100d;
|
||||||
#else
|
|
||||||
SetCurrentValue(MinWidthProperty, 100d);
|
|
||||||
#endif
|
|
||||||
label.HorizontalAlignment = HorizontalAlignment.Left;
|
label.HorizontalAlignment = HorizontalAlignment.Left;
|
||||||
label.VerticalAlignment = VerticalAlignment.Top;
|
label.VerticalAlignment = VerticalAlignment.Top;
|
||||||
label.TextAlignment = TextAlignment.Center;
|
label.TextAlignment = TextAlignment.Center;
|
||||||
|
label.SetBinding(TextBlock.ForegroundProperty, ForegroundBinding);
|
||||||
|
|
||||||
label.SetBinding(TextBlock.ForegroundProperty, new Binding
|
line.SetBinding(Shape.StrokeProperty, StrokeBinding);
|
||||||
{
|
line.SetBinding(Shape.StrokeThicknessProperty, StrokeThicknessBinding);
|
||||||
Source = this,
|
|
||||||
Path = new PropertyPath("Foreground")
|
|
||||||
});
|
|
||||||
|
|
||||||
line.SetBinding(Shape.StrokeProperty, new Binding
|
|
||||||
{
|
|
||||||
Source = this,
|
|
||||||
Path = new PropertyPath("Stroke")
|
|
||||||
});
|
|
||||||
|
|
||||||
line.SetBinding(Shape.StrokeThicknessProperty, new Binding
|
|
||||||
{
|
|
||||||
Source = this,
|
|
||||||
Path = new PropertyPath("StrokeThickness")
|
|
||||||
});
|
|
||||||
|
|
||||||
Children.Add(line);
|
Children.Add(line);
|
||||||
Children.Add(label);
|
Children.Add(label);
|
||||||
|
|
|
||||||
|
|
@ -30,12 +30,12 @@ namespace MapControl
|
||||||
{
|
{
|
||||||
if (path == null)
|
if (path == null)
|
||||||
{
|
{
|
||||||
path = new Path
|
path = new Path { Data = new PathGeometry() };
|
||||||
{
|
path.SetBinding(Shape.StrokeProperty, StrokeBinding);
|
||||||
Data = new PathGeometry()
|
path.SetBinding(Shape.StrokeThicknessProperty, StrokeThicknessBinding);
|
||||||
};
|
path.SetBinding(Shape.StrokeDashArrayProperty, StrokeDashArrayBinding);
|
||||||
|
path.SetBinding(Shape.StrokeDashOffsetProperty, StrokeDashOffsetBinding);
|
||||||
SetStrokeBindings(path);
|
path.SetBinding(Shape.StrokeDashCapProperty, StrokeDashCapBinding);
|
||||||
Children.Add(path);
|
Children.Add(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -115,31 +115,14 @@ namespace MapControl
|
||||||
renderTransform.Children.Add(ParentMap.RotateTransform);
|
renderTransform.Children.Add(ParentMap.RotateTransform);
|
||||||
renderTransform.Children.Add(new TranslateTransform());
|
renderTransform.Children.Add(new TranslateTransform());
|
||||||
|
|
||||||
label = new TextBlock
|
label = new TextBlock { RenderTransform = renderTransform };
|
||||||
{
|
label.SetBinding(TextBlock.ForegroundProperty, ForegroundBinding);
|
||||||
RenderTransform = renderTransform
|
|
||||||
};
|
|
||||||
|
|
||||||
label.SetBinding(TextBlock.ForegroundProperty, new Binding
|
|
||||||
{
|
|
||||||
Source = this,
|
|
||||||
Path = new PropertyPath("Foreground")
|
|
||||||
});
|
|
||||||
|
|
||||||
Children.Add(label);
|
Children.Add(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
childIndex++;
|
childIndex++;
|
||||||
|
|
||||||
if (FontFamily != null)
|
|
||||||
{
|
|
||||||
label.FontFamily = FontFamily;
|
|
||||||
}
|
|
||||||
|
|
||||||
label.FontSize = FontSize;
|
|
||||||
label.FontStyle = FontStyle;
|
|
||||||
label.FontStretch = FontStretch;
|
|
||||||
label.FontWeight = FontWeight;
|
|
||||||
label.Text = GetLabelText(lat, labelFormat, "NS") + "\n" + GetLabelText(Location.NormalizeLongitude(lon), labelFormat, "EW");
|
label.Text = GetLabelText(lat, labelFormat, "NS") + "\n" + GetLabelText(Location.NormalizeLongitude(lon), labelFormat, "EW");
|
||||||
label.Tag = new Location(lat, lon);
|
label.Tag = new Location(lat, lon);
|
||||||
label.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
|
label.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,7 @@
|
||||||
|
|
||||||
using Windows.UI.Text;
|
using Windows.UI.Text;
|
||||||
using Windows.UI.Xaml;
|
using Windows.UI.Xaml;
|
||||||
using Windows.UI.Xaml.Data;
|
|
||||||
using Windows.UI.Xaml.Media;
|
using Windows.UI.Xaml.Media;
|
||||||
using Windows.UI.Xaml.Shapes;
|
|
||||||
|
|
||||||
namespace MapControl
|
namespace MapControl
|
||||||
{
|
{
|
||||||
|
|
@ -56,62 +54,5 @@ namespace MapControl
|
||||||
|
|
||||||
public static readonly DependencyProperty StrokeMiterLimitProperty = DependencyProperty.Register(
|
public static readonly DependencyProperty StrokeMiterLimitProperty = DependencyProperty.Register(
|
||||||
nameof(StrokeMiterLimit), typeof(double), typeof(MapOverlay), new PropertyMetadata(1d));
|
nameof(StrokeMiterLimit), typeof(double), typeof(MapOverlay), new PropertyMetadata(1d));
|
||||||
|
|
||||||
public void SetStrokeBindings(Shape shape)
|
|
||||||
{
|
|
||||||
shape.SetBinding(Shape.StrokeProperty, new Binding
|
|
||||||
{
|
|
||||||
Source = this,
|
|
||||||
Path = new PropertyPath("Stroke")
|
|
||||||
});
|
|
||||||
|
|
||||||
shape.SetBinding(Shape.StrokeThicknessProperty, new Binding
|
|
||||||
{
|
|
||||||
Source = this,
|
|
||||||
Path = new PropertyPath("StrokeThickness")
|
|
||||||
});
|
|
||||||
|
|
||||||
shape.SetBinding(Shape.StrokeDashArrayProperty, new Binding
|
|
||||||
{
|
|
||||||
Source = this,
|
|
||||||
Path = new PropertyPath("StrokeDashArray")
|
|
||||||
});
|
|
||||||
|
|
||||||
shape.SetBinding(Shape.StrokeDashOffsetProperty, new Binding
|
|
||||||
{
|
|
||||||
Source = this,
|
|
||||||
Path = new PropertyPath("StrokeDashOffset")
|
|
||||||
});
|
|
||||||
|
|
||||||
shape.SetBinding(Shape.StrokeDashCapProperty, new Binding
|
|
||||||
{
|
|
||||||
Source = this,
|
|
||||||
Path = new PropertyPath("StrokeDashCap")
|
|
||||||
});
|
|
||||||
|
|
||||||
shape.SetBinding(Shape.StrokeStartLineCapProperty, new Binding
|
|
||||||
{
|
|
||||||
Source = this,
|
|
||||||
Path = new PropertyPath("StrokeStartLineCap")
|
|
||||||
});
|
|
||||||
|
|
||||||
shape.SetBinding(Shape.StrokeEndLineCapProperty, new Binding
|
|
||||||
{
|
|
||||||
Source = this,
|
|
||||||
Path = new PropertyPath("StrokeEndLineCap")
|
|
||||||
});
|
|
||||||
|
|
||||||
shape.SetBinding(Shape.StrokeLineJoinProperty, new Binding
|
|
||||||
{
|
|
||||||
Source = this,
|
|
||||||
Path = new PropertyPath("StrokeLineJoin")
|
|
||||||
});
|
|
||||||
|
|
||||||
shape.SetBinding(Shape.StrokeMiterLimitProperty, new Binding
|
|
||||||
{
|
|
||||||
Source = this,
|
|
||||||
Path = new PropertyPath("StrokeMiterLimit")
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue