Reworked MapGraticule

This commit is contained in:
Clemens 2022-04-28 18:34:30 +02:00
parent 53a291662d
commit 28f65140c4
3 changed files with 116 additions and 113 deletions

View file

@ -26,49 +26,41 @@ namespace MapControl
protected override void OnRender(DrawingContext drawingContext)
{
var projection = ParentMap?.MapProjection;
if (projection != null)
if (ParentMap != null)
{
var typeface = new Typeface(FontFamily, FontStyle, FontWeight, FontStretch);
var pixelsPerDip = VisualTreeHelper.GetDpi(this).PixelsPerDip;
var pathGeometry = new PathGeometry();
var labels = new List<Label>();
SetLineDistance();
if (projection.Type <= MapProjectionType.NormalCylindrical)
{
DrawCylindricalGraticule(pathGeometry.Figures, labels);
}
else
{
DrawGraticule(pathGeometry.Figures, labels);
}
var labels = DrawGraticule(pathGeometry.Figures);
drawingContext.DrawGeometry(null, CreatePen(), pathGeometry);
foreach (var label in labels)
if (labels.Count > 0)
{
var latText = new FormattedText(label.LatitudeText,
CultureInfo.InvariantCulture, FlowDirection.LeftToRight, typeface, FontSize, Foreground, pixelsPerDip);
var typeface = new Typeface(FontFamily, FontStyle, FontWeight, FontStretch);
var pixelsPerDip = VisualTreeHelper.GetDpi(this).PixelsPerDip;
var lonText = new FormattedText(label.LongitudeText,
CultureInfo.InvariantCulture, FlowDirection.LeftToRight, typeface, FontSize, Foreground, pixelsPerDip);
foreach (var label in labels)
{
var latText = new FormattedText(label.LatitudeText,
CultureInfo.InvariantCulture, FlowDirection.LeftToRight, typeface, FontSize, Foreground, pixelsPerDip);
var x = label.Position.X + StrokeThickness / 2d + 2d;
var y1 = label.Position.Y - StrokeThickness / 2d - latText.Height;
var y2 = label.Position.Y + StrokeThickness / 2d;
var lonText = new FormattedText(label.LongitudeText,
CultureInfo.InvariantCulture, FlowDirection.LeftToRight, typeface, FontSize, Foreground, pixelsPerDip);
drawingContext.PushTransform(new RotateTransform(label.Rotation, label.Position.X, label.Position.Y));
drawingContext.DrawText(latText, new Point(x, y1));
drawingContext.DrawText(lonText, new Point(x, y2));
drawingContext.Pop();
var x = label.X + StrokeThickness / 2d + 2d;
var y1 = label.Y - StrokeThickness / 2d - latText.Height;
var y2 = label.Y + StrokeThickness / 2d;
drawingContext.PushTransform(new RotateTransform(label.Rotation, label.X, label.Y));
drawingContext.DrawText(latText, new Point(x, y1));
drawingContext.DrawText(lonText, new Point(x, y2));
drawingContext.Pop();
}
}
}
}
private static PathFigure CreatePolylineFigure(ICollection<Point> points)
private static PathFigure CreatePolylineFigure(IEnumerable<Point> points)
{
var figure = new PathFigure
{