mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-01-10 18:50:03 +01:00
Added ViewTransform methods
This commit is contained in:
parent
eee71e9190
commit
26e9b21816
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ namespace MapControl
|
|||
|
||||
if (point.HasValue)
|
||||
{
|
||||
point = ParentMap.ViewTransform.MapToViewMatrix.Transform(point.Value);
|
||||
point = ParentMap.ViewTransform.MapToView(point.Value);
|
||||
}
|
||||
|
||||
return point;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue