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

View file

@ -1,34 +0,0 @@
using MapsforgeWrapper;
using System;
using System.Threading.Tasks;
using System.Windows.Media;
using System.Windows.Media.Imaging;
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<ImageSource> 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 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;
}
}
}

View file

@ -5,10 +5,37 @@
<DefineConstants>WPF</DefineConstants>
<RootNamespace>MapControl.MapsforgeTiles</RootNamespace>
<AssemblyTitle>XAML Map Control Mapsforge Library for WPF</AssemblyTitle>
<GeneratePackageOnBuild>$(GeneratePackage)</GeneratePackageOnBuild>
<PackageId>XAML.MapControl.MapsforgeTiles.WPF</PackageId>
<Title>$(AssemblyTitle)</Title>
<Description>Mapsforge support library for XAML Map Control</Description>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\MapControl\WPF\MapControl.WPF.csproj" />
<ProjectReference Include="..\MapsforgeWrapper\MapsforgeWrapper.csproj" />
<Compile Include="..\Shared\*.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\MapControl\WPF\MapControl.WPF.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-windows7.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>