Reverted new() expressions

This commit is contained in:
ClemensFischer 2025-12-05 14:44:33 +01:00
parent 264f751d4e
commit 107b8e0f90
8 changed files with 52 additions and 23 deletions

View file

@ -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()
{

View file

@ -174,7 +174,7 @@ namespace MapControl
/// Gets the ViewTransform instance that is used to transform between projected
/// map coordinates and view coordinates.
/// </summary>
public ViewTransform ViewTransform { get; } = new();
public ViewTransform ViewTransform { get; } = new ViewTransform();
/// <summary>
/// Gets the map scale as horizontal and vertical scaling factors from meters to

View file

@ -52,12 +52,12 @@ namespace MapControl
/// <summary>
/// Gets or sets an optional projection center.
/// </summary>
public virtual Location Center { get; protected internal set; } = new();
public virtual Location Center { get; protected internal set; } = new Location();
/// <summary>
/// Gets the relative map scale at the specified Location.
/// </summary>
public virtual Point GetRelativeScale(Location location) => new(1d, 1d);
public virtual Point GetRelativeScale(Location location) => new Point(1d, 1d);
/// <summary>
/// Transforms a Location in geographic coordinates to a Point in projected map coordinates.

View file

@ -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

View file

@ -26,7 +26,7 @@ namespace MapControl
{
private const int tileSize = 256;
private static readonly Point mapTopLeft = new(-180d * MapProjection.Wgs84MeterPerDegree,
private static readonly Point mapTopLeft = new Point(-180d * MapProjection.Wgs84MeterPerDegree,
180d * MapProjection.Wgs84MeterPerDegree);
public static readonly DependencyProperty TileSourceProperty =
@ -45,7 +45,7 @@ namespace MapControl
/// <summary>
/// A default MapTileLayer using OpenStreetMap data.
/// </summary>
public static MapTileLayer OpenStreetMapTileLayer => new()
public static MapTileLayer OpenStreetMapTileLayer => new MapTileLayer
{
TileSource = TileSource.Parse("https://tile.openstreetmap.org/{z}/{x}/{y}.png"),
SourceName = "OpenStreetMap",

View file

@ -70,7 +70,7 @@ namespace MapControl
/// </summary>
public static int MaxLoadTasks { get; set; } = 4;
private readonly Queue<Tile> tileQueue = new();
private readonly Queue<Tile> tileQueue = new Queue<Tile>();
private int tileCount;
private int taskCount;

View file

@ -4,23 +4,56 @@ 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<Task<ImageSource>> 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);
}
}
public class DrawingTileMatrixLayer(WmtsTileMatrix wmtsTileMatrix, int zoomLevel) : UIElement
@ -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);

View file

@ -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,
};