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

42 lines
1.1 KiB
C#
Raw 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-23 16:47:53 +01:00
var pixels = RenderTile(zoomLevel, column, row);
2026-02-19 17:20:09 +01:00
if (pixels != null)
2026-02-15 00:09:21 +01:00
{
2026-02-19 17:20:09 +01:00
unsafe
{
fixed (int* ptr = pixels)
{
return new Bitmap(PixelFormat.Bgra8888, AlphaFormat.Opaque, (nint)ptr,
2026-02-24 10:19:28 +01:00
new PixelSize(TileSize, TileSize), new Vector(96d, 96d), TileSize * 4);
2026-02-19 17:20:09 +01:00
}
}
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
}
}
}