Version 4.7.0: Added UWP Vector class

This commit is contained in:
ClemensFischer 2018-03-07 22:19:16 +01:00
parent 32db0f22c1
commit 9c148e13c4
21 changed files with 154 additions and 93 deletions

View file

@ -25,9 +25,9 @@ namespace MapControl
IsAzimuthal = true;
}
public override Point GetMapScale(Location location)
public override Vector GetMapScale(Location location)
{
return new Point(ViewportScale, ViewportScale);
return new Vector(ViewportScale, ViewportScale);
}
public override Rect BoundingBoxToRect(BoundingBox boundingBox)

View file

@ -26,9 +26,9 @@ namespace MapControl
CrsId = crsId;
}
public override Point GetMapScale(Location location)
public override Vector GetMapScale(Location location)
{
return new Point(
return new Vector(
ViewportScale / (MetersPerDegree * Math.Cos(location.Latitude * Math.PI / 180d)),
ViewportScale / MetersPerDegree);
}

View file

@ -276,9 +276,9 @@ namespace MapControl
}
/// <summary>
/// Changes the Center property according to the specified map translation in viewport coordinates.
/// Changes the Center property according to the specified translation in viewport coordinates.
/// </summary>
public void TranslateMap(Point translation)
public void TranslateMap(Vector translation)
{
if (transformCenter != null)
{
@ -288,8 +288,7 @@ namespace MapControl
if (translation.X != 0d || translation.Y != 0d)
{
Center = MapProjection.ViewportPointToLocation(
new Point(viewportCenter.X - translation.X, viewportCenter.Y - translation.Y));
Center = MapProjection.ViewportPointToLocation(viewportCenter - translation);
}
}
@ -298,12 +297,12 @@ namespace MapControl
/// viewport coordinate translation, rotation and scale delta values. Rotation and scaling
/// is performed relative to the specified center point in viewport coordinates.
/// </summary>
public void TransformMap(Point center, Point translation, double rotation, double scale)
public void TransformMap(Point center, Vector translation, double rotation, double scale)
{
if (rotation != 0d || scale != 1d)
{
transformCenter = MapProjection.ViewportPointToLocation(center);
viewportCenter = new Point(center.X + translation.X, center.Y + translation.Y);
viewportCenter = center + translation;
if (rotation != 0d)
{

View file

@ -76,7 +76,7 @@ namespace MapControl
/// <summary>
/// Gets the map scale at the specified Location as viewport coordinate units per meter (px/m).
/// </summary>
public abstract Point GetMapScale(Location location);
public abstract Vector GetMapScale(Location location);
/// <summary>
/// Transforms a Location in geographic coordinates to a Point in cartesian map coordinates.
@ -143,14 +143,13 @@ namespace MapControl
ViewportScale = Math.Pow(2d, zoomLevel) * PixelPerDegree / TrueScale;
var center = LocationToPoint(mapCenter);
var transformMatrix = CreateTransformMatrix(
-center.X, -center.Y, ViewportScale, -ViewportScale, heading, viewportCenter.X, viewportCenter.Y);
var matrix = CreateTransformMatrix(center, ViewportScale, -ViewportScale, heading, viewportCenter);
ViewportTransformMatrix = transformMatrix;
ViewportTransform.Matrix = transformMatrix;
ViewportTransformMatrix = matrix;
ViewportTransform.Matrix = matrix;
transformMatrix.Invert();
inverseViewportTransformMatrix = transformMatrix;
matrix.Invert();
inverseViewportTransformMatrix = matrix;
}
/// <summary>
@ -183,15 +182,12 @@ namespace MapControl
rect.X, rect.Y, (rect.X + rect.Width), (rect.Y + rect.Height), width, height);
}
public static Matrix CreateTransformMatrix(
double translation1X, double translation1Y,
double scaleX, double scaleY, double rotationAngle,
double translation2X, double translation2Y)
internal static Matrix CreateTransformMatrix(
Point translation1, double scaleX, double scaleY, double rotation, Point translation2)
{
var matrix = new Matrix(1d, 0d, 0d, 1d, translation1X, translation1Y);
matrix.Scale(scaleX, scaleY);
matrix.Rotate(rotationAngle);
matrix.Translate(translation2X, translation2Y);
var matrix = new Matrix(scaleX, 0d, 0d, scaleY, -translation1.X * scaleX, -translation1.Y * scaleY);
matrix.Rotate(rotation);
matrix.Translate(translation2.X, translation2.Y);
return matrix;
}
}

