From 107b8e0f90f4ad6c081a0e4084e24eca73d6a999 Mon Sep 17 00:00:00 2001 From: ClemensFischer Date: Fri, 5 Dec 2025 14:44:33 +0100 Subject: [PATCH] Reverted new() expressions --- MapControl/Shared/BoundingBox.cs | 2 +- MapControl/Shared/MapBase.cs | 2 +- MapControl/Shared/MapProjection.cs | 4 +- MapControl/Shared/MapScale.cs | 4 +- MapControl/Shared/MapTileLayer.cs | 6 +-- MapControl/Shared/TileImageLoader.cs | 2 +- MapControl/WPF/DrawingTileMatrixLayer.cs | 53 ++++++++++++++++----- MapUiTools/Avalonia/MapMenuItem.Avalonia.cs | 2 +- 8 files changed, 52 insertions(+), 23 deletions(-) diff --git a/MapControl/Shared/BoundingBox.cs b/MapControl/Shared/BoundingBox.cs index 4d5eecfd..5d4ad5f2 100644 --- a/MapControl/Shared/BoundingBox.cs +++ b/MapControl/Shared/BoundingBox.cs @@ -38,7 +38,7 @@ namespace MapControl public virtual double Width => East - West; public virtual double Height => North - South; - public virtual Location Center => new((South + North) / 2d, (West + East) / 2d); + public virtual Location Center => new Location((South + North) / 2d, (West + East) / 2d); public override string ToString() { diff --git a/MapControl/Shared/MapBase.cs b/MapControl/Shared/MapBase.cs index 11c0ab28..18925dbc 100644 --- a/MapControl/Shared/MapBase.cs +++ b/MapControl/Shared/MapBase.cs @@ -174,7 +174,7 @@ namespace MapControl /// Gets the ViewTransform instance that is used to transform between projected /// map coordinates and view coordinates. /// - public ViewTransform ViewTransform { get; } = new(); + public ViewTransform ViewTransform { get; } = new ViewTransform(); /// /// Gets the map scale as horizontal and vertical scaling factors from meters to diff --git a/MapControl/Shared/MapProjection.cs b/MapControl/Shared/MapProjection.cs index d9af8e94..f5451202 100644 --- a/MapControl/Shared/MapProjection.cs +++ b/MapControl/Shared/MapProjection.cs @@ -52,12 +52,12 @@ namespace MapControl /// /// Gets or sets an optional projection center. /// - public virtual Location Center { get; protected internal set; } = new(); + public virtual Location Center { get; protected internal set; } = new Location(); /// /// Gets the relative map scale at the specified Location. /// - public virtual Point GetRelativeScale(Location location) => new(1d, 1d); + public virtual Point GetRelativeScale(Location location) => new Point(1d, 1d); /// /// Transforms a Location in geographic coordinates to a Point in projected map coordinates. diff --git a/MapControl/Shared/MapScale.cs b/MapControl/Shared/MapScale.cs index f6ba4fef..7e714660 100644 --- a/MapControl/Shared/MapScale.cs +++ b/MapControl/Shared/MapScale.cs @@ -55,9 +55,9 @@ namespace MapControl set => SetValue(StrokeThicknessProperty, value); } - private readonly Polyline line = new(); + private readonly Polyline line = new Polyline(); - private readonly TextBlock label = new() + private readonly TextBlock label = new TextBlock { HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center diff --git a/MapControl/Shared/MapTileLayer.cs b/MapControl/Shared/MapTileLayer.cs index 0023d8b1..43ebbad3 100644 --- a/MapControl/Shared/MapTileLayer.cs +++ b/MapControl/Shared/MapTileLayer.cs @@ -26,8 +26,8 @@ namespace MapControl { private const int tileSize = 256; - private static readonly Point mapTopLeft = new(-180d * MapProjection.Wgs84MeterPerDegree, - 180d * MapProjection.Wgs84MeterPerDegree); + private static readonly Point mapTopLeft = new Point(-180d * MapProjection.Wgs84MeterPerDegree, + 180d * MapProjection.Wgs84MeterPerDegree); public static readonly DependencyProperty TileSourceProperty = DependencyPropertyHelper.Register(nameof(TileSource), null, @@ -45,7 +45,7 @@ namespace MapControl /// /// A default MapTileLayer using OpenStreetMap data. /// - public static MapTileLayer OpenStreetMapTileLayer => new() + public static MapTileLayer OpenStreetMapTileLayer => new MapTileLayer { TileSource = TileSource.Parse("https://tile.openstreetmap.org/{z}/{x}/{y}.png"), SourceName = "OpenStreetMap", diff --git a/MapControl/Shared/TileImageLoader.cs b/MapControl/Shared/TileImageLoader.cs index 9fcb6942..cc560b68 100644 --- a/MapControl/Shared/TileImageLoader.cs +++ b/MapControl/Shared/TileImageLoader.cs @@ -70,7 +70,7 @@ namespace MapControl /// public static int MaxLoadTasks { get; set; } = 4; - private readonly Queue tileQueue = new(); + private readonly Queue tileQueue = new Queue(); private int tileCount; private int taskCount; diff --git a/MapControl/WPF/DrawingTileMatrixLayer.cs b/MapControl/WPF/DrawingTileMatrixLayer.cs index 14bc470b..a0f12b94 100644 --- a/MapControl/WPF/DrawingTileMatrixLayer.cs +++ b/MapControl/WPF/DrawingTileMatrixLayer.cs @@ -4,22 +4,55 @@ using System.Linq; using System.Threading.Tasks; using System.Windows; using System.Windows.Media; +using System.Windows.Media.Animation; namespace MapControl { - public class ImageDrawingTile(int zoomLevel, int x, int y, int columnCount) - : Tile(zoomLevel, x, y, columnCount) + public class ImageDrawingTile : Tile { - public ImageDrawing Drawing { get; } = new ImageDrawing(); + private readonly ImageDrawing imageDrawing = new ImageDrawing(); + + public ImageDrawingTile(int zoomLevel, int x, int y, int columnCount) + : base(zoomLevel, x, y, columnCount) + { + Drawing.Children.Add(imageDrawing); + } + + public DrawingGroup Drawing { get; } = new DrawingGroup(); + + public ImageSource ImageSource + { + get => imageDrawing.ImageSource; + set => imageDrawing.ImageSource = value; + } + + public void SetRect(int xMin, int yMin, int tileWidth, int tileHeight) + { + imageDrawing.Rect = new Rect(tileWidth * (X - xMin), tileHeight * (Y - yMin), tileWidth, tileHeight); + } public override async Task LoadImageAsync(Func> loadImageFunc) { var image = await loadImageFunc().ConfigureAwait(false); - if (image != null) + void SetImageSource() { - await Drawing.Dispatcher.InvokeAsync(() => Drawing.ImageSource = image); + imageDrawing.ImageSource = image; + + if (image != null && MapBase.ImageFadeDuration > TimeSpan.Zero) + { + var fadeInAnimation = new DoubleAnimation + { + From = 0d, + Duration = MapBase.ImageFadeDuration, + FillBehavior = FillBehavior.Stop + }; + + Drawing.BeginAnimation(DrawingGroup.OpacityProperty, fadeInAnimation); + } } + + await Drawing.Dispatcher.InvokeAsync(SetImageSource); } } @@ -105,20 +138,16 @@ namespace MapControl { tile = new ImageDrawingTile(TileMatrix.ZoomLevel, x, y, WmtsTileMatrix.MatrixWidth); - var equivalentTile = Tiles.FirstOrDefault(t => t.Drawing.ImageSource != null && t.Column == tile.Column && t.Row == tile.Row); + var equivalentTile = Tiles.FirstOrDefault(t => t.ImageSource != null && t.Column == tile.Column && t.Row == tile.Row); if (equivalentTile != null) { tile.IsPending = false; - tile.Drawing.ImageSource = equivalentTile.Drawing.ImageSource; + tile.ImageSource = equivalentTile.ImageSource; } } - tile.Drawing.Rect = new Rect( - WmtsTileMatrix.TileWidth * (x - TileMatrix.XMin), - WmtsTileMatrix.TileHeight * (y - TileMatrix.YMin), - WmtsTileMatrix.TileWidth, - WmtsTileMatrix.TileHeight); + tile.SetRect(TileMatrix.XMin, TileMatrix.YMin, WmtsTileMatrix.TileWidth, WmtsTileMatrix.TileHeight); tiles.Add(tile); drawings.Add(tile.Drawing); diff --git a/MapUiTools/Avalonia/MapMenuItem.Avalonia.cs b/MapUiTools/Avalonia/MapMenuItem.Avalonia.cs index 177f5bab..89492bae 100644 --- a/MapUiTools/Avalonia/MapMenuItem.Avalonia.cs +++ b/MapUiTools/Avalonia/MapMenuItem.Avalonia.cs @@ -13,7 +13,7 @@ namespace MapControl.UiTools { Icon = new TextBlock { - FontFamily = new("Segoe MDL2 Assets"), + FontFamily = new FontFamily("Segoe MDL2 Assets"), FontWeight = FontWeight.Black, VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center, };