mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Added Location.NormalizeLongitude and fixed LocationAnimation
This commit is contained in:
parent
bbaa5b37e8
commit
cc690c5445
|
|
@ -11,6 +11,9 @@ namespace MapControl
|
||||||
[TypeConverter(typeof(LocationConverter))]
|
[TypeConverter(typeof(LocationConverter))]
|
||||||
public class Location
|
public class Location
|
||||||
{
|
{
|
||||||
|
private double latitude;
|
||||||
|
private double longitude;
|
||||||
|
|
||||||
public Location()
|
public Location()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
@ -21,8 +24,22 @@ namespace MapControl
|
||||||
Longitude = longitude;
|
Longitude = longitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double Latitude { get; set; }
|
public double Latitude
|
||||||
public double Longitude { get; set; }
|
{
|
||||||
|
get { return latitude; }
|
||||||
|
set { latitude = Math.Min(Math.Max(value, -90d), 90d); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public double Longitude
|
||||||
|
{
|
||||||
|
get { return longitude; }
|
||||||
|
set { longitude = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return string.Format(CultureInfo.InvariantCulture, "{0:0.00000},{1:0.00000}", latitude, longitude);
|
||||||
|
}
|
||||||
|
|
||||||
public static Location Parse(string source)
|
public static Location Parse(string source)
|
||||||
{
|
{
|
||||||
|
|
@ -30,9 +47,9 @@ namespace MapControl
|
||||||
return new Location(p.X, p.Y);
|
return new Location(p.X, p.Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public static double NormalizeLongitude(double longitude)
|
||||||
{
|
{
|
||||||
return string.Format(CultureInfo.InvariantCulture, "{0:0.00000},{1:0.00000}", Latitude, Longitude);
|
return ((longitude + 180d) % 360d + 360d) % 360d - 180d;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,9 +42,11 @@ namespace MapControl
|
||||||
progress = EasingFunction.Ease(progress);
|
progress = EasingFunction.Ease(progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double deltaLongitude = progress * Location.NormalizeLongitude(To.Longitude - From.Longitude);
|
||||||
|
|
||||||
return new Location(
|
return new Location(
|
||||||
(1d - progress) * From.Latitude + progress * To.Latitude,
|
(1d - progress) * From.Latitude + progress * To.Latitude,
|
||||||
(1d - progress) * From.Longitude + progress * To.Longitude);
|
Location.NormalizeLongitude(From.Longitude + deltaLongitude));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -574,7 +574,7 @@ namespace MapControl
|
||||||
private Location CoerceCenter(Location location)
|
private Location CoerceCenter(Location location)
|
||||||
{
|
{
|
||||||
location.Latitude = Math.Min(Math.Max(location.Latitude, -MapTransform.MaxLatitude), MapTransform.MaxLatitude);
|
location.Latitude = Math.Min(Math.Max(location.Latitude, -MapTransform.MaxLatitude), MapTransform.MaxLatitude);
|
||||||
location.Longitude = ((location.Longitude + 180d) % 360d + 360d) % 360d - 180d;
|
location.Longitude = Location.NormalizeLongitude(location.Longitude);
|
||||||
return location;
|
return location;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -177,7 +177,7 @@ namespace MapControl
|
||||||
Point latPos = new Point(p.X + t + 2d, p.Y - t - FontSize / 4d);
|
Point latPos = new Point(p.X + t + 2d, p.Y - t - FontSize / 4d);
|
||||||
Point lonPos = new Point(p.X + t + 2d, p.Y + t + FontSize);
|
Point lonPos = new Point(p.X + t + 2d, p.Y + t + FontSize);
|
||||||
string latString = CoordinateString(lat, format, "NS");
|
string latString = CoordinateString(lat, format, "NS");
|
||||||
string lonString = CoordinateString(((lon + 180d) % 360d + 360d) % 360d - 180d, format, "EW");
|
string lonString = CoordinateString(Location.NormalizeLongitude(lon), format, "EW");
|
||||||
|
|
||||||
drawingContext.PushTransform(new RotateTransform(parentMap.Heading, p.X, p.Y));
|
drawingContext.PushTransform(new RotateTransform(parentMap.Heading, p.X, p.Y));
|
||||||
drawingContext.DrawGlyphRun(Foreground, GlyphRunText.Create(latString, typeface, FontSize, latPos));
|
drawingContext.DrawGlyphRun(Foreground, GlyphRunText.Create(latString, typeface, FontSize, latPos));
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue