2012-05-04 12:52:20 +02:00
|
|
|
|
// WPF MapControl - http://wpfmapcontrol.codeplex.com/
|
|
|
|
|
|
// Copyright © 2012 Clemens Fischer
|
|
|
|
|
|
// Licensed under the Microsoft Public License (Ms-PL)
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
2012-04-25 22:02:53 +02:00
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
|
using System.Windows.Media.Animation;
|
2012-07-20 21:57:29 +02:00
|
|
|
|
using System.Windows.Media.Imaging;
|
2012-04-25 22:02:53 +02:00
|
|
|
|
|
|
|
|
|
|
namespace MapControl
|
|
|
|
|
|
{
|
|
|
|
|
|
internal class Tile
|
|
|
|
|
|
{
|
|
|
|
|
|
private static readonly DoubleAnimation opacityAnimation = new DoubleAnimation(0d, 1d, TimeSpan.FromSeconds(0.5), FillBehavior.Stop);
|
|
|
|
|
|
|
|
|
|
|
|
public readonly int ZoomLevel;
|
|
|
|
|
|
public readonly int X;
|
|
|
|
|
|
public readonly int Y;
|
|
|
|
|
|
public readonly ImageBrush Brush = new ImageBrush();
|
|
|
|
|
|
|
2012-06-18 20:12:35 +02:00
|
|
|
|
public Tile(int zoomLevel, int x, int y)
|
2012-04-25 22:02:53 +02:00
|
|
|
|
{
|
|
|
|
|
|
ZoomLevel = zoomLevel;
|
|
|
|
|
|
X = x;
|
|
|
|
|
|
Y = y;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2012-06-18 20:12:35 +02:00
|
|
|
|
public Uri Uri { get; set; }
|
2012-04-25 22:02:53 +02:00
|
|
|
|
|
|
|
|
|
|
public int XIndex
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
int numTiles = 1 << ZoomLevel;
|
|
|
|
|
|
return ((X % numTiles) + numTiles) % numTiles;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2012-11-06 19:49:29 +01:00
|
|
|
|
public ImageSource Source
|
2012-04-25 22:02:53 +02:00
|
|
|
|
{
|
|
|
|
|
|
get { return Brush.ImageSource; }
|
2012-11-06 19:49:29 +01:00
|
|
|
|
set { Brush.ImageSource = value; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void SetSource(ImageSource source)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Source == null)
|
2012-04-25 22:02:53 +02:00
|
|
|
|
{
|
2012-11-06 19:49:29 +01:00
|
|
|
|
BitmapImage bitmap = source as BitmapImage;
|
2012-07-20 21:57:29 +02:00
|
|
|
|
|
2012-11-06 19:49:29 +01:00
|
|
|
|
if (bitmap != null && bitmap.IsDownloading)
|
|
|
|
|
|
{
|
|
|
|
|
|
bitmap.DownloadCompleted += BitmapDownloadCompleted;
|
|
|
|
|
|
bitmap.DownloadFailed += BitmapDownloadFailed;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Brush.BeginAnimation(ImageBrush.OpacityProperty, opacityAnimation);
|
2012-04-25 22:02:53 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2012-11-06 19:49:29 +01:00
|
|
|
|
|
|
|
|
|
|
Source = source;
|
2012-04-25 22:02:53 +02:00
|
|
|
|
}
|
2012-07-20 21:57:29 +02:00
|
|
|
|
|
|
|
|
|
|
private void BitmapDownloadCompleted(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
((BitmapImage)sender).DownloadCompleted -= BitmapDownloadCompleted;
|
|
|
|
|
|
((BitmapImage)sender).DownloadFailed -= BitmapDownloadFailed;
|
|
|
|
|
|
Brush.BeginAnimation(ImageBrush.OpacityProperty, opacityAnimation);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void BitmapDownloadFailed(object sender, ExceptionEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
((BitmapImage)sender).DownloadCompleted -= BitmapDownloadCompleted;
|
|
|
|
|
|
((BitmapImage)sender).DownloadFailed -= BitmapDownloadFailed;
|
2012-11-06 19:49:29 +01:00
|
|
|
|
Source = null;
|
2012-07-20 21:57:29 +02:00
|
|
|
|
}
|
2012-04-25 22:02:53 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|