XAML-Map-Control/MapControl/ImageTileSource.WPF.cs

43 lines
1.3 KiB
C#
Raw Normal View History

// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// © 2017 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace MapControl
{
/// <summary>
/// Provides the image of a map tile. ImageTileSource bypasses image downloading
/// and optional caching in TileImageLoader. By overriding the LoadImage method,
/// an application can provide tile images from an arbitrary source.
/// If the IsAsync property is true, LoadImage will be called from a separate,
/// non-UI thread and must therefore return a frozen ImageSource.
/// </summary>
public class ImageTileSource : TileSource
{
public bool IsAsync { get; set; }
public virtual ImageSource LoadImage(int x, int y, int zoomLevel)
{
ImageSource image = null;
var uri = GetUri(x, y, zoomLevel);
if (uri != null)
{
if (IsAsync)
{
image = BitmapSourceHelper.FromUri(uri);
}
else
{
2016-02-23 20:07:30 +01:00
image = new BitmapImage(uri);
}
}
return image;
}
}
}