mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-05-07 13:37:47 +00:00
File scoped namespaces
This commit is contained in:
parent
c14377f976
commit
65aba44af6
152 changed files with 11962 additions and 12115 deletions
|
|
@ -14,129 +14,128 @@ using Microsoft.UI.Xaml.Media;
|
|||
using Microsoft.UI.Xaml.Shapes;
|
||||
#endif
|
||||
|
||||
namespace MapControl
|
||||
namespace MapControl;
|
||||
|
||||
public partial class MapGrid : MapPanel
|
||||
{
|
||||
public partial class MapGrid : MapPanel
|
||||
public static readonly DependencyProperty ForegroundProperty =
|
||||
DependencyPropertyHelper.Register<MapGrid, Brush>(nameof(Foreground));
|
||||
|
||||
public static readonly DependencyProperty FontFamilyProperty =
|
||||
DependencyPropertyHelper.Register<MapGrid, FontFamily>(nameof(FontFamily));
|
||||
|
||||
public static readonly DependencyProperty FontSizeProperty =
|
||||
DependencyPropertyHelper.Register<MapGrid, double>(nameof(FontSize), 12d);
|
||||
|
||||
protected override void SetParentMap(MapBase map)
|
||||
{
|
||||
public static readonly DependencyProperty ForegroundProperty =
|
||||
DependencyPropertyHelper.Register<MapGrid, Brush>(nameof(Foreground));
|
||||
|
||||
public static readonly DependencyProperty FontFamilyProperty =
|
||||
DependencyPropertyHelper.Register<MapGrid, FontFamily>(nameof(FontFamily));
|
||||
|
||||
public static readonly DependencyProperty FontSizeProperty =
|
||||
DependencyPropertyHelper.Register<MapGrid, double>(nameof(FontSize), 12d);
|
||||
|
||||
protected override void SetParentMap(MapBase map)
|
||||
if (map != null && Foreground == null)
|
||||
{
|
||||
if (map != null && Foreground == null)
|
||||
{
|
||||
SetBinding(ForegroundProperty,
|
||||
new Binding { Source = map, Path = new PropertyPath(nameof(Foreground)) });
|
||||
}
|
||||
|
||||
base.SetParentMap(map);
|
||||
SetBinding(ForegroundProperty,
|
||||
new Binding { Source = map, Path = new PropertyPath(nameof(Foreground)) });
|
||||
}
|
||||
|
||||
protected override void OnViewportChanged(ViewportChangedEventArgs e)
|
||||
base.SetParentMap(map);
|
||||
}
|
||||
|
||||
protected override void OnViewportChanged(ViewportChangedEventArgs e)
|
||||
{
|
||||
Path path;
|
||||
|
||||
if (Children.Count == 0)
|
||||
{
|
||||
Path path;
|
||||
path = new Path { Data = new PathGeometry() };
|
||||
|
||||
if (Children.Count == 0)
|
||||
path.SetBinding(Shape.StrokeProperty,
|
||||
new Binding { Source = this, Path = new PropertyPath(nameof(Foreground)) });
|
||||
|
||||
path.SetBinding(Shape.StrokeThicknessProperty,
|
||||
new Binding { Source = this, Path = new PropertyPath(nameof(StrokeThickness)) });
|
||||
|
||||
Children.Add(path);
|
||||
}
|
||||
else
|
||||
{
|
||||
path = (Path)Children[0];
|
||||
}
|
||||
|
||||
var childrenCount = 1;
|
||||
var labels = new List<Label>();
|
||||
var figures = ((PathGeometry)path.Data).Figures;
|
||||
figures.Clear();
|
||||
|
||||
DrawGrid(figures, labels);
|
||||
|
||||
foreach (var label in labels)
|
||||
{
|
||||
TextBlock textBlock;
|
||||
|
||||
if (childrenCount < Children.Count)
|
||||
{
|
||||
path = new Path { Data = new PathGeometry() };
|
||||
|
||||
path.SetBinding(Shape.StrokeProperty,
|
||||
new Binding { Source = this, Path = new PropertyPath(nameof(Foreground)) });
|
||||
|
||||
path.SetBinding(Shape.StrokeThicknessProperty,
|
||||
new Binding { Source = this, Path = new PropertyPath(nameof(StrokeThickness)) });
|
||||
|
||||
Children.Add(path);
|
||||
textBlock = (TextBlock)Children[childrenCount];
|
||||
}
|
||||
else
|
||||
{
|
||||
path = (Path)Children[0];
|
||||
}
|
||||
textBlock = new TextBlock { RenderTransform = new MatrixTransform() };
|
||||
|
||||
var childrenCount = 1;
|
||||
var labels = new List<Label>();
|
||||
var figures = ((PathGeometry)path.Data).Figures;
|
||||
figures.Clear();
|
||||
textBlock.SetBinding(TextBlock.FontSizeProperty,
|
||||
new Binding { Source = this, Path = new PropertyPath(nameof(FontSize)) });
|
||||
|
||||
DrawGrid(figures, labels);
|
||||
textBlock.SetBinding(TextBlock.ForegroundProperty,
|
||||
new Binding { Source = this, Path = new PropertyPath(nameof(Foreground)) });
|
||||
|
||||
foreach (var label in labels)
|
||||
{
|
||||
TextBlock textBlock;
|
||||
|
||||
if (childrenCount < Children.Count)
|
||||
if (FontFamily != null)
|
||||
{
|
||||
textBlock = (TextBlock)Children[childrenCount];
|
||||
}
|
||||
else
|
||||
{
|
||||
textBlock = new TextBlock { RenderTransform = new MatrixTransform() };
|
||||
|
||||
textBlock.SetBinding(TextBlock.FontSizeProperty,
|
||||
new Binding { Source = this, Path = new PropertyPath(nameof(FontSize)) });
|
||||
|
||||
textBlock.SetBinding(TextBlock.ForegroundProperty,
|
||||
new Binding { Source = this, Path = new PropertyPath(nameof(Foreground)) });
|
||||
|
||||
if (FontFamily != null)
|
||||
{
|
||||
textBlock.SetBinding(TextBlock.FontFamilyProperty,
|
||||
new Binding { Source = this, Path = new PropertyPath(nameof(FontFamily)) });
|
||||
}
|
||||
|
||||
Children.Add(textBlock);
|
||||
textBlock.SetBinding(TextBlock.FontFamilyProperty,
|
||||
new Binding { Source = this, Path = new PropertyPath(nameof(FontFamily)) });
|
||||
}
|
||||
|
||||
textBlock.Text = label.Text;
|
||||
textBlock.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
|
||||
|
||||
var x = label.HorizontalAlignment switch
|
||||
{
|
||||
HorizontalAlignment.Left => 2d,
|
||||
HorizontalAlignment.Right => -textBlock.DesiredSize.Width - 2d,
|
||||
_ => -textBlock.DesiredSize.Width / 2d
|
||||
};
|
||||
var y = label.VerticalAlignment switch
|
||||
{
|
||||
VerticalAlignment.Top => 0d,
|
||||
VerticalAlignment.Bottom => -textBlock.DesiredSize.Height,
|
||||
_ => -textBlock.DesiredSize.Height / 2d,
|
||||
};
|
||||
|
||||
var matrix = new Matrix(1, 0, 0, 1, 0, 0);
|
||||
matrix.Translate(x, y);
|
||||
matrix.Rotate(label.Rotation);
|
||||
matrix.Translate(label.X, label.Y);
|
||||
|
||||
((MatrixTransform)textBlock.RenderTransform).Matrix = matrix;
|
||||
|
||||
childrenCount++;
|
||||
Children.Add(textBlock);
|
||||
}
|
||||
|
||||
while (Children.Count > childrenCount)
|
||||
textBlock.Text = label.Text;
|
||||
textBlock.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
|
||||
|
||||
var x = label.HorizontalAlignment switch
|
||||
{
|
||||
Children.RemoveAt(Children.Count - 1);
|
||||
}
|
||||
HorizontalAlignment.Left => 2d,
|
||||
HorizontalAlignment.Right => -textBlock.DesiredSize.Width - 2d,
|
||||
_ => -textBlock.DesiredSize.Width / 2d
|
||||
};
|
||||
var y = label.VerticalAlignment switch
|
||||
{
|
||||
VerticalAlignment.Top => 0d,
|
||||
VerticalAlignment.Bottom => -textBlock.DesiredSize.Height,
|
||||
_ => -textBlock.DesiredSize.Height / 2d,
|
||||
};
|
||||
|
||||
base.OnViewportChanged(e);
|
||||
var matrix = new Matrix(1, 0, 0, 1, 0, 0);
|
||||
matrix.Translate(x, y);
|
||||
matrix.Rotate(label.Rotation);
|
||||
matrix.Translate(label.X, label.Y);
|
||||
|
||||
((MatrixTransform)textBlock.RenderTransform).Matrix = matrix;
|
||||
|
||||
childrenCount++;
|
||||
}
|
||||
|
||||
private static PolyLineSegment CreatePolyLineSegment(IEnumerable<Point> points)
|
||||
while (Children.Count > childrenCount)
|
||||
{
|
||||
var polyline = new PolyLineSegment();
|
||||
|
||||
foreach (var p in points)
|
||||
{
|
||||
polyline.Points.Add(p);
|
||||
}
|
||||
|
||||
return polyline;
|
||||
Children.RemoveAt(Children.Count - 1);
|
||||
}
|
||||
|
||||
base.OnViewportChanged(e);
|
||||
}
|
||||
|
||||
private static PolyLineSegment CreatePolyLineSegment(IEnumerable<Point> points)
|
||||
{
|
||||
var polyline = new PolyLineSegment();
|
||||
|
||||
foreach (var p in points)
|
||||
{
|
||||
polyline.Points.Add(p);
|
||||
}
|
||||
|
||||
return polyline;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue