Added ViewTransform methods

This commit is contained in:
ClemensFischer 2026-01-07 19:39:28 +01:00
parent eee71e9190
commit 26e9b21816
6 changed files with 25 additions and 12 deletions

View file

@ -221,7 +221,7 @@ namespace MapControl
if (point.HasValue)
{
point = ViewTransform.MapToViewMatrix.Transform(point.Value);
point = ViewTransform.MapToView(point.Value);
}
return point;
@ -240,7 +240,7 @@ namespace MapControl
/// </summary>
public Location ViewToLocation(Point point)
{
return MapProjection.MapToLocation(ViewTransform.ViewToMapMatrix.Transform(point));
return MapProjection.MapToLocation(ViewTransform.ViewToMap(point));
}
/// <summary>
@ -248,7 +248,7 @@ namespace MapControl
/// </summary>
public BoundingBox ViewToBoundingBox(Rect rect)
{
return MapProjection.MapToBoundingBox(ViewTransform.ViewToMapMatrix.TransformBounds(rect));
return MapProjection.MapToBoundingBox(ViewTransform.ViewToMapBounds(rect));
}
/// <summary>

View file

@ -191,7 +191,7 @@ namespace MapControl
var height = ParentMap.ActualHeight * RelativeImageSize;
var x = (ParentMap.ActualWidth - width) / 2d;
var y = (ParentMap.ActualHeight - height) / 2d;
var mapRect = ParentMap.ViewTransform.ViewToMapMatrix.TransformBounds(new Rect(x, y, width, height));
var mapRect = ParentMap.ViewTransform.ViewToMapBounds(new Rect(x, y, width, height));
boundingBox = ParentMap.MapProjection.MapToBoundingBox(mapRect);
if (boundingBox != null)

View file

@ -220,7 +220,7 @@ namespace MapControl
private Rect GetViewRect(Rect mapRect)
{
var center = new Point(mapRect.X + mapRect.Width / 2d, mapRect.Y + mapRect.Height / 2d);
var position = parentMap.ViewTransform.MapToViewMatrix.Transform(center);
var position = parentMap.ViewTransform.MapToView(center);
if (parentMap.MapProjection.Type <= MapProjectionType.NormalCylindrical &&
!parentMap.InsideViewBounds(position))

View file

@ -114,7 +114,7 @@ namespace MapControl
if (point.HasValue)
{
point = ParentMap.ViewTransform.MapToViewMatrix.Transform(point.Value);
point = ParentMap.ViewTransform.MapToView(point.Value);
}
return point;

View file

@ -38,6 +38,22 @@ namespace MapControl
/// </summary>
public Matrix ViewToMapMatrix { get; private set; }
/// <summary>
/// Transforms a Point in projected map coordinates to a Point in view coordinates.
/// </summary>
public Point MapToView(Point point) => MapToViewMatrix.Transform(point);
/// <summary>
/// Transforms a Point in view coordinates to a Point in projected map coordinates.
/// </summary>
public Point ViewToMap(Point point) => ViewToMapMatrix.Transform(point);
/// <summary>
/// Gets an axis-aligned bounding box in projected map coordinates that contains
/// a rectangle in view coordinates.
/// </summary>
public Rect ViewToMapBounds(Rect rect) => TransformBounds(ViewToMapMatrix, rect);
/// <summary>
/// Initializes a ViewTransform from a map center point in projected coordinates,
/// a view conter point, a scaling factor from projected coordinates to view coordinates
@ -101,13 +117,10 @@ namespace MapControl
// Transform view bounds to tile pixel bounds.
//
return transform.TransformBounds(new Rect(0d, 0d, viewWidth, viewHeight));
return TransformBounds(transform, new Rect(0d, 0d, viewWidth, viewHeight));
}
}
public static class MatrixExtension
{
public static Rect TransformBounds(this Matrix transform, Rect rect)
private static Rect TransformBounds(Matrix transform, Rect rect)
{
#if AVALONIA
return rect.TransformToAABB(transform);

View file

@ -264,7 +264,7 @@ namespace MapControl
{
var width = ParentMap.ActualWidth;
var height = ParentMap.ActualHeight;
var bbox = ParentMap.ViewTransform.ViewToMapMatrix.TransformBounds(new Rect(0d, 0d, width, height));
var bbox = ParentMap.ViewTransform.ViewToMapBounds(new Rect(0d, 0d, width, height));
if (ParentMap.ViewTransform.Rotation != 0d)
{