mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-09 00:14:51 +00:00
Updated MapsforgeTiles
This commit is contained in:
parent
215ea1428f
commit
08bb0fe8de
15 changed files with 224 additions and 241 deletions
34
MapsforgeTiles/WPF/MapsforgeTileSource.cs
Normal file
34
MapsforgeTiles/WPF/MapsforgeTileSource.cs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue