2012-11-22 21:42:29 +01:00
|
|
|
|
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
|
2013-05-07 18:12:25 +02:00
|
|
|
|
// Copyright © Clemens Fischer 2012-2013
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
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-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
|
|
|
|
|
|
{
|
2013-05-07 18:12:25 +02:00
|
|
|
|
Brush.BeginAnimation(ImageBrush.OpacityProperty, new DoubleAnimation(1d, AnimationDuration));
|
2012-11-22 21:42:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Brush.Opacity = 1d;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-01-03 15:33:46 +01:00
|
|
|
|
Brush.ImageSource = 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;
|
|
|
|
|
|
|
2013-05-07 18:12:25 +02:00
|
|
|
|
Brush.BeginAnimation(ImageBrush.OpacityProperty, new DoubleAnimation(1d, AnimationDuration));
|
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;
|
|
|
|
|
|
|
2013-01-03 15:33:46 +01:00
|
|
|
|
Brush.ImageSource = null;
|
2012-11-22 21:42:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|