mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-07 07:25:21 +00:00
Updated MapsforgeTiles
This commit is contained in:
parent
215ea1428f
commit
08bb0fe8de
15 changed files with 224 additions and 241 deletions
|
|
@ -1,30 +0,0 @@
|
|||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
49
MapsforgeTiles/WinUI/MapsforgeTileSource.cs
Normal file
49
MapsforgeTiles/WinUI/MapsforgeTileSource.cs
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
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<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 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -7,23 +7,8 @@
|
|||
<AssemblyTitle>XAML Map Control Mapsforge Library for WinUI</AssemblyTitle>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\Shared\*.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\MapControl\WinUI\MapControl.WinUI.csproj" />
|
||||
<ProjectReference Include="..\MapsforgeWrapper\MapsforgeWrapper.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="IKVM" Version="8.15.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<IkvmReference Include="..\target\mapsforge-tilerenderer-0.1.0-jar-with-dependencies.jar" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
|
||||
<Exec Command="cd ..
mvn package" />
|
||||
</Target>
|
||||
</Project>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue