From fa508f51e7d686c61693e914837ceb4e669e6f65 Mon Sep 17 00:00:00 2001 From: ClemensFischer Date: Mon, 15 Jul 2024 20:10:28 +0200 Subject: [PATCH] Replaced RenderSize by ActualWidth/Height --- MapControl/Avalonia/MapBase.Avalonia.cs | 3 ++- MapControl/Avalonia/PushpinBorder.Avalonia.cs | 3 ++- MapControl/Avalonia/ViewTransform.Avalonia.cs | 4 ++-- MapControl/Shared/MapBase.cs | 8 ++++---- MapControl/Shared/MapBorderPanel.cs | 4 ++-- MapControl/Shared/MapGraticule.cs | 14 ++++++------- MapControl/Shared/MapImageLayer.cs | 10 +++++----- MapControl/Shared/MapPanel.cs | 12 +++++------ MapControl/Shared/MapPath.cs | 4 ++-- MapControl/Shared/MapTileLayer.cs | 2 +- MapControl/Shared/PushpinBorder.cs | 4 ++-- MapControl/Shared/ViewTransform.cs | 6 ++---- MapControl/Shared/WmsImageLayer.cs | 18 ++++++++--------- MapControl/Shared/WmtsTileLayer.cs | 2 +- MapControl/Shared/WmtsTileMatrixLayer.cs | 4 ++-- MapControl/WinUI/MapPolypoint.WinUI.cs | 20 +++++++++++++++++-- 16 files changed, 67 insertions(+), 51 deletions(-) diff --git a/MapControl/Avalonia/MapBase.Avalonia.cs b/MapControl/Avalonia/MapBase.Avalonia.cs index 666becaf..4c4f127f 100644 --- a/MapControl/Avalonia/MapBase.Avalonia.cs +++ b/MapControl/Avalonia/MapBase.Avalonia.cs @@ -105,7 +105,8 @@ namespace MapControl Animation.RegisterCustomAnimator(); } - internal Size RenderSize => Bounds.Size; + public double ActualWidth => Bounds.Width; + public double ActualHeight => Bounds.Height; protected override void OnSizeChanged(SizeChangedEventArgs e) { diff --git a/MapControl/Avalonia/PushpinBorder.Avalonia.cs b/MapControl/Avalonia/PushpinBorder.Avalonia.cs index 08c48269..314c99b3 100644 --- a/MapControl/Avalonia/PushpinBorder.Avalonia.cs +++ b/MapControl/Avalonia/PushpinBorder.Avalonia.cs @@ -29,7 +29,8 @@ namespace MapControl AffectsRender(ArrowSizeProperty, BorderWidthProperty, CornerRadiusProperty, BackgroundProperty, BorderBrushProperty); } - private Size RenderSize => Bounds.Size; + public double ActualWidth => Bounds.Width; + public double ActualHeight => Bounds.Height; public CornerRadius CornerRadius { diff --git a/MapControl/Avalonia/ViewTransform.Avalonia.cs b/MapControl/Avalonia/ViewTransform.Avalonia.cs index 286431c0..d49776d6 100644 --- a/MapControl/Avalonia/ViewTransform.Avalonia.cs +++ b/MapControl/Avalonia/ViewTransform.Avalonia.cs @@ -123,7 +123,7 @@ namespace MapControl /// /// Gets the index bounds of a tile matrix. /// - public Rect GetTileMatrixBounds(double tileMatrixScale, Point tileMatrixTopLeft, Size viewSize) + public Rect GetTileMatrixBounds(double tileMatrixScale, Point tileMatrixTopLeft, double viewWidth, double viewHeight) { // View origin in map coordinates. // @@ -143,7 +143,7 @@ namespace MapControl // Transform view bounds to tile pixel bounds. // - return new Rect(0d, 0d, viewSize.Width, viewSize.Height).TransformToAABB(transform); + return new Rect(0d, 0d, viewWidth, viewHeight).TransformToAABB(transform); } internal static Matrix CreateTransformMatrix( diff --git a/MapControl/Shared/MapBase.cs b/MapControl/Shared/MapBase.cs index 62707cca..5e8215e5 100644 --- a/MapControl/Shared/MapBase.cs +++ b/MapControl/Shared/MapBase.cs @@ -255,7 +255,7 @@ namespace MapControl public void SetTransformCenter(Point center) { transformCenter = ViewToLocation(center); - viewCenter = transformCenter != null ? center : new Point(RenderSize.Width / 2d, RenderSize.Height / 2d); + viewCenter = transformCenter != null ? center : new Point(ActualWidth / 2d, ActualHeight / 2d); } /// @@ -264,7 +264,7 @@ namespace MapControl public void ResetTransformCenter() { transformCenter = null; - viewCenter = new Point(RenderSize.Width / 2d, RenderSize.Height / 2d); + viewCenter = new Point(ActualWidth / 2d, ActualHeight / 2d); } /// @@ -359,7 +359,7 @@ namespace MapControl if (targetCenter != null) { - var scale = Math.Min(RenderSize.Width / rect.Value.Width, RenderSize.Height / rect.Value.Height); + var scale = Math.Min(ActualWidth / rect.Value.Width, ActualHeight / rect.Value.Height); TargetZoomLevel = ViewTransform.ScaleToZoomLevel(scale); TargetCenter = targetCenter; @@ -510,7 +510,7 @@ namespace MapControl if (transformCenter != null) { - var center = ViewToLocation(new Point(RenderSize.Width / 2d, RenderSize.Height / 2d)); + var center = ViewToLocation(new Point(ActualWidth / 2d, ActualHeight / 2d)); if (center != null) { diff --git a/MapControl/Shared/MapBorderPanel.cs b/MapControl/Shared/MapBorderPanel.cs index 39e5c03d..957a6f75 100644 --- a/MapControl/Shared/MapBorderPanel.cs +++ b/MapControl/Shared/MapBorderPanel.cs @@ -40,8 +40,8 @@ namespace MapControl protected override void SetViewPosition(FrameworkElement element, ref Point? position) { var onBorder = false; - var w = ParentMap.RenderSize.Width; - var h = ParentMap.RenderSize.Height; + var w = ParentMap.ActualWidth; + var h = ParentMap.ActualHeight; var minX = BorderWidth / 2d; var minY = BorderWidth / 2d; var maxX = w - BorderWidth / 2d; diff --git a/MapControl/Shared/MapGraticule.cs b/MapControl/Shared/MapGraticule.cs index 77d97a9e..00d1c2ee 100644 --- a/MapControl/Shared/MapGraticule.cs +++ b/MapControl/Shared/MapGraticule.cs @@ -104,8 +104,8 @@ namespace MapControl private void AddLabel(ICollection protected virtual string GetFeatureInfoRequestUri(Point position, string format) { - var viewSize = ParentMap.RenderSize; - var boundingBox = ParentMap.ViewRectToBoundingBox(new Rect(0d, 0d, viewSize.Width, viewSize.Height)); - var rect = ParentMap.MapProjection.BoundingBoxToMap(boundingBox); + var viewport = new Rect(0d, 0d, ParentMap.ActualWidth, ParentMap.ActualHeight); + var boundingBox = ParentMap.ViewRectToBoundingBox(viewport); + var mapRect = ParentMap.MapProjection.BoundingBoxToMap(boundingBox); - if (!rect.HasValue) + if (!mapRect.HasValue) { return null; } - var viewRect = GetViewRect(rect.Value); + var viewRect = GetViewRect(mapRect.Value); var transform = ViewTransform.CreateTransformMatrix( - -viewSize.Width / 2d, -viewSize.Height / 2d, + -viewport.Width / 2d, -viewport.Height / 2d, -viewRect.Rotation, viewRect.Rect.Width / 2d, viewRect.Rect.Height / 2d); @@ -285,7 +285,7 @@ namespace MapControl { "FORMAT", "image/png" }, { "INFO_FORMAT", format }, { "CRS", GetCrsValue() }, - { "BBOX", GetBboxValue(rect.Value) }, + { "BBOX", GetBboxValue(mapRect.Value) }, { "WIDTH", Math.Round(viewRect.Rect.Width).ToString("F0") }, { "HEIGHT", Math.Round(viewRect.Rect.Height).ToString("F0") }, { "I", Math.Round(imagePos.X).ToString("F0") }, diff --git a/MapControl/Shared/WmtsTileLayer.cs b/MapControl/Shared/WmtsTileLayer.cs index 9bc816ac..893023b7 100644 --- a/MapControl/Shared/WmtsTileLayer.cs +++ b/MapControl/Shared/WmtsTileLayer.cs @@ -154,7 +154,7 @@ namespace MapControl var layer = currentLayers.FirstOrDefault(l => l.WmtsTileMatrix == tileMatrix) ?? new WmtsTileMatrixLayer(tileMatrix, tileMatrixSet.TileMatrixes.IndexOf(tileMatrix)); - if (layer.UpdateTiles(ParentMap.ViewTransform, ParentMap.RenderSize)) + if (layer.UpdateTiles(ParentMap.ViewTransform, ParentMap.ActualWidth, ParentMap.ActualHeight)) { tilesChanged = true; } diff --git a/MapControl/Shared/WmtsTileMatrixLayer.cs b/MapControl/Shared/WmtsTileMatrixLayer.cs index 87062ddf..8e0bc955 100644 --- a/MapControl/Shared/WmtsTileMatrixLayer.cs +++ b/MapControl/Shared/WmtsTileMatrixLayer.cs @@ -47,11 +47,11 @@ namespace MapControl viewTransform.GetTileLayerTransform(WmtsTileMatrix.Scale, WmtsTileMatrix.TopLeft, tileMatrixOrigin); } - public bool UpdateTiles(ViewTransform viewTransform, Size viewSize) + public bool UpdateTiles(ViewTransform viewTransform, double viewWidth, double viewHeight) { // Bounds in tile pixels from view size. // - var bounds = viewTransform.GetTileMatrixBounds(WmtsTileMatrix.Scale, WmtsTileMatrix.TopLeft, viewSize); + var bounds = viewTransform.GetTileMatrixBounds(WmtsTileMatrix.Scale, WmtsTileMatrix.TopLeft, viewWidth, viewHeight); // Tile X and Y bounds. // diff --git a/MapControl/WinUI/MapPolypoint.WinUI.cs b/MapControl/WinUI/MapPolypoint.WinUI.cs index f2891d3e..d6c6e5d3 100644 --- a/MapControl/WinUI/MapPolypoint.WinUI.cs +++ b/MapControl/WinUI/MapPolypoint.WinUI.cs @@ -2,6 +2,7 @@ // Copyright © 2024 Clemens Fischer // Licensed under the Microsoft Public License (Ms-PL) +using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; @@ -78,9 +79,15 @@ namespace MapControl if (points.Any()) { + var startPoint = points.First(); + var minX = startPoint.X; + var maxX = startPoint.X; + var minY = startPoint.Y; + var maxY = startPoint.Y; + var figure = new PathFigure { - StartPoint = points.First(), + StartPoint = startPoint, IsClosed = closed, IsFilled = true }; @@ -89,10 +96,19 @@ namespace MapControl foreach (var point in points.Skip(1)) { + minX = Math.Min(minX, point.X); + maxX = Math.Max(maxX, point.X); + minY = Math.Min(minY, point.Y); + maxY = Math.Max(maxY, point.Y); polyline.Points.Add(point); } - figure.Segments.Add(polyline); + if (maxX >= 0 && minX <= ParentMap.ActualWidth && + maxY >= 0 && minY <= ParentMap.ActualHeight) + { + figure.Segments.Add(polyline); + } + pathFigures.Add(figure); } }