CsWinRT1028, C# LangVersion 12

This commit is contained in:
ClemensFischer 2025-09-15 17:46:31 +02:00
parent e1a4ba3fd6
commit c0783efb4a
27 changed files with 67 additions and 119 deletions

View file

@ -2,17 +2,10 @@
namespace MapControl namespace MapControl
{ {
public class CenteredBoundingBox : BoundingBox public class CenteredBoundingBox(Location center, double width, double height) : BoundingBox
{ {
public CenteredBoundingBox(Location center, double width, double height) public override Location Center { get; } = center;
{ public override double Width { get; } = Math.Max(width, 0d);
Center = center; public override double Height { get; } = Math.Max(height, 0d);
Width = Math.Max(width, 0d);
Height = Math.Max(height, 0d);
}
public override Location Center { get; }
public override double Width { get; }
public override double Height { get; }
} }
} }

View file

@ -6,10 +6,10 @@ namespace MapControl
{ {
public static string GetFullPath(string path) public static string GetFullPath(string path)
{ {
#if NET6_0_OR_GREATER #if NETFRAMEWORK
return Path.GetFullPath(path, System.AppDomain.CurrentDomain.BaseDirectory);
#else
return Path.GetFullPath(path); return Path.GetFullPath(path);
#else
return Path.GetFullPath(path, System.AppDomain.CurrentDomain.BaseDirectory);
#endif #endif
} }
} }

View file

