2012-11-22 21:42:29 +01:00
|
|
|
|
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
|
2013-01-17 18:48:38 +01:00
|
|
|
|
// Copyright © 2013 Clemens Fischer
|
2012-11-22 21:42:29 +01:00
|
|
|
|
// Licensed under the Microsoft Public License (Ms-PL)
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
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;
|
2013-01-03 15:33:46 +01:00
|
|
|
|
using System.Windows.Threading;
|
2012-11-22 21:42:29 +01:00
|
|
|
|
|
|
|
|
|
|
namespace MapControl
|
|
|
|
|
|
{
|
2013-01-03 15:33:46 +01:00
|
|
|
|
public partial class Tile
|
2012-11-22 21:42:29 +01:00
|
|
|
|
{
|
|
|
|
|
|
public readonly ImageBrush Brush = new ImageBrush { Opacity = 0d };
|
|
|
|
|
|
|
|
|
|
|
|
public ImageSource ImageSource
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return Brush.ImageSource; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-01-03 15:33:46 +01:00
|
|
|
|
public void SetImageSource(ImageSource image, bool animateOpacity)
|
2012-11-22 21:42:29 +01:00
|
|
|
|
{
|
2013-01-17 18:48:38 +01:00
|
|
|
|
if (image != null && Brush.ImageSource == null)
|
2012-11-22 21:42:29 +01:00
|
|
|
|
{
|
|
|
|
|
|
if (animateOpacity)
|
|
|
|
|
|
{
|
2013-01-03 15:33:46 +01:00
|
|
|
|
var bitmapImage = image as BitmapImage;
|
2012-11-22 21:42:29 +01:00
|
|
|
|
|
2013-01-03 15:33:46 +01:00
|
|
|
|
if (bitmapImage != null && bitmapImage.IsDownloading)
|
2012-11-22 21:42:29 +01:00
|
|
|
|
{
|
2013-01-03 15:33:46 +01:00
|
|
|
|
bitmapImage.DownloadCompleted += BitmapDownloadCompleted;
|
|
|
|
|
|
bitmapImage.DownloadFailed += BitmapDownloadFailed;
|
2012-11-22 21:42:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2013-04-21 23:56:08 +02:00
|
|
|
|
BeginOpacityAnimation();
|
2012-11-22 21:42:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Brush.Opacity = 1d;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-01-03 15:33:46 +01:00
|
|
|
|
Brush.ImageSource = image;
|
2013-01-17 18:48:38 +01:00
|
|
|
|
HasImage = true;
|
2012-11-22 21:42:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void BitmapDownloadCompleted(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
((BitmapImage)sender).DownloadCompleted -= BitmapDownloadCompleted;
|
|
|
|
|
|
((BitmapImage)sender).DownloadFailed -= BitmapDownloadFailed;
|
2013-04-21 23:56:08 +02:00
|
|
|
|
BeginOpacityAnimation();
|
2012-11-22 21:42:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void BitmapDownloadFailed(object sender, ExceptionEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
((BitmapImage)sender).DownloadCompleted -= BitmapDownloadCompleted;
|
|
|
|
|
|
((BitmapImage)sender).DownloadFailed -= BitmapDownloadFailed;
|
2013-01-03 15:33:46 +01:00
|
|
|
|
Brush.ImageSource = null;
|
2012-11-22 21:42:29 +01:00
|
|
|
|
}
|
2013-04-21 23:56:08 +02:00
|
|
|
|
|
|
|
|
|
|
private void BeginOpacityAnimation()
|
|
|
|
|
|
{
|
|
|
|
|
|
Brush.BeginAnimation(ImageBrush.OpacityProperty,
|
|
|
|
|
|
new DoubleAnimation
|
|
|
|
|
|
{
|
|
|
|
|
|
To = 1d,
|
|
|
|
|
|
Duration = AnimationDuration,
|
|
|
|
|
|
FillBehavior = FillBehavior.HoldEnd
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2012-11-22 21:42:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|