String.Format

This commit is contained in:
Clemens 2021-07-05 00:04:07 +02:00
parent 5fde94acb9
commit 3cdbbe1e13
2 changed files with 12 additions and 25 deletions

View file

@ -3,6 +3,7 @@
// Licensed under the Microsoft Public License (Ms-PL) // Licensed under the Microsoft Public License (Ms-PL)
using System; using System;
using System.Globalization;
#if WINUI #if WINUI
using Microsoft.UI.Xaml; using Microsoft.UI.Xaml;
#elif WINDOWS_UWP #elif WINDOWS_UWP
@ -55,17 +56,8 @@ namespace MapControl
private static string GetLabelFormat(double lineDistance) private static string GetLabelFormat(double lineDistance)
{ {
if (lineDistance < 1d / 60d) return lineDistance < 1d / 60d ? "{0} {1}°{2:00}'{3:00}\""
{ : lineDistance < 1d ? "{0} {1}°{2:00}'" : "{0} {1}°";
return "{0} {1}°{2:00}'{3:00}\"";
}
if (lineDistance < 1d)
{
return "{0} {1}°{2:00}'";
}
return "{0} {1}°";
} }
private static string GetLabelText(double value, string format, string hemispheres) private static string GetLabelText(double value, string format, string hemispheres)
@ -80,7 +72,8 @@ namespace MapControl
var seconds = (int)Math.Round(value * 3600d); var seconds = (int)Math.Round(value * 3600d);
return string.Format(format, hemisphere, seconds / 3600, (seconds / 60) % 60, seconds % 60); return string.Format(CultureInfo.InvariantCulture,
format, hemisphere, seconds / 3600, seconds / 60 % 60, seconds % 60);
} }
} }
} }

View file

@ -3,6 +3,7 @@
// Licensed under the Microsoft Public License (Ms-PL) // Licensed under the Microsoft Public License (Ms-PL)
using System; using System;
using System.Globalization;
#if WINUI #if WINUI
using Windows.Foundation; using Windows.Foundation;
using Microsoft.UI.Xaml; using Microsoft.UI.Xaml;
@ -70,18 +71,9 @@ namespace MapControl
var length = MinWidth / scale; var length = MinWidth / scale;
var magnitude = Math.Pow(10d, Math.Floor(Math.Log10(length))); var magnitude = Math.Pow(10d, Math.Floor(Math.Log10(length)));
if (length / magnitude < 2d) length = length / magnitude < 2d ? 2d * magnitude
{ : length / magnitude < 5d ? 5d * magnitude
length = 2d * magnitude; : 10d * magnitude;
}
else if (length / magnitude < 5d)
{
length = 5d * magnitude;
}
else
{
length = 10d * magnitude;
}
size.Width = length * scale + StrokeThickness + Padding.Left + Padding.Right; size.Width = length * scale + StrokeThickness + Padding.Left + Padding.Right;
size.Height = 1.25 * FontSize + StrokeThickness + Padding.Top + Padding.Bottom; size.Height = 1.25 * FontSize + StrokeThickness + Padding.Top + Padding.Bottom;
@ -100,7 +92,9 @@ namespace MapControl
}; };
line.Measure(size); line.Measure(size);
label.Text = length >= 1000d ? string.Format("{0:0} km", length / 1000d) : string.Format("{0:0} m", length); label.Text = length >= 1000d
? string.Format(CultureInfo.InvariantCulture, "{0:0} km", length / 1000d)
: string.Format(CultureInfo.InvariantCulture, "{0:0} m", length);
label.Width = size.Width; label.Width = size.Width;
label.Height = size.Height; label.Height = size.Height;
label.Measure(size); label.Measure(size);