View file

@ -305,14 +305,13 @@ namespace MapControl
var tileZoomLevel = Math.Max(0, (int)Math.Round(parentMap.ZoomLevel + ZoomLevelOffset));
var tileScale = (double)(1 << tileZoomLevel);
var scale = tileScale / (Math.Pow(2d, parentMap.ZoomLevel) * MapProjection.TileSize);
var tileCenterX = tileScale * (0.5 + parentMap.Center.Longitude / 360d);
var tileCenterY = tileScale * (0.5 - WebMercatorProjection.LatitudeToY(parentMap.Center.Latitude) / 360d);
var viewCenterX = parentMap.RenderSize.Width / 2d;
var viewCenterY = parentMap.RenderSize.Height / 2d;
var tileCenter = new Point(tileScale * (0.5 + parentMap.Center.Longitude / 360d),
tileScale * (0.5 - WebMercatorProjection.LatitudeToY(parentMap.Center.Latitude) / 360d));
var viewCenter = new Point(parentMap.RenderSize.Width / 2d, parentMap.RenderSize.Height / 2d);
var transform = new MatrixTransform
{
Matrix = MapProjection.CreateTransformMatrix(-viewCenterX, -viewCenterY, scale, scale, -parentMap.Heading, tileCenterX, tileCenterY)
Matrix = MapProjection.CreateTransformMatrix(viewCenter, scale, scale, -parentMap.Heading, tileCenter)
};
var bounds = transform.TransformBounds(new Rect(0d, 0d, parentMap.RenderSize.Width, parentMap.RenderSize.Height));
@ -326,15 +325,14 @@ namespace MapControl
{
var tileScale = (double)(1 << TileGrid.ZoomLevel);
var scale = Math.Pow(2d, parentMap.ZoomLevel) / tileScale;
var tileCenterX = tileScale * (0.5 + parentMap.Center.Longitude / 360d);
var tileCenterY = tileScale * (0.5 - WebMercatorProjection.LatitudeToY(parentMap.Center.Latitude) / 360d);
var tileOriginX = MapProjection.TileSize * (tileCenterX - TileGrid.XMin);
var tileOriginY = MapProjection.TileSize * (tileCenterY - TileGrid.YMin);
var viewCenterX = parentMap.RenderSize.Width / 2d;
var viewCenterY = parentMap.RenderSize.Height / 2d;
var tileCenter = new Point(tileScale * (0.5 + parentMap.Center.Longitude / 360d),
tileScale * (0.5 - WebMercatorProjection.LatitudeToY(parentMap.Center.Latitude) / 360d));
var tileOrigin = new Point(MapProjection.TileSize * (tileCenter.X - TileGrid.XMin),
MapProjection.TileSize * (tileCenter.Y - TileGrid.YMin));
var viewCenter = new Point(parentMap.RenderSize.Width / 2d, parentMap.RenderSize.Height / 2d);
((MatrixTransform)RenderTransform).Matrix = MapProjection.CreateTransformMatrix(
-tileOriginX, -tileOriginY, scale, scale, parentMap.Heading, viewCenterX, viewCenterY);
((MatrixTransform)RenderTransform).Matrix =
MapProjection.CreateTransformMatrix(tileOrigin, scale, scale, parentMap.Heading, viewCenter);
}
private void UpdateTiles()

View file

@ -29,11 +29,11 @@ namespace MapControl
MaxLatitude = YToLatitude(180d);
}
public override Point GetMapScale(Location location)
public override Vector GetMapScale(Location location)
{
var scale = ViewportScale / Math.Cos(location.Latitude * Math.PI / 180d);
return new Point(scale, scale);
return new Vector(scale, scale);
}
public override Point LocationToPoint(Location location)

View file

@ -34,13 +34,13 @@ namespace MapControl
MaxLatitude = YToLatitude(180d);
}
public override Point GetMapScale(Location location)
public override Vector GetMapScale(Location location)
{
var lat = location.Latitude * Math.PI / 180d;
var eSinLat = Wgs84Eccentricity * Math.Sin(lat);
var scale = ViewportScale * Math.Sqrt(1d - eSinLat * eSinLat) / Math.Cos(lat);
return new Point(scale, scale);
return new Vector(scale, scale);
}
public override Point LocationToPoint(Location location)