mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
- Added ImageFileCache and FileDbCache for WinRT - Improved TileImageLoader - Removed TileContainer, TileLayer can be added as MapBase child - Removed attached property MapPanel.ViewportPosition
67 lines
2 KiB
C#
67 lines
2 KiB
C#
// XAML Map Control - http://xamlmapcontrol.codeplex.com/
|
|
// Copyright © 2014 Clemens Fischer
|
|
// Licensed under the Microsoft Public License (Ms-PL)
|
|
|
|
using System;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Animation;
|
|
using System.Windows.Media.Imaging;
|
|
|
|
namespace MapControl
|
|
{
|
|
public partial class Tile
|
|
{
|
|
public void SetImage(ImageSource image, bool animateOpacity = true)
|
|
{
|
|
if (image != null && Image.Source == null)
|
|
{
|
|
if (animateOpacity && OpacityAnimationDuration > TimeSpan.Zero)
|
|
{
|
|
var bitmap = image as BitmapSource;
|
|
|
|
if (bitmap != null && !bitmap.IsFrozen && bitmap.IsDownloading)
|
|
{
|
|
bitmap.DownloadCompleted += BitmapDownloadCompleted;
|
|
bitmap.DownloadFailed += BitmapDownloadFailed;
|
|
}
|
|
else
|
|
{
|
|
Image.BeginAnimation(Image.OpacityProperty,
|
|
new DoubleAnimation(0d, 1d, OpacityAnimationDuration));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Image.Opacity = 1d;
|
|
}
|
|
|
|
Image.Source = image;
|
|
}
|
|
|
|
Pending = false;
|
|
}
|
|
|
|
private void BitmapDownloadCompleted(object sender, EventArgs e)
|
|
{
|
|
var bitmap = (BitmapSource)sender;
|
|
|
|
bitmap.DownloadCompleted -= BitmapDownloadCompleted;
|
|
bitmap.DownloadFailed -= BitmapDownloadFailed;
|
|
|
|
Image.BeginAnimation(Image.OpacityProperty,
|
|
new DoubleAnimation(0d, 1d, OpacityAnimationDuration));
|
|
}
|
|
|
|
private void BitmapDownloadFailed(object sender, ExceptionEventArgs e)
|
|
{
|
|
var bitmap = (BitmapSource)sender;
|
|
|
|
bitmap.DownloadCompleted -= BitmapDownloadCompleted;
|
|
bitmap.DownloadFailed -= BitmapDownloadFailed;
|
|
|
|
Image.Source = null;
|
|
}
|
|
}
|
|
}
|