Version 4.16.0. Improved MapProjection.

This commit is contained in:
ClemensF 2019-12-16 18:35:04 +01:00
parent 1f66a9f878
commit 0dbdd4c810
5 changed files with 24 additions and 15 deletions

View file

@ -36,7 +36,7 @@ namespace MapControl
{
if (point.X == 0d && point.Y == 0d)
{
return ProjectionCenter;
return new Location(ProjectionCenter.Latitude, ProjectionCenter.Longitude);
}
var azimuth = Math.Atan2(point.X, point.Y);

View file

@ -71,18 +71,27 @@ namespace MapControl
/// </summary>
public static Location GetLocation(Location location, double azimuth, double distance)
{
var lat1 = location.Latitude * Math.PI / 180d;
var sinDistance = Math.Sin(distance);
var cosDistance = Math.Cos(distance);
var cosAzimuth = Math.Cos(azimuth);
var sinAzimuth = Math.Sin(azimuth);
var cosLat1 = Math.Cos(lat1);
var sinLat1 = Math.Sin(lat1);
var sinLat2 = sinLat1 * cosDistance + cosLat1 * sinDistance * cosAzimuth;
var lat2 = Math.Asin(Math.Min(Math.Max(sinLat2, -1d), 1d));
var dLon = Math.Atan2(sinDistance * sinAzimuth, cosLat1 * cosDistance - sinLat1 * sinDistance * cosAzimuth);
var lat = location.Latitude;
var lon = location.Longitude;
return new Location(lat2 * 180d / Math.PI, location.Longitude + dLon * 180d / Math.PI);
if (distance > 0d)
{
var lat1 = lat * Math.PI / 180d;
var sinDistance = Math.Sin(distance);
var cosDistance = Math.Cos(distance);
var cosAzimuth = Math.Cos(azimuth);
var sinAzimuth = Math.Sin(azimuth);
var cosLat1 = Math.Cos(lat1);
var sinLat1 = Math.Sin(lat1);
var sinLat2 = sinLat1 * cosDistance + cosLat1 * sinDistance * cosAzimuth;
var lat2 = Math.Asin(Math.Min(Math.Max(sinLat2, -1d), 1d));
var dLon = Math.Atan2(sinDistance * sinAzimuth, cosLat1 * cosDistance - sinLat1 * sinDistance * cosAzimuth);
lat = lat2 * 180d / Math.PI;
lon += dLon * 180d / Math.PI;
}
return new Location(lat, lon);
}
}
}

View file

@ -41,7 +41,7 @@ namespace MapControl
{
if (point.X == 0d && point.Y == 0d)
{
return ProjectionCenter;
return new Location(ProjectionCenter.Latitude, ProjectionCenter.Longitude);
}
var azimuth = Math.Atan2(point.X, point.Y);

View file

@ -40,7 +40,7 @@ namespace MapControl
{
if (point.X == 0d && point.Y == 0d)
{
return ProjectionCenter;
return new Location(ProjectionCenter.Latitude, ProjectionCenter.Longitude);
}
var s = TrueScale * 180d / Math.PI;

View file

@ -39,7 +39,7 @@ namespace MapControl
{
if (point.X == 0d && point.Y == 0d)
{
return ProjectionCenter;
return new Location(ProjectionCenter.Latitude, ProjectionCenter.Longitude);
}
var azimuth = Math.Atan2(point.X, point.Y);