From 0511b439e1b7f0189d4ebb0b48f41ad39d52956c Mon Sep 17 00:00:00 2001 From: ClemensFischer Date: Mon, 24 Mar 2025 20:59:11 +0100 Subject: [PATCH] Update MapPanel.cs --- MapControl/Shared/MapPanel.cs | 53 +++++++++++++++-------------------- 1 file changed, 23 insertions(+), 30 deletions(-) diff --git a/MapControl/Shared/MapPanel.cs b/MapControl/Shared/MapPanel.cs index f3a85a2b..5001ae07 100644 --- a/MapControl/Shared/MapPanel.cs +++ b/MapControl/Shared/MapPanel.cs @@ -202,30 +202,6 @@ namespace MapControl return position; } - private Tuple GetViewRect(BoundingBox boundingBox) - { - if (boundingBox is LatLonBox latLonBox) - { - var rotatedRect = parentMap.MapProjection.LatLonBoxToMap(latLonBox); - - if (rotatedRect != null) - { - return new Tuple(GetViewRect(rotatedRect.Item1), rotatedRect.Item2); - } - } - else - { - var mapRect = parentMap.MapProjection.BoundingBoxToMap(boundingBox); - - if (mapRect.HasValue) - { - return new Tuple(GetViewRect(mapRect.Value), 0d); - } - } - - return null; - } - private Rect GetViewRect(Rect mapRect) { var center = new Point(mapRect.X + mapRect.Width / 2d, mapRect.Y + mapRect.Height / 2d); @@ -295,16 +271,33 @@ namespace MapControl private void ArrangeElement(FrameworkElement element, BoundingBox boundingBox) { - var viewRect = GetViewRect(boundingBox); + Rect? mapRect = null; + var rotation = 0d; - if (viewRect != null) + if (boundingBox is LatLonBox latLonBox) { - element.Width = viewRect.Item1.Width; - element.Height = viewRect.Item1.Height; + var rotatedRect = parentMap.MapProjection.LatLonBoxToMap(latLonBox); - element.Arrange(viewRect.Item1); + if (rotatedRect != null) + { + mapRect = rotatedRect.Item1; + rotation = -rotatedRect.Item2; + } + } + else + { + mapRect = parentMap.MapProjection.BoundingBoxToMap(boundingBox); + } - var rotation = parentMap.ViewTransform.Rotation - viewRect.Item2; + if (mapRect.HasValue) + { + var viewRect = GetViewRect(mapRect.Value); + + element.Width = viewRect.Width; + element.Height = viewRect.Height; + element.Arrange(viewRect); + + rotation += parentMap.ViewTransform.Rotation; if (element.RenderTransform is RotateTransform rotateTransform) {