mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
WPF specific file names
This commit is contained in:
parent
172a388841
commit
21d7938d33
|
|
@ -36,7 +36,7 @@ namespace MapControl
|
||||||
if (equivalentTile != null)
|
if (equivalentTile != null)
|
||||||
{
|
{
|
||||||
tile.IsPending = false;
|
tile.IsPending = false;
|
||||||
tile.Image.Source = equivalentTile.Image.Source; // no opacity animation
|
tile.Image.Source = equivalentTile.Image.Source; // no Opacity animation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
90
MapControl/WPF/DrawingTile.WPF.cs
Normal file
90
MapControl/WPF/DrawingTile.WPF.cs
Normal file
|
|
@ -0,0 +1,90 @@
|
||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Media.Animation;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
|
||||||
|
namespace MapControl
|
||||||
|
{
|
||||||
|
public class DrawingTile : Tile
|
||||||
|
{
|
||||||
|
private readonly ImageDrawing imageDrawing = new ImageDrawing();
|
||||||
|
|
||||||
|
public DrawingTile(int zoomLevel, int x, int y, int columnCount)
|
||||||
|
: base(zoomLevel, x, y, columnCount)
|
||||||
|
{
|
||||||
|
Drawing.Children.Add(imageDrawing);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DrawingGroup Drawing { get; } = new DrawingGroup();
|
||||||
|
|
||||||
|
public ImageSource ImageSource
|
||||||
|
{
|
||||||
|
get => imageDrawing.ImageSource;
|
||||||
|
set => imageDrawing.ImageSource = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetRect(int xMin, int yMin, int tileWidth, int tileHeight)
|
||||||
|
{
|
||||||
|
imageDrawing.Rect = new Rect(tileWidth * (X - xMin), tileHeight * (Y - yMin), tileWidth, tileHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task LoadImageAsync(Func<Task<ImageSource>> loadImageFunc)
|
||||||
|
{
|
||||||
|
var image = await loadImageFunc().ConfigureAwait(false);
|
||||||
|
|
||||||
|
void SetImageSource()
|
||||||
|
{
|
||||||
|
imageDrawing.ImageSource = image;
|
||||||
|
|
||||||
|
if (image != null && MapBase.ImageFadeDuration > TimeSpan.Zero)
|
||||||
|
{
|
||||||
|
if (image is BitmapSource bitmap && !bitmap.IsFrozen && bitmap.IsDownloading)
|
||||||
|
{
|
||||||
|
bitmap.DownloadCompleted += BitmapDownloadCompleted;
|
||||||
|
bitmap.DownloadFailed += BitmapDownloadFailed;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
BeginFadeInAnimation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await Drawing.Dispatcher.InvokeAsync(SetImageSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BeginFadeInAnimation()
|
||||||
|
{
|
||||||
|
var fadeInAnimation = new DoubleAnimation
|
||||||
|
{
|
||||||
|
From = 0d,
|
||||||
|
Duration = MapBase.ImageFadeDuration,
|
||||||
|
FillBehavior = FillBehavior.Stop
|
||||||
|
};
|
||||||
|
|
||||||
|
Drawing.BeginAnimation(DrawingGroup.OpacityProperty, fadeInAnimation);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BitmapDownloadCompleted(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var bitmap = (BitmapSource)sender;
|
||||||
|
|
||||||
|
bitmap.DownloadCompleted -= BitmapDownloadCompleted;
|
||||||
|
bitmap.DownloadFailed -= BitmapDownloadFailed;
|
||||||
|
|
||||||
|
BeginFadeInAnimation();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BitmapDownloadFailed(object sender, ExceptionEventArgs e)
|
||||||
|
{
|
||||||
|
var bitmap = (BitmapSource)sender;
|
||||||
|
|
||||||
|
bitmap.DownloadCompleted -= BitmapDownloadCompleted;
|
||||||
|
bitmap.DownloadFailed -= BitmapDownloadFailed;
|
||||||
|
|
||||||
|
imageDrawing.ImageSource = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,68 +1,18 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Media.Animation;
|
|
||||||
|
|
||||||
namespace MapControl
|
namespace MapControl
|
||||||
{
|
{
|
||||||
public class ImageDrawingTile : Tile
|
|
||||||
{
|
|
||||||
private readonly ImageDrawing imageDrawing = new ImageDrawing();
|
|
||||||
|
|
||||||
public ImageDrawingTile(int zoomLevel, int x, int y, int columnCount)
|
|
||||||
: base(zoomLevel, x, y, columnCount)
|
|
||||||
{
|
|
||||||
Drawing.Children.Add(imageDrawing);
|
|
||||||
}
|
|
||||||
|
|
||||||
public DrawingGroup Drawing { get; } = new DrawingGroup();
|
|
||||||
|
|
||||||
public ImageSource ImageSource
|
|
||||||
{
|
|
||||||
get => imageDrawing.ImageSource;
|
|
||||||
set => imageDrawing.ImageSource = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetRect(int xMin, int yMin, int tileWidth, int tileHeight)
|
|
||||||
{
|
|
||||||
imageDrawing.Rect = new Rect(tileWidth * (X - xMin), tileHeight * (Y - yMin), tileWidth, tileHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task LoadImageAsync(Func<Task<ImageSource>> loadImageFunc)
|
|
||||||
{
|
|
||||||
var image = await loadImageFunc().ConfigureAwait(false);
|
|
||||||
|
|
||||||
void SetImageSource()
|
|
||||||
{
|
|
||||||
imageDrawing.ImageSource = image;
|
|
||||||
|
|
||||||
if (image != null && MapBase.ImageFadeDuration > TimeSpan.Zero)
|
|
||||||
{
|
|
||||||
var fadeInAnimation = new DoubleAnimation
|
|
||||||
{
|
|
||||||
From = 0d,
|
|
||||||
Duration = MapBase.ImageFadeDuration,
|
|
||||||
FillBehavior = FillBehavior.Stop
|
|
||||||
};
|
|
||||||
|
|
||||||
Drawing.BeginAnimation(DrawingGroup.OpacityProperty, fadeInAnimation);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await Drawing.Dispatcher.InvokeAsync(SetImageSource);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class DrawingTileMatrixLayer(WmtsTileMatrix wmtsTileMatrix, int zoomLevel) : UIElement
|
public class DrawingTileMatrixLayer(WmtsTileMatrix wmtsTileMatrix, int zoomLevel) : UIElement
|
||||||
{
|
{
|
||||||
public WmtsTileMatrix WmtsTileMatrix => wmtsTileMatrix;
|
public WmtsTileMatrix WmtsTileMatrix => wmtsTileMatrix;
|
||||||
|
|
||||||
public TileMatrix TileMatrix { get; private set; } = new TileMatrix(zoomLevel, 1, 1, 0, 0);
|
public TileMatrix TileMatrix { get; private set; } = new TileMatrix(zoomLevel, 1, 1, 0, 0);
|
||||||
|
|
||||||
public IEnumerable<ImageDrawingTile> Tiles { get; private set; } = [];
|
public IEnumerable<DrawingTile> Tiles { get; private set; } = [];
|
||||||
|
|
||||||
public DrawingGroup Drawing { get; } = new DrawingGroup { Transform = new MatrixTransform() };
|
public DrawingGroup Drawing { get; } = new DrawingGroup { Transform = new MatrixTransform() };
|
||||||
|
|
||||||
|
|
@ -125,7 +75,7 @@ namespace MapControl
|
||||||
private void CreateTiles()
|
private void CreateTiles()
|
||||||
{
|
{
|
||||||
var tileCount = TileMatrix.Width * TileMatrix.Height;
|
var tileCount = TileMatrix.Width * TileMatrix.Height;
|
||||||
var tiles = new List<ImageDrawingTile>(tileCount);
|
var tiles = new List<DrawingTile>(tileCount);
|
||||||
var drawings = new DrawingCollection(tileCount);
|
var drawings = new DrawingCollection(tileCount);
|
||||||
|
|
||||||
for (var y = TileMatrix.YMin; y <= TileMatrix.YMax; y++)
|
for (var y = TileMatrix.YMin; y <= TileMatrix.YMax; y++)
|
||||||
|
|
@ -136,14 +86,14 @@ namespace MapControl
|
||||||
|
|
||||||
if (tile == null)
|
if (tile == null)
|
||||||
{
|
{
|
||||||
tile = new ImageDrawingTile(TileMatrix.ZoomLevel, x, y, WmtsTileMatrix.MatrixWidth);
|
tile = new DrawingTile(TileMatrix.ZoomLevel, x, y, WmtsTileMatrix.MatrixWidth);
|
||||||
|
|
||||||
var equivalentTile = Tiles.FirstOrDefault(t => t.ImageSource != null && t.Column == tile.Column && t.Row == tile.Row);
|
var equivalentTile = Tiles.FirstOrDefault(t => t.ImageSource != null && t.Column == tile.Column && t.Row == tile.Row);
|
||||||
|
|
||||||
if (equivalentTile != null)
|
if (equivalentTile != null)
|
||||||
{
|
{
|
||||||
tile.IsPending = false;
|
tile.IsPending = false;
|
||||||
tile.ImageSource = equivalentTile.ImageSource;
|
tile.ImageSource = equivalentTile.ImageSource; // no Opacity animation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Loading…
Reference in a new issue