@ -26,7 +26,7 @@ using Avalonia.Media;
namespace MapControl namespace MapControl
{ {
public class GroundOverlay : MapPanel public partial class GroundOverlay : MapPanel
{ {
private class ImageOverlay private class ImageOverlay
{ {

View file

@ -23,7 +23,7 @@ namespace MapControl.Caching
/// IDistributedCache implementation that creates a single file per cache entry. /// IDistributedCache implementation that creates a single file per cache entry.
/// The cache expiration time is stored in the file's CreationTime property. /// The cache expiration time is stored in the file's CreationTime property.
/// </summary> /// </summary>
public sealed class ImageFileCache : IDistributedCache, IDisposable public sealed partial class ImageFileCache : IDistributedCache, IDisposable
{ {
private readonly MemoryDistributedCache memoryCache; private readonly MemoryDistributedCache memoryCache;
private readonly DirectoryInfo rootDirectory; private readonly DirectoryInfo rootDirectory;

View file

@ -13,7 +13,7 @@ namespace MapControl
#else #else
[System.ComponentModel.TypeConverter(typeof(LocationCollectionConverter))] [System.ComponentModel.TypeConverter(typeof(LocationCollectionConverter))]
#endif #endif
public class LocationCollection : List<Location> public partial class LocationCollection : List<Location>
{ {
public LocationCollection() public LocationCollection()
{ {

View file

@ -16,7 +16,7 @@ namespace MapControl
/// Such elements are arranged at a distance of BorderWidth/2 from the edges of the /// Such elements are arranged at a distance of BorderWidth/2 from the edges of the
/// MapBorderPanel in direction of their original azimuth from the map center. /// MapBorderPanel in direction of their original azimuth from the map center.
/// </summary> /// </summary>
public class MapBorderPanel : MapPanel public partial class MapBorderPanel : MapPanel
{ {
public static readonly DependencyProperty BorderWidthProperty = public static readonly DependencyProperty BorderWidthProperty =
DependencyPropertyHelper.Register<MapBorderPanel, double>(nameof(BorderWidth)); DependencyPropertyHelper.Register<MapBorderPanel, double>(nameof(BorderWidth));

View file

@ -24,22 +24,13 @@ namespace MapControl
/// </summary> /// </summary>
public partial class MapGraticule public partial class MapGraticule
{ {
private class Label private class Label(string latText, string lonText, double x, double y, double rotation)
{ {
public Label(string latText, string lonText, double x, double y, double rotation) public string LatitudeText { get; } = latText;
{ public string LongitudeText { get; } = lonText;
LatitudeText = latText; public double X { get; } = x;
LongitudeText = lonText; public double Y { get; } = y;
X = x; public double Rotation { get; } = rotation;
Y = y;
Rotation = rotation;
}
public string LatitudeText { get; }
public string LongitudeText { get; }
public double X { get; }
public double Y { get; }
public double Rotation { get; }
} }
private const double LineInterpolationResolution = 2d; private const double LineInterpolationResolution = 2d;

View file

@ -17,7 +17,7 @@ namespace MapControl
/// for the Polygons property if collection changes of the property itself and its /// for the Polygons property if collection changes of the property itself and its
/// elements are both supposed to trigger UI updates. /// elements are both supposed to trigger UI updates.
/// </summary> /// </summary>
public class MapMultiPolygon : MapPolypoint public partial class MapMultiPolygon : MapPolypoint
{ {
public static readonly DependencyProperty PolygonsProperty = public static readonly DependencyProperty PolygonsProperty =
DependencyPropertyHelper.Register<MapMultiPolygon, IEnumerable<IEnumerable<Location>>>(nameof(Polygons), null, DependencyPropertyHelper.Register<MapMultiPolygon, IEnumerable<IEnumerable<Location>>>(nameof(Polygons), null,

View file

@ -16,7 +16,7 @@ namespace MapControl
/// <summary> /// <summary>
/// A MapPanel with a collection of GroundOverlay or GeoImage children. /// A MapPanel with a collection of GroundOverlay or GeoImage children.
/// </summary> /// </summary>
public class MapOverlaysPanel : MapPanel public partial class MapOverlaysPanel : MapPanel
{ {
public static readonly DependencyProperty SourcePathsProperty = public static readonly DependencyProperty SourcePathsProperty =
DependencyPropertyHelper.Register<MapOverlaysPanel, IEnumerable<string>>(nameof(SourcePaths), null, DependencyPropertyHelper.Register<MapOverlaysPanel, IEnumerable<string>>(nameof(SourcePaths), null,

View file

@ -12,7 +12,7 @@ namespace MapControl
/// <summary> /// <summary>
/// A polygon defined by a collection of Locations. /// A polygon defined by a collection of Locations.
/// </summary> /// </summary>
public class MapPolygon : MapPolypoint public partial class MapPolygon : MapPolypoint
{ {
public static readonly DependencyProperty LocationsProperty = public static readonly DependencyProperty LocationsProperty =
DependencyPropertyHelper.Register<MapPolygon, IEnumerable<Location>>(nameof(Locations), null, DependencyPropertyHelper.Register<MapPolygon, IEnumerable<Location>>(nameof(Locations), null,

View file

@ -12,7 +12,7 @@ namespace MapControl
/// <summary> /// <summary>
/// A polyline defined by a collection of Locations. /// A polyline defined by a collection of Locations.
/// </summary> /// </summary>
public class MapPolyline : MapPolypoint public partial class MapPolyline : MapPolypoint
{ {
public static readonly DependencyProperty LocationsProperty = public static readonly DependencyProperty LocationsProperty =
DependencyPropertyHelper.Register<MapPolyline, IEnumerable<Location>>(nameof(Locations), null, DependencyPropertyHelper.Register<MapPolyline, IEnumerable<Location>>(nameof(Locations), null,

View file

@ -34,7 +34,7 @@ namespace MapControl
/// <summary> /// <summary>
/// Draws a map scale overlay. /// Draws a map scale overlay.
/// </summary> /// </summary>
public class MapScale : MapPanel public partial class MapScale : MapPanel
{ {
public static readonly DependencyProperty PaddingProperty = public static readonly DependencyProperty PaddingProperty =
DependencyPropertyHelper.Register<MapScale, Thickness>(nameof(Padding), new Thickness(4)); DependencyPropertyHelper.Register<MapScale, Thickness>(nameof(Padding), new Thickness(4));

View file

@ -20,7 +20,7 @@ namespace MapControl
/// <summary> /// <summary>
/// Displays a standard Web Mercator map tile grid, e.g. an OpenStreetMap tile grid. /// Displays a standard Web Mercator map tile grid, e.g. an OpenStreetMap tile grid.
/// </summary> /// </summary>
public class MapTileLayer : MapTileLayerBase public partial class MapTileLayer : MapTileLayerBase
{ {
public static readonly DependencyProperty MinZoomLevelProperty = public static readonly DependencyProperty MinZoomLevelProperty =
DependencyPropertyHelper.Register<MapTileLayer, int>(nameof(MinZoomLevel), 0); DependencyPropertyHelper.Register<MapTileLayer, int>(nameof(MinZoomLevel), 0);

View file

@ -10,7 +10,7 @@ namespace MapControl
/// listener to each element that implements INotifyCollectionChanged and, when such an element changes, /// listener to each element that implements INotifyCollectionChanged and, when such an element changes,
/// fires its own CollectionChanged event with NotifyCollectionChangedAction.Replace for that element. /// fires its own CollectionChanged event with NotifyCollectionChangedAction.Replace for that element.
/// </summary> /// </summary>
public class PolygonCollection : ObservableCollection<IEnumerable<Location>> public partial class PolygonCollection : ObservableCollection<IEnumerable<Location>>
{ {
private void PolygonChanged(object sender, NotifyCollectionChangedEventArgs e) private void PolygonChanged(object sender, NotifyCollectionChangedEventArgs e)
{ {

View file

@ -14,22 +14,15 @@ using Avalonia.Media;
namespace MapControl namespace MapControl
{ {
public partial class Tile public partial class Tile(int zoomLevel, int x, int y, int columnCount)
{ {
public Tile(int zoomLevel, int x, int y, int columnCount) public int ZoomLevel { get; } = zoomLevel;
{ public int X { get; } = x;
ZoomLevel = zoomLevel; public int Y { get; } = y;
X = x; public int Column { get; } = ((x % columnCount) + columnCount) % columnCount;
Y = y; public int Row => Y;
Column = ((x % columnCount) + columnCount) % columnCount;
}
public Image Image { get; } = new Image { Stretch = Stretch.Fill }; public Image Image { get; } = new Image { Stretch = Stretch.Fill };
public int ZoomLevel { get; }
public int X { get; }
public int Y { get; }
public int Column { get; }
public int Row => Y;
public bool IsPending { get; set; } = true; public bool IsPending { get; set; } = true;
} }
} }

View file

@ -3,7 +3,7 @@ using System.Linq;
namespace MapControl namespace MapControl
{ {
public class TileCollection : List<Tile> public partial class TileCollection : List<Tile>
{ {
/// <summary> /// <summary>
/// Adds existing Tiles from the source collection or newly created Tiles to fill the specified tile matrix. /// Adds existing Tiles from the source collection or newly created Tiles to fill the specified tile matrix.

View file

@ -1,20 +1,11 @@
namespace MapControl namespace MapControl
{ {
public class TileMatrix public class TileMatrix(int zoomLevel, int xMin, int yMin, int xMax, int yMax)
{ {
public TileMatrix(int zoomLevel, int xMin, int yMin, int xMax, int yMax) public int ZoomLevel { get; } = zoomLevel;
{ public int XMin { get; } = xMin;
ZoomLevel = zoomLevel; public int YMin { get; } = yMin;
XMin = xMin; public int XMax { get; } = xMax;
YMin = yMin; public int YMax { get; } = yMax;
XMax = xMax;
YMax = yMax;
}
public int ZoomLevel { get; }
public int XMin { get; }
public int YMin { get; }
public int XMax { get; }
public int YMax { get; }
} }
} }

View file

@ -18,7 +18,7 @@ using ConverterCulture = System.Globalization.CultureInfo;
namespace MapControl namespace MapControl
{ {
public class LocationConverter : TypeConverter, IValueConverter public partial class LocationConverter : TypeConverter, IValueConverter
{ {
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{ {
@ -41,7 +41,7 @@ namespace MapControl
} }
} }
public class LocationCollectionConverter : TypeConverter, IValueConverter public partial class LocationCollectionConverter : TypeConverter, IValueConverter
{ {
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{ {
@ -64,7 +64,7 @@ namespace MapControl
} }
} }
public class BoundingBoxConverter : TypeConverter, IValueConverter public partial class BoundingBoxConverter : TypeConverter, IValueConverter
{ {
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{ {
@ -87,7 +87,7 @@ namespace MapControl
} }
} }
public class TileSourceConverter : TypeConverter, IValueConverter public partial class TileSourceConverter : TypeConverter, IValueConverter
{ {
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{ {

View file

@ -2,25 +2,19 @@
namespace MapControl namespace MapControl
{ {
public class ViewportChangedEventArgs : EventArgs public class ViewportChangedEventArgs(bool projectionChanged = false, bool transformCenterChanged = false) : EventArgs
{ {
public ViewportChangedEventArgs(bool projectionChanged = false, bool transformCenterChanged = false)
{
ProjectionChanged = projectionChanged;
TransformCenterChanged = transformCenterChanged;
}
/// <summary> /// <summary>
/// Indicates that the map projection has changed. Used to control when /// Indicates that the map projection has changed. Used to control when
/// a MapTileLayer or a MapImageLayer should be updated immediately, /// a MapTileLayer or a MapImageLayer should be updated immediately,
/// or MapPath Data in projected map coordinates should be recalculated. /// or MapPath Data in projected map coordinates should be recalculated.
/// </summary> /// </summary>
public bool ProjectionChanged { get; } public bool ProjectionChanged { get; } = projectionChanged;
/// <summary> /// <summary>
/// Indicates that the view transform center has moved across 180° longitude. /// Indicates that the view transform center has moved across 180° longitude.
/// Used to control when a MapTileLayer should be updated immediately. /// Used to control when a MapTileLayer should be updated immediately.
/// </summary> /// </summary>
public bool TransformCenterChanged { get; } public bool TransformCenterChanged { get; } = transformCenterChanged;
} }
} }

View file

@ -23,7 +23,7 @@ namespace MapControl
/// <summary> /// <summary>
/// Displays a single map image from a Web Map Service (WMS). /// Displays a single map image from a Web Map Service (WMS).
/// </summary> /// </summary>
public class WmsImageLayer : MapImageLayer public partial class WmsImageLayer : MapImageLayer
{ {
private static ILogger logger; private static ILogger logger;
private static ILogger Logger => logger ??= ImageLoader.LoggerFactory?.CreateLogger<GroundOverlay>(); private static ILogger Logger => logger ??= ImageLoader.LoggerFactory?.CreateLogger<GroundOverlay>();

View file

@ -20,7 +20,7 @@ namespace MapControl
/// <summary> /// <summary>
/// Displays map tiles from a Web Map Tile Service (WMTS). /// Displays map tiles from a Web Map Tile Service (WMTS).
/// </summary> /// </summary>
public class WmtsTileLayer : MapTileLayerBase public partial class WmtsTileLayer : MapTileLayerBase
{ {
private static ILogger logger; private static ILogger logger;
private static ILogger Logger => logger ??= ImageLoader.LoggerFactory?.CreateLogger<GroundOverlay>(); private static ILogger Logger => logger ??= ImageLoader.LoggerFactory?.CreateLogger<GroundOverlay>();
@ -70,7 +70,7 @@ namespace MapControl
public IEnumerable<WmtsTileMatrixLayer> ChildLayers => Children.Cast<WmtsTileMatrixLayer>(); public IEnumerable<WmtsTileMatrixLayer> ChildLayers => Children.Cast<WmtsTileMatrixLayer>();
public Dictionary<string, WmtsTileMatrixSet> TileMatrixSets { get; } = new Dictionary<string, WmtsTileMatrixSet>(); public Dictionary<string, WmtsTileMatrixSet> TileMatrixSets { get; } = [];
protected virtual WmtsTileSource CreateTileSource(string uriTemplate) => new WmtsTileSource { UriTemplate = uriTemplate }; protected virtual WmtsTileSource CreateTileSource(string uriTemplate) => new WmtsTileSource { UriTemplate = uriTemplate };

View file

@ -6,29 +6,19 @@ using Avalonia;
namespace MapControl namespace MapControl
{ {
public class WmtsTileMatrix // See 07-057r7_Web_Map_Tile_Service_Standard.pdf, section 6.1.a, page 8:
// "standardized rendering pixel size" is 0.28 mm
//
public class WmtsTileMatrix(
string identifier, double scaleDenominator, Point topLeft,
int tileWidth, int tileHeight, int matrixWidth, int matrixHeight)
{ {
// See 07-057r7_Web_Map_Tile_Service_Standard.pdf, section 6.1.a, page 8: public string Identifier { get; } = identifier;
// "standardized rendering pixel size" is 0.28 mm public double Scale { get; } = 1 / (scaleDenominator * 0.00028); // 0.28 mm
public Point TopLeft { get; } = topLeft;
public WmtsTileMatrix(string identifier, double scaleDenominator, Point topLeft, public int TileWidth { get; } = tileWidth;
int tileWidth, int tileHeight, int matrixWidth, int matrixHeight) public int TileHeight { get; } = tileHeight;
{ public int MatrixWidth { get; } = matrixWidth;
Identifier = identifier; public int MatrixHeight { get; } = matrixHeight;
Scale = 1 / (scaleDenominator * 0.00028); // 0.28 mm
TopLeft = topLeft;
TileWidth = tileWidth;
TileHeight = tileHeight;
MatrixWidth = matrixWidth;
MatrixHeight = matrixHeight;
}
public string Identifier { get; }
public double Scale { get; }
public Point TopLeft { get; }
public int TileWidth { get; }
public int TileHeight { get; }
public int MatrixWidth { get; }
public int MatrixHeight { get; }
} }
} }

View file

@ -19,7 +19,7 @@ using Avalonia.Media;
namespace MapControl namespace MapControl
{ {
public class WmtsTileMatrixLayer : Panel public partial class WmtsTileMatrixLayer : Panel
{ {
// zoomLevel is index of tileMatrix in a WmtsTileMatrixSet.TileMatrixes list. // zoomLevel is index of tileMatrix in a WmtsTileMatrixSet.TileMatrixes list.
// //

View file

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net9.0-windows;net462</TargetFrameworks> <TargetFrameworks>net9.0-windows;net462</TargetFrameworks>
<LangVersion Condition="'$(TargetFramework)'=='net462'">8.0</LangVersion> <LangVersion Condition="'$(TargetFramework)'=='net462'">12.0</LangVersion>
<UseWPF>true</UseWPF> <UseWPF>true</UseWPF>
<DefineConstants>WPF</DefineConstants> <DefineConstants>WPF</DefineConstants>
<RootNamespace>MapControl</RootNamespace> <RootNamespace>MapControl</RootNamespace>

View file

@ -13,7 +13,7 @@ namespace MapControl
/// <summary> /// <summary>
/// ContentControl placed on a MapPanel at a geographic location specified by the Location property. /// ContentControl placed on a MapPanel at a geographic location specified by the Location property.
/// </summary> /// </summary>
public class MapContentControl : ContentControl public partial class MapContentControl : ContentControl
{ {
public static readonly DependencyProperty AutoCollapseProperty = public static readonly DependencyProperty AutoCollapseProperty =
DependencyPropertyHelper.Register<MapContentControl, bool>(nameof(AutoCollapse), false, DependencyPropertyHelper.Register<MapContentControl, bool>(nameof(AutoCollapse), false,
@ -79,7 +79,7 @@ namespace MapControl
/// <summary> /// <summary>
/// MapContentControl with a Pushpin Style. /// MapContentControl with a Pushpin Style.
/// </summary> /// </summary>
public class Pushpin : MapContentControl public partial class Pushpin : MapContentControl
{ {
public Pushpin() public Pushpin()
{ {

View file

@ -16,7 +16,7 @@ namespace MapControl
/// <summary> /// <summary>
/// Base class of MapPolyline and MapPolygon. /// Base class of MapPolyline and MapPolygon.
/// </summary> /// </summary>
public class MapPolypoint : MapPath public partial class MapPolypoint : MapPath
{ {
public static readonly DependencyProperty FillRuleProperty = public static readonly DependencyProperty FillRuleProperty =
DependencyPropertyHelper.Register<MapPolygon, FillRule>(nameof(FillRule), FillRule.EvenOdd, DependencyPropertyHelper.Register<MapPolygon, FillRule>(nameof(FillRule), FillRule.EvenOdd,

View file

@ -25,15 +25,11 @@
</Content> </Content>
</ItemGroup> </ItemGroup>
<ItemGroup Condition="'$(TargetFramework)'=='net48'"> <ItemGroup>
<Reference Include="System.Net.Http" /> <ProjectReference Include="..\..\MapUiTools\WPF\MapUiTools.WPF.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.9" /> <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.9" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\MapUiTools\WPF\MapUiTools.WPF.csproj" />
</ItemGroup>
</Project> </Project>