2017-06-25 23:05:48 +02:00
|
|
|
|
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
|
|
|
|
|
// © 2017 Clemens Fischer
|
2013-11-12 21:14:53 +01:00
|
|
|
|
// Licensed under the Microsoft Public License (Ms-PL)
|
|
|
|
|
|
|
2014-07-01 18:57:44 +02:00
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
|
using System.Windows.Media.Imaging;
|
|
|
|
|
|
|
2013-11-12 21:14:53 +01:00
|
|
|
|
namespace MapControl
|
|
|
|
|
|
{
|
2014-07-01 18:57:44 +02:00
|
|
|
|
/// <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
|
2013-11-12 21:14:53 +01:00
|
|
|
|
{
|
2014-07-01 18:57:44 +02:00
|
|
|
|
public bool IsAsync { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public virtual ImageSource LoadImage(int x, int y, int zoomLevel)
|
2013-11-12 21:14:53 +01:00
|
|
|
|
{
|
2014-07-01 18:57:44 +02:00
|
|
|
|
ImageSource image = null;
|
|
|
|
|
|
|
|
|
|
|
|
var uri = GetUri(x, y, zoomLevel);
|
|
|
|
|
|
|
|
|
|
|
|
if (uri != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (IsAsync)
|
|
|
|
|
|
{
|
2017-06-25 23:05:48 +02:00
|
|
|
|
image = BitmapSourceHelper.FromUri(uri);
|
2014-07-01 18:57:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2016-02-23 20:07:30 +01:00
|
|
|
|
image = new BitmapImage(uri);
|
2014-07-01 18:57:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return image;
|
2013-11-12 21:14:53 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|