Version 5.0.1: Reworked MapBase and MapProjection

This commit is contained in:
ClemensF 2020-04-01 18:04:39 +02:00
parent 81ec8e7eb2
commit 2b41d298f4
4 changed files with 22 additions and 26 deletions

View file

@ -14,7 +14,7 @@ namespace MapControl
{
/// <summary>
/// Equirectangular Projection.
/// Longitude and Latitude values are transformed linearly to X and Y in meters.
/// Longitude and Latitude values are transformed linearly to X and Y values in meters.
/// </summary>
public class EquirectangularProjection : MapProjection
{
@ -47,7 +47,7 @@ namespace MapControl
public override string GetBboxValue(Rect rect)
{
return string.Format(CultureInfo.InvariantCulture,
CrsId != "CRS:84" ? "{1},{0},{3},{2}" : "{0},{1},{2},{3}",
CrsId == "CRS:84" ? "{0},{1},{2},{3}" : "{1},{0},{3},{2}",
rect.X / UnitsPerDegree, rect.Y / UnitsPerDegree,
(rect.X + rect.Width) / UnitsPerDegree, (rect.Y + rect.Height) / UnitsPerDegree);
}

View file

@ -692,16 +692,13 @@ namespace MapControl
private void UpdateTransform(bool resetTransformCenter = false, bool projectionChanged = false)
{
var viewScale = ViewTransform.ZoomLevelToScale(ZoomLevel);
var center = transformCenter ?? Center;
var projection = MapProjection;
projection.Center = ProjectionCenter ?? Center;
var center = transformCenter ?? Center;
var mapCenter = projection.LocationToMap(center);
var viewScale = ViewTransform.ZoomLevelToScale(ZoomLevel);
ViewTransform.SetTransform(mapCenter, viewCenter, viewScale, Heading);
ViewTransform.SetTransform(projection.LocationToMap(center), viewCenter, viewScale, Heading);
if (transformCenter != null)
{
@ -726,9 +723,8 @@ namespace MapControl
ResetTransformCenter();
projection.Center = ProjectionCenter ?? center;
mapCenter = projection.LocationToMap(center);
ViewTransform.SetTransform(mapCenter, viewCenter, viewScale, Heading);
ViewTransform.SetTransform(projection.LocationToMap(center), viewCenter, viewScale, Heading);
}
}

View file

@ -22,15 +22,15 @@ namespace MapControl
public const double Wgs84Flattening = 1d / 298.257223563;
public static readonly double Wgs84Eccentricity = Math.Sqrt((2d - Wgs84Flattening) * Wgs84Flattening);
/// <summary>
/// Gets or sets the projection center. Only relevant for azimuthal projections.
/// </summary>
public Location Center { get; set; } = new Location();
/// <summary>
/// Gets or sets the WMS 1.3.0 CRS identifier.
/// </summary>
public string CrsId { get; set; }
public string CrsId { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the projection center.
/// </summary>
public Location Center { get; set; } = new Location();
/// <summary>
/// Indicates if this is a normal cylindrical projection.

View file

@ -19,6 +19,16 @@ namespace MapControl
/// </summary>
public class ViewTransform
{
public static double ZoomLevelToScale(double zoomLevel)
{
return 256d * Math.Pow(2d, zoomLevel) / (360d * MapProjection.Wgs84MetersPerDegree);
}
public static double ScaleToZoomLevel(double scale)
{
return Math.Log(scale * 360d * MapProjection.Wgs84MetersPerDegree / 256d, 2d);
}
/// <summary>
/// Gets the scaling factor from cartesian map coordinates to view coordinates,
/// i.e. pixels per meter.
@ -117,15 +127,5 @@ namespace MapControl
return new MatrixTransform { Matrix = transform }
.TransformBounds(new Rect(0d, 0d, viewSize.Width, viewSize.Height));
}
public static double ZoomLevelToScale(double zoomLevel)
{
return 256d * Math.Pow(2d, zoomLevel) / (360d * MapProjection.Wgs84MetersPerDegree);
}
public static double ScaleToZoomLevel(double scale)
{
return Math.Log(scale * 360d * MapProjection.Wgs84MetersPerDegree / 256d, 2d);
}
}
}