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

33 lines
812 B
C#
Raw Normal View History

2026-02-19 17:20:09 +01:00
using Microsoft.Extensions.Logging;
using System;
using System.Threading.Tasks;
2026-02-15 00:09:21 +01:00
using System.Windows.Media;
using System.Windows.Media.Imaging;
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<ImageSource> LoadImageAsync(int zoomLevel, int column, int row)
2026-02-15 00:09:21 +01:00
{
2026-04-13 17:14:49 +02:00
BitmapSource bitmap = null;
2026-02-19 17:20:09 +01:00
2026-04-13 17:14:49 +02:00
try
{
var pixels = RenderTile(zoomLevel, column, row);
2026-02-19 17:20:09 +01:00
2026-04-13 17:14:49 +02:00
if (pixels != null)
2026-02-19 17:20:09 +01:00
{
2026-04-13 17:14:49 +02:00
bitmap = BitmapSource.Create(TileSize, TileSize, 96d, 96d, PixelFormats.Bgra32, null, pixels, TileSize * 4);
bitmap.Freeze();
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
}
}