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

41 lines
1,016 B
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
2026-04-13 17:14:49 +02:00
namespace MapControl.MapsforgeTiles;
public partial class MapsforgeTileSource
2026-02-15 00:09:21 +01:00
{
2026-04-13 17:14:49 +02:00
public override async Task<IImage> LoadImageAsync(int zoomLevel, int column, int row)
2026-02-15 00:09:21 +01:00
{
2026-04-13 17:14:49 +02:00
Bitmap bitmap = null;
try
2026-02-15 00:09:21 +01:00
{
2026-04-13 17:14:49 +02:00
var pixels = RenderTile(zoomLevel, column, row);
2026-02-15 00:09:21 +01:00
2026-04-13 17:14:49 +02:00
if (pixels != null)
2026-02-15 00:09:21 +01:00
{
2026-04-13 17:14:49 +02:00
unsafe
2026-02-15 00:09:21 +01:00
{
2026-04-13 17:14:49 +02:00
fixed (int* ptr = pixels)
2026-02-19 17:20:09 +01:00
{
2026-04-13 17:14:49 +02:00
return new Bitmap(PixelFormat.Bgra8888, AlphaFormat.Opaque, (nint)ptr,
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-04-13 17:14:49 +02:00
catch (Exception ex)
{
Logger?.LogError(ex, "LoadImageAsync");
}
return bitmap;
2026-02-15 00:09:21 +01:00
}
}