diff --git a/MapsforgeTiles/Avalonia/MapsforgeTileSource.Avalonia.cs b/MapsforgeTiles/Avalonia/MapsforgeTileSource.Avalonia.cs new file mode 100644 index 00000000..096e1980 --- /dev/null +++ b/MapsforgeTiles/Avalonia/MapsforgeTileSource.Avalonia.cs @@ -0,0 +1,24 @@ +using Avalonia; +using Avalonia.Media.Imaging; +using Avalonia.Platform; +using System; + +namespace MapControl.MapsforgeTiles +{ + public partial class MapsforgeTileSource + { + private static Bitmap CreateImage(int[] pixels) + { + var size = (int)Math.Sqrt(pixels.Length); + + unsafe + { + fixed (int* ptr = pixels) + { + return new Bitmap(PixelFormat.Bgra8888, AlphaFormat.Opaque, (nint)ptr, + new PixelSize(size, size), new Vector(96d, 96d), size * 4); + } + } + } + } +} diff --git a/MapsforgeTiles/Avalonia/MapsforgeTileSource.cs b/MapsforgeTiles/Avalonia/MapsforgeTileSource.cs deleted file mode 100644 index d020bef3..00000000 --- a/MapsforgeTiles/Avalonia/MapsforgeTileSource.cs +++ /dev/null @@ -1,42 +0,0 @@ -using Avalonia; -using Avalonia.Media; -using Avalonia.Media.Imaging; -using Avalonia.Platform; -using MapsforgeWrapper; -using System; -using System.Threading.Tasks; - -namespace MapControl.MapsforgeTiles -{ - public class MapsforgeTileSource(string theme, int cacheCapacity = 200) : TileSource - { - private readonly TileRenderer renderer = new(theme, cacheCapacity); - - public static void Initialize(string mapFilePath, float dpiScale) - { - TileRenderer.Initialize(mapFilePath, dpiScale); - } - - public override Task LoadImageAsync(int zoomLevel, int column, int row) - { - var pixels = renderer.RenderTile(zoomLevel, column, row); - IImage image = pixels != null ? CreateImage(pixels) : null; - - return Task.FromResult(image); - } - - private static Bitmap CreateImage(int[] pixels) - { - var size = (int)Math.Sqrt(pixels.Length); - - unsafe - { - fixed (int* ptr = pixels) - { - return new Bitmap(PixelFormat.Bgra8888, AlphaFormat.Opaque, (nint)ptr, - new PixelSize(size, size), new Vector(96d, 96d), size * 4); - } - } - } - } -} diff --git a/MapsforgeTiles/Avalonia/MapsforgeTiles.Avalonia.csproj b/MapsforgeTiles/Avalonia/MapsforgeTiles.Avalonia.csproj index f5b97fda..d11dbd9c 100644 --- a/MapsforgeTiles/Avalonia/MapsforgeTiles.Avalonia.csproj +++ b/MapsforgeTiles/Avalonia/MapsforgeTiles.Avalonia.csproj @@ -4,11 +4,38 @@ AVALONIA MapControl.MapsforgeTiles XAML Map Control Mapsforge Library for Avalonia + $(GeneratePackage) + XAML.MapControl.MapsforgeTiles.Avalonia + $(AssemblyTitle) + Mapsforge support library for XAML Map Control true - - + + + + + + + + + + + + + + + + + true + lib\net10.0 + + + + + + diff --git a/MapsforgeTiles/MapsforgeWrapper/MapsforgeWrapper.csproj b/MapsforgeTiles/MapsforgeWrapper/MapsforgeWrapper.csproj deleted file mode 100644 index 023e441a..00000000 --- a/MapsforgeTiles/MapsforgeWrapper/MapsforgeWrapper.csproj +++ /dev/null @@ -1,23 +0,0 @@ - - - net10.0 - - - - - - - - - - - - - - - - - - - - diff --git a/MapsforgeTiles/WPF/MapsforgeTileSource.cs b/MapsforgeTiles/Shared/MapsforgeTileSource.cs similarity index 55% rename from MapsforgeTiles/WPF/MapsforgeTileSource.cs rename to MapsforgeTiles/Shared/MapsforgeTileSource.cs index f7edb2da..05d60ea0 100644 --- a/MapsforgeTiles/WPF/MapsforgeTileSource.cs +++ b/MapsforgeTiles/Shared/MapsforgeTileSource.cs @@ -1,12 +1,17 @@ -using MapsforgeWrapper; -using System; -using System.Threading.Tasks; +using System.Threading.Tasks; +#if WPF using System.Windows.Media; -using System.Windows.Media.Imaging; +#elif UWP +using Windows.UI.Xaml.Media; +#elif WINUI +using Microsoft.UI.Xaml.Media; +#elif AVALONIA +using ImageSource=Avalonia.Media.IImage; +#endif namespace MapControl.MapsforgeTiles { - public class MapsforgeTileSource(string theme, int cacheCapacity = 200) : TileSource + public partial class MapsforgeTileSource(string theme, int cacheCapacity = 200) : TileSource { private readonly TileRenderer renderer = new(theme, cacheCapacity); @@ -22,13 +27,5 @@ namespace MapControl.MapsforgeTiles return Task.FromResult(image); } - - private static BitmapSource CreateImage(int[] pixels) - { - var size = (int)Math.Sqrt(pixels.Length); - var image = BitmapSource.Create(size, size, 96d, 96d, PixelFormats.Bgra32, null, pixels, size * 4); - image.Freeze(); - return image; - } } } diff --git a/MapsforgeTiles/MapsforgeWrapper/TileRenderer.cs b/MapsforgeTiles/Shared/TileRenderer.cs similarity index 93% rename from MapsforgeTiles/MapsforgeWrapper/TileRenderer.cs rename to MapsforgeTiles/Shared/TileRenderer.cs index cb02ad93..ff1f7a4b 100644 --- a/MapsforgeTiles/MapsforgeWrapper/TileRenderer.cs +++ b/MapsforgeTiles/Shared/TileRenderer.cs @@ -1,5 +1,4 @@ -using org.mapsforge.core.model; -using org.mapsforge.map.awt.graphics; +using org.mapsforge.map.awt.graphics; using org.mapsforge.map.datastore; using org.mapsforge.map.layer.cache; using org.mapsforge.map.layer.renderer; @@ -10,7 +9,7 @@ using org.mapsforge.map.rendertheme.@internal; using org.mapsforge.map.rendertheme.rule; using System.IO; -namespace MapsforgeWrapper +namespace MapControl.MapsforgeTiles { public class TileRenderer { @@ -68,7 +67,7 @@ namespace MapsforgeWrapper } int[] imageBuffer = null; - var tile = new Tile(column, row, (byte)zoomLevel, displayModel.getTileSize()); + var tile = new org.mapsforge.core.model.Tile(column, row, (byte)zoomLevel, displayModel.getTileSize()); var job = new RendererJob(tile, dataStore, renderThemeFuture, displayModel, 1f, false, false); var bitmap = tileCache.get(job) ?? renderer.executeJob(job); diff --git a/MapsforgeTiles/UWP/MapsforgeTiles.UWP.csproj b/MapsforgeTiles/UWP/MapsforgeTiles.UWP.csproj index 7dc510af..ece7db48 100644 --- a/MapsforgeTiles/UWP/MapsforgeTiles.UWP.csproj +++ b/MapsforgeTiles/UWP/MapsforgeTiles.UWP.csproj @@ -6,16 +6,40 @@ UWP MapControl.MapsforgeTiles XAML Map Control Mapsforge Library for UWP + $(GeneratePackage) + XAML.MapControl.MapsforgeTiles.UWP + $(AssemblyTitle) + Mapsforge support library for XAML Map Control true en-US + - + + + + + + + + + + + + true + lib\net10.0-windows10.0.26100 + + + + + + diff --git a/MapsforgeTiles/WPF/MapsforgeTileSource.WPF.cs b/MapsforgeTiles/WPF/MapsforgeTileSource.WPF.cs new file mode 100644 index 00000000..0808903d --- /dev/null +++ b/MapsforgeTiles/WPF/MapsforgeTileSource.WPF.cs @@ -0,0 +1,17 @@ +using System; +using System.Windows.Media; +using System.Windows.Media.Imaging; + +namespace MapControl.MapsforgeTiles +{ + public partial class MapsforgeTileSource + { + private static BitmapSource CreateImage(int[] pixels) + { + var size = (int)Math.Sqrt(pixels.Length); + var image = BitmapSource.Create(size, size, 96d, 96d, PixelFormats.Bgra32, null, pixels, size * 4); + image.Freeze(); + return image; + } + } +} diff --git a/MapsforgeTiles/WPF/MapsforgeTiles.WPF.csproj b/MapsforgeTiles/WPF/MapsforgeTiles.WPF.csproj index c7f59782..869a22d4 100644 --- a/MapsforgeTiles/WPF/MapsforgeTiles.WPF.csproj +++ b/MapsforgeTiles/WPF/MapsforgeTiles.WPF.csproj @@ -5,10 +5,37 @@ WPF MapControl.MapsforgeTiles XAML Map Control Mapsforge Library for WPF + $(GeneratePackage) + XAML.MapControl.MapsforgeTiles.WPF + $(AssemblyTitle) + Mapsforge support library for XAML Map Control - - + + + + + + + + + + + + + + + + + true + lib\net10.0-windows7.0 + + + + + + diff --git a/MapsforgeTiles/WinUI/MapsforgeTileSource.WinUI.cs b/MapsforgeTiles/WinUI/MapsforgeTileSource.WinUI.cs new file mode 100644 index 00000000..0b02bfba --- /dev/null +++ b/MapsforgeTiles/WinUI/MapsforgeTileSource.WinUI.cs @@ -0,0 +1,30 @@ +using System; +using System.IO; +using System.Runtime.InteropServices.WindowsRuntime; +#if UWP +using Windows.UI.Xaml.Media.Imaging; +#elif WINUI +using Microsoft.UI.Xaml.Media.Imaging; +#endif + +namespace MapControl.MapsforgeTiles +{ + public partial class MapsforgeTileSource + { + private static WriteableBitmap CreateImage(int[] pixels) + { + var size = (int)Math.Sqrt(pixels.Length); + var bitmap = new WriteableBitmap(size, size); + + using var stream = bitmap.PixelBuffer.AsStream(); + using var writer = new BinaryWriter(stream); + + foreach (var pixel in pixels) + { + writer.Write(pixel); + } + + return bitmap; + } + } +} diff --git a/MapsforgeTiles/WinUI/MapsforgeTileSource.cs b/MapsforgeTiles/WinUI/MapsforgeTileSource.cs deleted file mode 100644 index 6e48a447..00000000 --- a/MapsforgeTiles/WinUI/MapsforgeTileSource.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using System.IO; -using System.Runtime.InteropServices.WindowsRuntime; -using System.Threading.Tasks; -using MapsforgeWrapper; -#if UWP -using Windows.UI.Xaml.Media; -using Windows.UI.Xaml.Media.Imaging; -#elif WINUI -using Microsoft.UI.Xaml.Media; -using Microsoft.UI.Xaml.Media.Imaging; -#endif - -namespace MapControl.MapsforgeTiles -{ - public class MapsforgeTileSource(string theme, int cacheCapacity = 200) : TileSource - { - private readonly TileRenderer renderer = new(theme, cacheCapacity); - - public static void Initialize(string mapFilePath, float dpiScale) - { - TileRenderer.Initialize(mapFilePath, dpiScale); - } - - public override Task LoadImageAsync(int zoomLevel, int column, int row) - { - var pixels = renderer.RenderTile(zoomLevel, column, row); - ImageSource image = pixels != null ? CreateImage(pixels) : null; - - return Task.FromResult(image); - } - - private static WriteableBitmap CreateImage(int[] pixels) - { - var size = (int)Math.Sqrt(pixels.Length); - var bitmap = new WriteableBitmap(size, size); - - using var stream = bitmap.PixelBuffer.AsStream(); - using var writer = new BinaryWriter(stream); - - foreach (var pixel in pixels) - { - writer.Write(pixel); - } - - return bitmap; - } - } -} diff --git a/MapsforgeTiles/WinUI/MapsforgeTiles.WinUI.csproj b/MapsforgeTiles/WinUI/MapsforgeTiles.WinUI.csproj index 85b304e6..6f74416d 100644 --- a/MapsforgeTiles/WinUI/MapsforgeTiles.WinUI.csproj +++ b/MapsforgeTiles/WinUI/MapsforgeTiles.WinUI.csproj @@ -5,10 +5,37 @@ WINUI MapControl.MapsforgeTiles XAML Map Control Mapsforge Library for WinUI + $(GeneratePackage) + XAML.MapControl.MapsforgeTiles.WinUI + $(AssemblyTitle) + Mapsforge support library for XAML Map Control - - + + + + + + + + + + + + + + + + + true + lib\net10.0-windows10.0.17763 + + + + + + diff --git a/MapsforgeTiles/MapsforgeWrapper/pom.xml b/MapsforgeTiles/pom.xml similarity index 100% rename from MapsforgeTiles/MapsforgeWrapper/pom.xml rename to MapsforgeTiles/pom.xml