mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-02-18 21:56:04 +01:00
Version 4.12.2 Reverted to previous ITileImageLoader
This commit is contained in:
parent
ad17312118
commit
21d7fa842d
|
|
@ -21,10 +21,7 @@ namespace MapControl
|
|||
{
|
||||
public interface ITileImageLoader
|
||||
{
|
||||
TileSource TileSource { get; set; }
|
||||
string SourceName { get; set; }
|
||||
|
||||
void LoadTilesAsync(IEnumerable<Tile> tiles);
|
||||
void LoadTilesAsync(IEnumerable<Tile> tiles, TileSource tileSource, string sourceName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -54,8 +51,7 @@ namespace MapControl
|
|||
new PropertyMetadata(null, (o, e) => ((MapTileLayer)o).TileSourcePropertyChanged()));
|
||||
|
||||
public static readonly DependencyProperty SourceNameProperty = DependencyProperty.Register(
|
||||
nameof(SourceName), typeof(string), typeof(MapTileLayer),
|
||||
new PropertyMetadata(null, (o, e) => ((MapTileLayer)o).TileImageLoader.SourceName = (string)e.NewValue));
|
||||
nameof(SourceName), typeof(string), typeof(MapTileLayer), new PropertyMetadata(null));
|
||||
|
||||
public static readonly DependencyProperty DescriptionProperty = DependencyProperty.Register(
|
||||
nameof(Description), typeof(string), typeof(MapTileLayer), new PropertyMetadata(null));
|
||||
|
|
@ -275,8 +271,6 @@ namespace MapControl
|
|||
|
||||
private void TileSourcePropertyChanged()
|
||||
{
|
||||
TileImageLoader.TileSource = TileSource;
|
||||
|
||||
if (TileGrid != null)
|
||||
{
|
||||
Tiles = new List<Tile>();
|
||||
|
|
@ -397,7 +391,7 @@ namespace MapControl
|
|||
Children.Add(tile.Image);
|
||||
}
|
||||
|
||||
TileImageLoader.LoadTilesAsync(Tiles);
|
||||
TileImageLoader.LoadTilesAsync(Tiles, TileSource, SourceName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,33 +48,34 @@ namespace MapControl
|
|||
private readonly TileQueue tileQueue = new TileQueue();
|
||||
private int taskCount;
|
||||
|
||||
public TileSource TileSource { get; set; }
|
||||
public string SourceName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Loads all pending tiles from the tiles collection in up to MaxLoadTasks parallel Tasks.
|
||||
/// If the UriFormat of TileSource starts with "http" and SourceName is a non-empty string,
|
||||
/// If the UriFormat of the TileSource starts with "http" and sourceName is a non-empty string,
|
||||
/// tile images will be cached in the TileImageLoader's Cache.
|
||||
/// </summary>
|
||||
public void LoadTilesAsync(IEnumerable<Tile> tiles)
|
||||
public void LoadTilesAsync(IEnumerable<Tile> tiles, TileSource tileSource, string sourceName)
|
||||
{
|
||||
tileQueue.Clear();
|
||||
tileQueue.Enqueue(tiles);
|
||||
|
||||
var newTasks = Math.Min(tileQueue.Count, MaxLoadTasks) - taskCount;
|
||||
|
||||
if (newTasks > 0)
|
||||
if (tileSource != null)
|
||||
{
|
||||
Interlocked.Add(ref taskCount, newTasks);
|
||||
tileQueue.Enqueue(tiles);
|
||||
|
||||
while (--newTasks >= 0)
|
||||
var newTasks = Math.Min(tileQueue.Count, MaxLoadTasks) - taskCount;
|
||||
|
||||
if (newTasks > 0)
|
||||
{
|
||||
Task.Run(() => LoadTilesFromQueueAsync());
|
||||
Interlocked.Add(ref taskCount, newTasks);
|
||||
|
||||
while (--newTasks >= 0)
|
||||
{
|
||||
Task.Run(() => LoadTilesFromQueueAsync(tileSource, sourceName));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task LoadTilesFromQueueAsync()
|
||||
private async Task LoadTilesFromQueueAsync(TileSource tileSource, string sourceName)
|
||||
{
|
||||
Tile tile;
|
||||
|
||||
|
|
@ -82,7 +83,7 @@ namespace MapControl
|
|||
{
|
||||
try
|
||||
{
|
||||
await LoadTileImageAsync(tile, TileSource, SourceName).ConfigureAwait(false);
|
||||
await LoadTileImageAsync(tile, tileSource, sourceName).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
@ -95,33 +96,30 @@ namespace MapControl
|
|||
|
||||
private async Task LoadTileImageAsync(Tile tile, TileSource tileSource, string sourceName)
|
||||
{
|
||||
if (tileSource != null)
|
||||
if (Cache != null &&
|
||||
tileSource.UriFormat != null &&
|
||||
tileSource.UriFormat.StartsWith("http") &&
|
||||
!string.IsNullOrEmpty(sourceName))
|
||||
{
|
||||
if (Cache != null &&
|
||||
tileSource.UriFormat != null &&
|
||||
tileSource.UriFormat.StartsWith("http") &&
|
||||
!string.IsNullOrEmpty(sourceName))
|
||||
{
|
||||
var uri = tileSource.GetUri(tile.XIndex, tile.Y, tile.ZoomLevel);
|
||||
var uri = tileSource.GetUri(tile.XIndex, tile.Y, tile.ZoomLevel);
|
||||
|
||||
if (uri != null)
|
||||
if (uri != null)
|
||||
{
|
||||
var extension = Path.GetExtension(uri.LocalPath);
|
||||
|
||||
if (string.IsNullOrEmpty(extension) || extension == ".jpeg")
|
||||
{
|
||||
var extension = Path.GetExtension(uri.LocalPath);
|
||||
|
||||
if (string.IsNullOrEmpty(extension) || extension == ".jpeg")
|
||||
{
|
||||
extension = ".jpg";
|
||||
}
|
||||
|
||||
var cacheKey = string.Format(CacheKeyFormat, sourceName, tile.ZoomLevel, tile.XIndex, tile.Y, extension);
|
||||
|
||||
await LoadCachedTileImageAsync(tile, uri, cacheKey).ConfigureAwait(false);
|
||||
extension = ".jpg";
|
||||
}
|
||||
|
||||
var cacheKey = string.Format(CacheKeyFormat, sourceName, tile.ZoomLevel, tile.XIndex, tile.Y, extension);
|
||||
|
||||
await LoadCachedTileImageAsync(tile, uri, cacheKey).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
await LoadTileImageAsync(tile, tileSource).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
await LoadTileImageAsync(tile, tileSource).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue