Added Avalonia MapOverlay and MapScale

This commit is contained in:
ClemensFischer 2024-05-24 18:24:44 +02:00
parent 192ecbf4df
commit 35c0076336
11 changed files with 210 additions and 123 deletions

View file

@ -57,17 +57,20 @@ namespace MapControl
if (parentMap != null)
{
// If this.Background is not explicitly set, bind it to parentMap.Background.
//
this.SetBindingOnUnsetProperty(BackgroundProperty, parentMap, Panel.BackgroundProperty, nameof(Background));
if (Background == null)
{
SetBinding(BackgroundProperty, parentMap.CreateBinding(nameof(Background)));
}
// If this.Foreground is not explicitly set, bind it to parentMap.Foreground.
//
this.SetBindingOnUnsetProperty(ForegroundProperty, parentMap, MapBase.ForegroundProperty, nameof(Foreground));
if (Foreground == null)
{
SetBinding(ForegroundProperty, parentMap.CreateBinding(nameof(Foreground)));
}
// If this.BorderBrush is not explicitly set, bind it to parentMap.Foreground.
//
this.SetBindingOnUnsetProperty(BorderBrushProperty, parentMap, MapBase.ForegroundProperty, nameof(Foreground));
if (BorderBrush == null)
{
SetBinding(BorderBrushProperty, parentMap.CreateBinding(nameof(Foreground)));
}
}
}
}

View file

@ -32,11 +32,13 @@ namespace MapControl
if (Children.Count == 0)
{
path.SetBinding(Shape.StrokeProperty, this.GetOrCreateBinding(StrokeProperty, nameof(Stroke)));
path.SetBinding(Shape.StrokeThicknessProperty, this.GetOrCreateBinding(StrokeThicknessProperty, nameof(StrokeThickness)));
path.SetBinding(Shape.StrokeDashArrayProperty, this.GetOrCreateBinding(StrokeDashArrayProperty, nameof(StrokeDashArray)));
path.SetBinding(Shape.StrokeDashOffsetProperty, this.GetOrCreateBinding(StrokeDashOffsetProperty, nameof(StrokeDashOffset)));
path.SetBinding(Shape.StrokeDashCapProperty, this.GetOrCreateBinding(StrokeDashCapProperty, nameof(StrokeDashCap)));
path.SetBinding(Shape.StrokeProperty, this.CreateBinding(nameof(Stroke)));
path.SetBinding(Shape.StrokeThicknessProperty, this.CreateBinding(nameof(StrokeThickness)));
path.SetBinding(Shape.StrokeStartLineCapProperty, this.CreateBinding(nameof(StrokeLineCap)));
path.SetBinding(Shape.StrokeEndLineCapProperty, this.CreateBinding(nameof(StrokeLineCap)));
path.SetBinding(Shape.StrokeDashCapProperty, this.CreateBinding(nameof(StrokeLineCap)));
path.SetBinding(Shape.StrokeDashArrayProperty, this.CreateBinding(nameof(StrokeDashArray)));
path.SetBinding(Shape.StrokeDashOffsetProperty, this.CreateBinding(nameof(StrokeDashOffset)));
Children.Add(path);
}
@ -54,15 +56,15 @@ namespace MapControl
else
{
textBlock = new TextBlock { RenderTransform = new MatrixTransform() };
textBlock.SetBinding(TextBlock.FontSizeProperty, this.GetOrCreateBinding(FontSizeProperty, nameof(FontSize)));
textBlock.SetBinding(TextBlock.FontStyleProperty, this.GetOrCreateBinding(FontStyleProperty, nameof(FontStyle)));
textBlock.SetBinding(TextBlock.FontStretchProperty, this.GetOrCreateBinding(FontStretchProperty, nameof(FontStretch)));
textBlock.SetBinding(TextBlock.FontWeightProperty, this.GetOrCreateBinding(FontWeightProperty, nameof(FontWeight)));
textBlock.SetBinding(TextBlock.ForegroundProperty, this.GetOrCreateBinding(ForegroundProperty, nameof(Foreground)));
textBlock.SetBinding(TextBlock.FontSizeProperty, this.CreateBinding(nameof(FontSize)));
textBlock.SetBinding(TextBlock.FontStyleProperty, this.CreateBinding(nameof(FontStyle)));
textBlock.SetBinding(TextBlock.FontStretchProperty, this.CreateBinding(nameof(FontStretch)));
textBlock.SetBinding(TextBlock.FontWeightProperty, this.CreateBinding(nameof(FontWeight)));
textBlock.SetBinding(TextBlock.ForegroundProperty, this.CreateBinding(nameof(Foreground)));
if (FontFamily != null)
{
textBlock.SetBinding(TextBlock.FontFamilyProperty, this.GetOrCreateBinding(FontFamilyProperty, nameof(FontFamily)));
textBlock.SetBinding(TextBlock.FontFamilyProperty, this.CreateBinding(nameof(FontFamily)));
}
Children.Add(textBlock);

View file

@ -51,14 +51,20 @@ namespace MapControl
if (parentMap != null)
{
// If this.Background is not explicitly set, bind it to parentMap.Background
this.SetBindingOnUnsetProperty(BackgroundProperty, parentMap, Panel.BackgroundProperty, nameof(Background));
if (Background == null)
{
SetBinding(BackgroundProperty, parentMap.CreateBinding(nameof(Background)));
}
// If this.Foreground is not explicitly set, bind it to parentMap.Foreground
this.SetBindingOnUnsetProperty(ForegroundProperty, parentMap, MapBase.ForegroundProperty, nameof(Foreground));
if (Foreground == null)
{
SetBinding(ForegroundProperty, parentMap.CreateBinding(nameof(Foreground)));
}
// If this.BorderBrush is not explicitly set, bind it to parentMap.Foreground
this.SetBindingOnUnsetProperty(BorderBrushProperty, parentMap, MapBase.ForegroundProperty, nameof(Foreground));
if (BorderBrush == null)
{
SetBinding(BorderBrushProperty, parentMap.CreateBinding(nameof(Foreground)));
}
}
}
}

