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)
|
|
|
|
|
|
|
2014-11-19 21:11:14 +01:00
|
|
|
|
using System;
|
2014-07-01 18:57:44 +02:00
|
|
|
|
#if WINDOWS_RUNTIME
|
2012-11-22 21:42:29 +01:00
|
|
|
|
using Windows.UI.Xaml;
|
|
|
|
|
|
using Windows.UI.Xaml.Controls;
|
|
|
|
|
|
using Windows.UI.Xaml.Media;
|
2013-04-21 23:56:08 +02:00
|
|
|
|
using Windows.UI.Xaml.Media.Animation;
|
2012-11-22 21:42:29 +01:00
|
|
|
|
using Windows.UI.Xaml.Media.Imaging;
|
|
|
|
|
|
#else
|
|
|
|
|
|
using System.Windows;
|
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
|
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;
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
namespace MapControl
|
|
|
|
|
|
{
|
2013-01-03 15:33:46 +01:00
|
|
|
|
public partial class Tile
|
2012-11-22 21:42:29 +01:00
|
|
|
|
{
|
2014-11-19 21:11:14 +01:00
|
|
|
|
public void SetImage(ImageSource image, bool animateOpacity = true, bool isDownloading = true)
|
2012-11-22 21:42:29 +01:00
|
|
|
|
{
|
2013-01-17 18:48:38 +01:00
|
|
|
|
if (image != null && Image.Source == null)
|
2012-11-22 21:42:29 +01:00
|
|
|
|
{
|
2014-11-19 21:11:14 +01:00
|
|
|
|
if (animateOpacity && OpacityAnimationDuration > TimeSpan.Zero)
|
2012-11-22 21:42:29 +01:00
|
|
|
|
{
|
2014-11-19 21:11:14 +01:00
|
|
|
|
BitmapImage bitmap;
|
2012-11-22 21:42:29 +01:00
|
|
|
|
|
2014-11-19 21:11:14 +01:00
|
|
|
|
if (isDownloading && (bitmap = image as BitmapImage) != null)
|
2012-11-22 21:42:29 +01:00
|
|
|
|
{
|
2013-11-12 21:14:53 +01:00
|
|
|
|
bitmap.ImageOpened += BitmapImageOpened;
|
|
|
|
|
|
bitmap.ImageFailed += BitmapImageFailed;
|
2012-11-22 21:42:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2014-10-19 21:50:23 +02:00
|
|
|
|
Image.BeginAnimation(Image.OpacityProperty,
|
2014-11-19 21:11:14 +01:00
|
|
|
|
new DoubleAnimation { From = 0d, To = 1d, Duration = OpacityAnimationDuration });
|
2012-11-22 21:42:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Image.Opacity = 1d;
|
|
|
|
|
|
}
|
2014-11-19 21:11:14 +01:00
|
|
|
|
|
|
|
|
|
|
Image.Source = image;
|
2012-11-22 21:42:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-11-19 21:11:14 +01:00
|
|
|
|
Pending = false;
|
2012-11-22 21:42:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void BitmapImageOpened(object sender, RoutedEventArgs e)
|
|
|
|
|
|
{
|
2013-11-12 21:14:53 +01:00
|
|
|
|
var bitmap = (BitmapImage)sender;
|
|
|
|
|
|
|
|
|
|
|
|
bitmap.ImageOpened -= BitmapImageOpened;
|
|
|
|
|
|
bitmap.ImageFailed -= BitmapImageFailed;
|
|
|
|
|
|
|
2014-10-19 21:50:23 +02:00
|
|
|
|
Image.BeginAnimation(Image.OpacityProperty,
|
2014-11-19 21:11:14 +01:00
|
|
|
|
new DoubleAnimation { From = 0d, To = 1d, Duration = OpacityAnimationDuration });
|
2012-11-22 21:42:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void BitmapImageFailed(object sender, ExceptionRoutedEventArgs e)
|
|
|
|
|
|
{
|
2013-11-12 21:14:53 +01:00
|
|
|
|
var bitmap = (BitmapImage)sender;
|
|
|
|
|
|
|
|
|
|
|
|
bitmap.ImageOpened -= BitmapImageOpened;
|
|
|
|
|
|
bitmap.ImageFailed -= BitmapImageFailed;
|
|
|
|
|
|
|
2013-01-03 15:33:46 +01:00
|
|
|
|
Image.Source = null;
|
2012-11-22 21:42:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|