mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-08 16:05:50 +00:00
Abstract classes Tile, TileSource
This commit is contained in:
parent
20e4fcce75
commit
cb8fff0dd1
14 changed files with 95 additions and 98 deletions
|
|
@ -7,61 +7,16 @@ using System.Collections.Generic;
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
#if WPF
|
||||
using System.Windows.Media;
|
||||
#elif UWP
|
||||
using Windows.UI.Xaml.Media;
|
||||
#elif WINUI
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
#elif AVALONIA
|
||||
using ImageSource = Avalonia.Media.IImage;
|
||||
#endif
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
public interface ITile
|
||||
{
|
||||
int ZoomLevel { get; }
|
||||
int Column { get; }
|
||||
int Row { get; }
|
||||
bool IsPending { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Runs a tile image download Task and marshals the result to the UI thread.
|
||||
/// </summary>
|
||||
Task LoadImageAsync(Func<Task<ImageSource>> loadImageFunc);
|
||||
}
|
||||
|
||||
public interface ITileSource
|
||||
{
|
||||
/// <summary>
|
||||
/// Indicates whether tile images from this source should be cached.
|
||||
/// </summary>
|
||||
bool Cacheable { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the image Uri for the specified zoom level and tile indices.
|
||||
/// </summary>
|
||||
Uri GetUri(int zoomLevel, int column, int row);
|
||||
|
||||
/// <summary>
|
||||
/// Loads a tile image whithout caching.
|
||||
/// </summary>
|
||||
Task<ImageSource> LoadImageAsync(int zoomLevel, int column, int row);
|
||||
|
||||
/// <summary>
|
||||
/// Loads a cacheable tile image from an encoded frame buffer.
|
||||
/// </summary>
|
||||
Task<ImageSource> LoadImageAsync(byte[] buffer);
|
||||
}
|
||||
|
||||
public interface ITileImageLoader
|
||||
{
|
||||
/// <summary>
|
||||
/// Loads all pending tiles from the tiles collection.
|
||||
/// Tile image caching is enabled when tileSource.UriFormat starts with "http" and cacheName is a non-empty string.
|
||||
/// </summary>
|
||||
void BeginLoadTiles(IEnumerable<ITile> tiles, ITileSource tileSource, string cacheName, IProgress<double> progress);
|
||||
void BeginLoadTiles(IEnumerable<Tile> tiles, TileSource tileSource, string cacheName, IProgress<double> progress);
|
||||
|
||||
/// <summary>
|
||||
/// Cancels a potentially ongoing tile loading task.
|
||||
|
|
@ -115,11 +70,11 @@ namespace MapControl
|
|||
/// </summary>
|
||||
public static int MaxLoadTasks { get; set; } = 4;
|
||||
|
||||
private readonly Queue<ITile> tileQueue = new();
|
||||
private readonly Queue<Tile> tileQueue = new();
|
||||
private int tileCount;
|
||||
private int taskCount;
|
||||
|
||||
public void BeginLoadTiles(IEnumerable<ITile> tiles, ITileSource tileSource, string cacheName, IProgress<double> progress)
|
||||
public void BeginLoadTiles(IEnumerable<Tile> tiles, TileSource tileSource, string cacheName, IProgress<double> progress)
|
||||
{
|
||||
if (Cache == null || !tileSource.Cacheable)
|
||||
{
|
||||
|
|
@ -158,9 +113,9 @@ namespace MapControl
|
|||
}
|
||||
}
|
||||
|
||||
private async Task LoadTilesFromQueue(ITileSource tileSource, string cacheName, IProgress<double> progress)
|
||||
private async Task LoadTilesFromQueue(TileSource tileSource, string cacheName, IProgress<double> progress)
|
||||
{
|
||||
bool TryDequeueTile(out ITile tile)
|
||||
bool TryDequeueTile(out Tile tile)
|
||||
{
|
||||
lock (tileQueue)
|
||||
{
|
||||
|
|
@ -178,7 +133,7 @@ namespace MapControl
|
|||
return false;
|
||||
}
|
||||
|
||||
while (TryDequeueTile(out ITile tile))
|
||||
while (TryDequeueTile(out Tile tile))
|
||||
{
|
||||
tile.IsPending = false;
|
||||
|
||||
|
|
@ -218,7 +173,7 @@ namespace MapControl
|
|||
}
|
||||
}
|
||||
|
||||
private static async Task<byte[]> LoadCachedBuffer(ITile tile, Uri uri, string cacheName)
|
||||
private static async Task<byte[]> LoadCachedBuffer(Tile tile, Uri uri, string cacheName)
|
||||
{
|
||||
var extension = Path.GetExtension(uri.LocalPath).ToLower();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue