XAML-Map-Control/MapsforgeTiles/Avalonia/MapsforgeTileSource.Avalonia.cs

44 lines
1.2 KiB
C#
Raw Permalink Normal View History

2026-02-15 00:09:21 +01:00
using Avalonia;
2026-02-19 17:20:09 +01:00
using Avalonia.Media;
2026-02-15 00:09:21 +01:00
using Avalonia.Media.Imaging;
using Avalonia.Platform;
2026-02-19 17:20:09 +01:00
using Microsoft.Extensions.Logging;
2026-02-15 00:09:21 +01:00
using System;
2026-02-19 17:20:09 +01:00
using System.Threading.Tasks;
2026-02-15 00:09:21 +01:00
namespace MapControl.MapsforgeTiles
{
public partial class MapsforgeTileSource
{
2026-02-19 17:20:09 +01:00
public override async Task<IImage> LoadImageAsync(int zoomLevel, int column, int row)
2026-02-15 00:09:21 +01:00
{
2026-02-19 17:20:09 +01:00
Bitmap bitmap = null;
2026-02-15 00:09:21 +01:00
2026-02-19 17:20:09 +01:00
try
2026-02-15 00:09:21 +01:00
{
2026-02-19 17:20:09 +01:00
var pixels = tileRenderer.RenderTile(zoomLevel, column, row);
if (pixels != null)
2026-02-15 00:09:21 +01:00
{
2026-02-19 17:20:09 +01:00
var size = TileRenderer.TileSize;
unsafe
{
fixed (int* ptr = pixels)
{
return new Bitmap(PixelFormat.Bgra8888, AlphaFormat.Opaque, (nint)ptr,
new PixelSize(size, size), new Vector(96d, 96d), size * 4);
}
}
2026-02-15 00:09:21 +01:00
}
}
2026-02-19 17:20:09 +01:00
catch (Exception ex)
{
Logger?.LogError(ex, "LoadImageAsync");
}
return bitmap;
2026-02-15 00:09:21 +01:00
}
}
}