Updated LatLonBoxToMap

This commit is contained in:
ClemensFischer 2026-01-26 23:44:59 +01:00
parent dbc4c142f7
commit 05032dbd25
2 changed files with 25 additions and 22 deletions

View file

@ -287,7 +287,7 @@ namespace MapControl
private void ArrangeElement(FrameworkElement element, BoundingBox boundingBox) private void ArrangeElement(FrameworkElement element, BoundingBox boundingBox)
{ {
Rect? mapRect; Rect? mapRect;
Matrix transform; Matrix? transform = null;
if (boundingBox is LatLonBox latLonBox) if (boundingBox is LatLonBox latLonBox)
{ {
@ -296,7 +296,6 @@ namespace MapControl
else else
{ {
mapRect = parentMap.MapProjection.BoundingBoxToMap(boundingBox); mapRect = parentMap.MapProjection.BoundingBoxToMap(boundingBox);
transform = new Matrix(1d, 0d, 0d, 1d, 0d, 0d);
} }
if (mapRect.HasValue) if (mapRect.HasValue)
@ -307,19 +306,23 @@ namespace MapControl
element.Height = viewRect.Height; element.Height = viewRect.Height;
element.Arrange(viewRect); element.Arrange(viewRect);
transform.Rotate(parentMap.ViewTransform.Rotation); if (parentMap.ViewTransform.Rotation != 0d)
if (element.RenderTransform is MatrixTransform matrixTransform
#if WPF
&& !matrixTransform.IsFrozen
#endif
)
{ {
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 else
{ {
element.SetRenderTransform(new MatrixTransform { Matrix = transform }, true); element.ClearValue(RenderTransformProperty);
} }
} }
} }

View file

@ -163,12 +163,12 @@ namespace MapControl
/// <summary> /// <summary>
/// Transforms a LatLonBox in geographic coordinates to a rotated Rect in projected map coordinates. /// 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.
/// </summary> /// </summary>
public (Rect?, Matrix) LatLonBoxToMap(LatLonBox latLonBox) public (Rect?, Matrix?) LatLonBoxToMap(LatLonBox latLonBox)
{ {
Rect? rect = null; Rect? rect = null;
Matrix transform; Matrix? transform = null;
var sw = LocationToMap(latLonBox.South, latLonBox.West); var sw = LocationToMap(latLonBox.South, latLonBox.West);
var se = LocationToMap(latLonBox.South, latLonBox.East); var se = LocationToMap(latLonBox.South, latLonBox.East);
var nw = LocationToMap(latLonBox.North, latLonBox.West); var nw = LocationToMap(latLonBox.North, latLonBox.West);
@ -192,14 +192,14 @@ namespace MapControl
rect = new Rect(x, y, width, height); rect = new Rect(x, y, width, height);
// Skew matrix with skewX = Atan(-dx2 / dy2) and skewY = Atan(-dy1 / dx1). if (dy1 != 0d || dx2 != 0d || latLonBox.Rotation != 0d)
// {
transform = new Matrix(1d, -dy1 / dx1, -dx2 / dy2, 1d, 0d, 0d); // Skew matrix with skewX = Atan(-dx2 / dy2) and skewY = Atan(-dy1 / dx1).
transform.Rotate(-latLonBox.Rotation); //
} var t = new Matrix(1d, -dy1 / dx1, -dx2 / dy2, 1d, 0d, 0d);
else t.Rotate(-latLonBox.Rotation);
{ transform = t;
transform = new Matrix(1d, 0d, 0d, 1d, 0d, 0d); }
} }
return (rect, transform); return (rect, transform);