From 05032dbd25da41764ff4e6909fa21affef63b492 Mon Sep 17 00:00:00 2001 From: ClemensFischer Date: Mon, 26 Jan 2026 23:44:59 +0100 Subject: [PATCH] Updated LatLonBoxToMap --- MapControl/Shared/MapPanel.cs | 25 ++++++++++++++----------- MapControl/Shared/MapProjection.cs | 22 +++++++++++----------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/MapControl/Shared/MapPanel.cs b/MapControl/Shared/MapPanel.cs index 01329536..e727cf4e 100644 --- a/MapControl/Shared/MapPanel.cs +++ b/MapControl/Shared/MapPanel.cs @@ -287,7 +287,7 @@ namespace MapControl private void ArrangeElement(FrameworkElement element, BoundingBox boundingBox) { Rect? mapRect; - Matrix transform; + Matrix? transform = null; if (boundingBox is LatLonBox latLonBox) { @@ -296,7 +296,6 @@ namespace MapControl else { mapRect = parentMap.MapProjection.BoundingBoxToMap(boundingBox); - transform = new Matrix(1d, 0d, 0d, 1d, 0d, 0d); } if (mapRect.HasValue) @@ -307,19 +306,23 @@ namespace MapControl element.Height = viewRect.Height; element.Arrange(viewRect); - transform.Rotate(parentMap.ViewTransform.Rotation); - - if (element.RenderTransform is MatrixTransform matrixTransform -#if WPF - && !matrixTransform.IsFrozen -#endif - ) + if (parentMap.ViewTransform.Rotation != 0d) { - matrixTransform.Matrix = transform; + if (!transform.HasValue) + { + transform = new Matrix(1d, 0d, 0d, 1d, 0d, 0d); + } + + transform.Value.Rotate(parentMap.ViewTransform.Rotation); + } + + if (transform.HasValue) + { + element.SetRenderTransform(new MatrixTransform { Matrix = transform.Value }, true); } else { - element.SetRenderTransform(new MatrixTransform { Matrix = transform }, true); + element.ClearValue(RenderTransformProperty); } } } diff --git a/MapControl/Shared/MapProjection.cs b/MapControl/Shared/MapProjection.cs index 91ae5c17..06780f6a 100644 --- a/MapControl/Shared/MapProjection.cs +++ b/MapControl/Shared/MapProjection.cs @@ -163,12 +163,12 @@ namespace MapControl /// /// Transforms a LatLonBox in geographic coordinates to a rotated Rect in projected map coordinates. - /// Returns (null, 0d) when the LatLonBox can not be transformed. + /// Returns (null, null) when the LatLonBox can not be transformed. /// - public (Rect?, Matrix) LatLonBoxToMap(LatLonBox latLonBox) + public (Rect?, Matrix?) LatLonBoxToMap(LatLonBox latLonBox) { Rect? rect = null; - Matrix transform; + Matrix? transform = null; var sw = LocationToMap(latLonBox.South, latLonBox.West); var se = LocationToMap(latLonBox.South, latLonBox.East); var nw = LocationToMap(latLonBox.North, latLonBox.West); @@ -192,14 +192,14 @@ namespace MapControl rect = new Rect(x, y, width, height); - // Skew matrix with skewX = Atan(-dx2 / dy2) and skewY = Atan(-dy1 / dx1). - // - transform = new Matrix(1d, -dy1 / dx1, -dx2 / dy2, 1d, 0d, 0d); - transform.Rotate(-latLonBox.Rotation); - } - else - { - transform = new Matrix(1d, 0d, 0d, 1d, 0d, 0d); + if (dy1 != 0d || dx2 != 0d || latLonBox.Rotation != 0d) + { + // Skew matrix with skewX = Atan(-dx2 / dy2) and skewY = Atan(-dy1 / dx1). + // + var t = new Matrix(1d, -dy1 / dx1, -dx2 / dy2, 1d, 0d, 0d); + t.Rotate(-latLonBox.Rotation); + transform = t; + } } return (rect, transform);