2012-11-22 21:42:29 +01:00
|
|
|
|
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
|
2014-01-10 20:11:39 +01:00
|
|
|
|
// Copyright © 2014 Clemens Fischer
|
2012-11-22 21:42:29 +01:00
|
|
|
|
// Licensed under the Microsoft Public License (Ms-PL)
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
2014-07-01 18:57:44 +02:00
|
|
|
|
using System.Windows.Controls;
|
2012-11-22 21:42:29 +01:00
|
|
|
|
using System.Windows.Media;
|
2013-04-21 23:56:08 +02:00
|
|
|
|
using System.Windows.Media.Animation;
|
2012-11-22 21:42:29 +01:00
|
|
|
|
using System.Windows.Media.Imaging;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MapControl
|
|
|
|
|
|
{
|
2013-01-03 15:33:46 +01:00
|
|
|
|
public partial class Tile
|
2012-11-22 21:42:29 +01:00
|
|
|
|
{
|
2013-01-03 15:33:46 +01:00
|
|
|
|
public void SetImageSource(ImageSource image, bool animateOpacity)
|
2012-11-22 21:42:29 +01:00
|
|
|
|
{
|
2014-07-01 18:57:44 +02:00
|
|
|
|
if (image != null && Image.Source == null)
|
2012-11-22 21:42:29 +01:00
|
|
|
|
{
|
|
|
|
|
|
if (animateOpacity)
|
|
|
|
|
|
{
|
2013-11-12 21:14:53 +01:00
|
|
|
|
var bitmap = image as BitmapSource;
|
2012-11-22 21:42:29 +01:00
|
|
|
|
|
2013-11-12 21:14:53 +01:00
|
|
|
|
if (bitmap != null && !bitmap.IsFrozen && bitmap.IsDownloading)
|
2012-11-22 21:42:29 +01:00
|
|
|
|
{
|
2013-11-12 21:14:53 +01:00
|
|
|
|
bitmap.DownloadCompleted += BitmapDownloadCompleted;
|
|
|
|
|
|
bitmap.DownloadFailed += BitmapDownloadFailed;
|
2012-11-22 21:42:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2014-10-19 21:50:23 +02:00
|
|
|
|
Image.BeginAnimation(Image.OpacityProperty,
|
|
|
|
|
|
new DoubleAnimation(1d, Settings.TileAnimationDuration));
|
2012-11-22 21:42:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2014-07-01 18:57:44 +02:00
|
|
|
|
Image.Opacity = 1d;
|
2012-11-22 21:42:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-07-01 18:57:44 +02:00
|
|
|
|
Image.Source = image;
|
2013-11-12 21:14:53 +01:00
|
|
|
|
HasImageSource = true;
|
2012-11-22 21:42:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void BitmapDownloadCompleted(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2013-11-12 21:14:53 +01:00
|
|
|
|
var bitmap = (BitmapSource)sender;
|
|
|
|
|
|
|
|
|
|
|
|
bitmap.DownloadCompleted -= BitmapDownloadCompleted;
|
|
|
|
|
|
bitmap.DownloadFailed -= BitmapDownloadFailed;
|
|
|
|
|
|
|
2014-10-19 21:50:23 +02:00
|
|
|
|
Image.BeginAnimation(Image.OpacityProperty,
|
|
|
|
|
|
new DoubleAnimation(1d, Settings.TileAnimationDuration));
|
2012-11-22 21:42:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void BitmapDownloadFailed(object sender, ExceptionEventArgs e)
|
|
|
|
|
|
{
|
2013-11-12 21:14:53 +01:00
|
|
|
|
var bitmap = (BitmapSource)sender;
|
|
|
|
|
|
|
|
|
|
|
|
bitmap.DownloadCompleted -= BitmapDownloadCompleted;
|
|
|
|
|
|
bitmap.DownloadFailed -= BitmapDownloadFailed;
|
|
|
|
|
|
|
2014-07-01 18:57:44 +02:00
|
|
|
|
Image.Source = null;
|
2012-11-22 21:42:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|