Updated MapsforgeTiles projects

This commit is contained in:
ClemensFischer 2026-02-15 00:09:21 +01:00
parent 105e812afa
commit a9f0ccc78b
13 changed files with 196 additions and 138 deletions

View file

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

View file

@ -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<IImage> 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);
}
}
}
}
}

View file

@ -4,11 +4,38 @@
<DefineConstants>AVALONIA</DefineConstants>
<RootNamespace>MapControl.MapsforgeTiles</RootNamespace>
<AssemblyTitle>XAML Map Control Mapsforge Library for Avalonia</AssemblyTitle>
<GeneratePackageOnBuild>$(GeneratePackage)</GeneratePackageOnBuild>
<PackageId>XAML.MapControl.MapsforgeTiles.Avalonia</PackageId>
<Title>$(AssemblyTitle)</Title>
<Description>Mapsforge support library for XAML Map Control</Description>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\MapControl\Avalonia\MapControl.Avalonia.csproj" />
<ProjectReference Include="..\MapsforgeWrapper\MapsforgeWrapper.csproj" />
<Compile Include="..\Shared\*.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\MapControl\Avalonia\MapControl.Avalonia.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="IKVM" Version="8.15.0" />
</ItemGroup>
<ItemGroup>
<IkvmReference Include="..\target\mapsforge-0.27.0-jar-with-dependencies.jar" />
</ItemGroup>
<ItemGroup>
<None Include="$(OutDir)\mapsforge.dll">
<Pack>true</Pack>
<PackagePath>lib\net10.0</PackagePath>
</None>
</ItemGroup>
<Target Name="PreBuild" BeforeTargets="PreBuildEvent"
Outputs="..\target\mapsforge-0.27.0-jar-with-dependencies.jar">
<Exec Command="mvn package" WorkingDirectory=".."/>
</Target>
</Project>