Added Location.NormalizeLongitude and fixed LocationAnimation

This commit is contained in:
ClemensF 2012-05-06 11:28:47 +02:00
parent bbaa5b37e8
commit cc690c5445
4 changed files with 26 additions and 7 deletions

View file

@ -11,6 +11,9 @@ namespace MapControl
[TypeConverter(typeof(LocationConverter))]
public class Location
{
private double latitude;
private double longitude;
public Location()
{
}
@ -21,8 +24,22 @@ namespace MapControl
Longitude = longitude;
}
public double Latitude { get; set; }
public double Longitude { get; set; }
public double Latitude
{
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)
{
@ -30,9 +47,9 @@ namespace MapControl
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;
}
}

View file

@ -42,9 +42,11 @@ namespace MapControl
progress = EasingFunction.Ease(progress);
}
double deltaLongitude = progress * Location.NormalizeLongitude(To.Longitude - From.Longitude);
return new Location(
(1d - progress) * From.Latitude + progress * To.Latitude,
(1d - progress) * From.Longitude + progress * To.Longitude);
Location.NormalizeLongitude(From.Longitude + deltaLongitude));
}
}
}

View file

@ -574,7 +574,7 @@ namespace MapControl
private Location CoerceCenter(Location location)
{
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;
}

View file

@ -177,7 +177,7 @@ namespace MapControl
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);
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.DrawGlyphRun(Foreground, GlyphRunText.Create(latString, typeface, FontSize, latPos));