View file

@ -5,10 +5,12 @@
using Windows.UI.Text;
#if UWP
using Windows.UI.Xaml;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Media;
#else
using Microsoft.UI.Text;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Media;
#endif
@ -46,14 +48,8 @@ namespace MapControl
public static readonly DependencyProperty StrokeDashOffsetProperty =
DependencyPropertyHelper.Register<MapOverlay, double>(nameof(StrokeDashOffset));
public static readonly DependencyProperty StrokeDashCapProperty =
DependencyPropertyHelper.Register<MapOverlay, PenLineCap>(nameof(StrokeDashCap), PenLineCap.Flat);
public static readonly DependencyProperty StrokeStartLineCapProperty =
DependencyPropertyHelper.Register<MapOverlay, PenLineCap>(nameof(StrokeStartLineCap), PenLineCap.Flat);
public static readonly DependencyProperty StrokeEndLineCapProperty =
DependencyPropertyHelper.Register<MapOverlay, PenLineCap>(nameof(StrokeEndLineCap), PenLineCap.Flat);
public static readonly DependencyProperty StrokeLineCapProperty =
DependencyPropertyHelper.Register<MapOverlay, PenLineCap>(nameof(StrokeLineCap), PenLineCap.Flat);
public static readonly DependencyProperty StrokeLineJoinProperty =
DependencyPropertyHelper.Register<MapOverlay, PenLineJoin>(nameof(StrokeLineJoin), PenLineJoin.Miter);
@ -65,13 +61,15 @@ namespace MapControl
{
if (map != null)
{
// If this.Forground is not explicitly set, bind it to map.Foreground.
//
this.SetBindingOnUnsetProperty(ForegroundProperty, map, MapBase.ForegroundProperty, nameof(Foreground));
if (Foreground == null)
{
SetBinding(ForegroundProperty, map.CreateBinding(nameof(Foreground)));
}
// If this.Stroke is not explicitly set, bind it to this.Foreground.
//
this.SetBindingOnUnsetProperty(StrokeProperty, this, ForegroundProperty, nameof(Foreground));
if (Stroke == null)
{
SetBinding(StrokeProperty, this.CreateBinding(nameof(Foreground)));
}
}
base.SetParentMap(map);