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