mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Minor improvements
This commit is contained in:
parent
754e185c5d
commit
7e6b187fd7
|
|
@ -15,8 +15,8 @@ namespace MapControl
|
|||
#endif
|
||||
public class BoundingBox
|
||||
{
|
||||
private double south;
|
||||
private double north;
|
||||
private double south = double.NaN;
|
||||
private double north = double.NaN;
|
||||
|
||||
public BoundingBox()
|
||||
{
|
||||
|
|
@ -30,9 +30,8 @@ namespace MapControl
|
|||
East = east;
|
||||
}
|
||||
|
||||
public double West { get; set; }
|
||||
|
||||
public double East { get; set; }
|
||||
public double West { get; set; } = double.NaN;
|
||||
public double East { get; set; } = double.NaN;
|
||||
|
||||
public double South
|
||||
{
|
||||
|
|
@ -64,11 +63,16 @@ namespace MapControl
|
|||
protected set { }
|
||||
}
|
||||
|
||||
public static BoundingBox Parse(string s)
|
||||
public static BoundingBox Parse(string boundingBox)
|
||||
{
|
||||
var values = s.Split(new char[] { ',' });
|
||||
string[] values = null;
|
||||
|
||||
if (values.Length != 4)
|
||||
if (!string.IsNullOrEmpty(boundingBox))
|
||||
{
|
||||
values = boundingBox.Split(new char[] { ',' });
|
||||
}
|
||||
|
||||
if (values?.Length != 4)
|
||||
{
|
||||
throw new FormatException("BoundingBox string must be a comma-separated list of four floating point numbers.");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -242,11 +242,11 @@ namespace MapControl
|
|||
|
||||
private static LatLonBox ReadLatLonBox(XmlElement element)
|
||||
{
|
||||
double north = double.NaN;
|
||||
double south = double.NaN;
|
||||
double east = double.NaN;
|
||||
double west = double.NaN;
|
||||
double rotation = 0d;
|
||||
var north = double.NaN;
|
||||
var south = double.NaN;
|
||||
var east = double.NaN;
|
||||
var west = double.NaN;
|
||||
var rotation = 0d;
|
||||
|
||||
foreach (var childElement in element.ChildNodes.OfType<XmlElement>())
|
||||
{
|
||||
|
|
|
|||
|
|
@ -57,42 +57,33 @@ namespace MapControl
|
|||
return string.Format(CultureInfo.InvariantCulture, "{0:F5},{1:F5}", Latitude, Longitude);
|
||||
}
|
||||
|
||||
public static Location Parse(string locationString)
|
||||
public static Location Parse(string location)
|
||||
{
|
||||
Location location = null;
|
||||
string[] values = null;
|
||||
|
||||
if (!string.IsNullOrEmpty(locationString))
|
||||
if (!string.IsNullOrEmpty(location))
|
||||
{
|
||||
var values = locationString.Split(new char[] { ',' });
|
||||
|
||||
if (values.Length != 2)
|
||||
{
|
||||
throw new FormatException("Location string must be a comma-separated pair of double values.");
|
||||
}
|
||||
|
||||
location = new Location(
|
||||
double.Parse(values[0], NumberStyles.Float, CultureInfo.InvariantCulture),
|
||||
double.Parse(values[1], NumberStyles.Float, CultureInfo.InvariantCulture));
|
||||
values = location.Split(new char[] { ',' });
|
||||
}
|
||||
|
||||
return location;
|
||||
if (values?.Length != 2)
|
||||
{
|
||||
throw new FormatException("Location string must be a comma-separated pair of floating point numbers.");
|
||||
}
|
||||
|
||||
return new Location(
|
||||
double.Parse(values[0], NumberStyles.Float, CultureInfo.InvariantCulture),
|
||||
double.Parse(values[1], NumberStyles.Float, CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Normalizes a longitude to a value in the interval [-180 .. 180].
|
||||
/// Normalizes a longitude to a value in the interval [-180 .. 180).
|
||||
/// </summary>
|
||||
public static double NormalizeLongitude(double longitude)
|
||||
{
|
||||
if (longitude < -180d)
|
||||
{
|
||||
longitude = ((longitude + 180d) % 360d) + 180d;
|
||||
}
|
||||
else if (longitude > 180d)
|
||||
{
|
||||
longitude = ((longitude - 180d) % 360d) - 180d;
|
||||
}
|
||||
var x = (longitude + 180d) % 360d;
|
||||
|
||||
return longitude;
|
||||
return x < 0d ? x + 180d : x - 180d;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -50,9 +50,14 @@ namespace MapControl
|
|||
Add(new Location(latitude, longitude));
|
||||
}
|
||||
|
||||
public static LocationCollection Parse(string s)
|
||||
public static LocationCollection Parse(string locations)
|
||||
{
|
||||
var strings = s.Split(new char[] { ' ', ';' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (string.IsNullOrEmpty(locations))
|
||||
{
|
||||
return new LocationCollection();
|
||||
}
|
||||
|
||||
var strings = locations.Split(new char[] { ' ', ';' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
return new LocationCollection(strings.Select(l => Location.Parse(l)));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -390,11 +390,11 @@ namespace MapControl
|
|||
|
||||
if (offset > 180d)
|
||||
{
|
||||
longitude = Center.Longitude - 360d + offset % 360d;
|
||||
longitude = Center.Longitude + (offset % 360d) - 360d;
|
||||
}
|
||||
else if (offset < -180d)
|
||||
{
|
||||
longitude = Center.Longitude + 360d + offset % 360d;
|
||||
longitude = Center.Longitude + (offset % 360d) + 360d;
|
||||
}
|
||||
|
||||
return longitude;
|
||||
|
|
|
|||
|
|
@ -92,9 +92,7 @@ namespace MapControl
|
|||
{
|
||||
var hemisphere = hemispheres[0];
|
||||
|
||||
value = (value + 540d) % 360d - 180d;
|
||||
|
||||
if (value < -1e-8) // ~1mm
|
||||
if (value < -1e-8) // ~1 mm
|
||||
{
|
||||
value = -value;
|
||||
hemisphere = hemispheres[1];
|
||||
|
|
|
|||
|
|
@ -211,7 +211,6 @@ namespace MapControl
|
|||
IsOutsideViewport(position))
|
||||
{
|
||||
location = new Location(location.Latitude, parentMap.ConstrainedLongitude(location.Longitude));
|
||||
|
||||
position = parentMap.LocationToView(location);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ namespace MapControl
|
|||
|
||||
/// <summary>
|
||||
/// Transforms a Location in geographic coordinates to a Point in projected map coordinates.
|
||||
/// Returns new Point(double.NaN, double.NaN) when the Location can not be transformed.
|
||||
/// </summary>
|
||||
public abstract Point LocationToMap(Location location);
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ namespace MapControl
|
|||
/// <summary>
|
||||
/// Rotated rectangle used to arrange and rotate an element with a BoundingBox.
|
||||
/// </summary>
|
||||
public struct ViewRect
|
||||
public class ViewRect
|
||||
{
|
||||
public ViewRect(double x, double y, double width, double height, double rotation)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue