mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Added MapTileLayerBase.LoadTiles method
This commit is contained in:
parent
f38ac5bec3
commit
ab69894f13
|
|
@ -146,7 +146,7 @@ namespace MapControl
|
|||
Children.Add(tile.Image);
|
||||
}
|
||||
|
||||
TileImageLoader.LoadTiles(Tiles, TileSource, SourceName);
|
||||
LoadTiles(Tiles, SourceName);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ namespace MapControl
|
|||
{
|
||||
public interface ITileImageLoader
|
||||
{
|
||||
void LoadTiles(IEnumerable<Tile> tiles, TileSource tileSource, string sourceName);
|
||||
void LoadTiles(IEnumerable<Tile> tiles, TileSource tileSource, string cacheName);
|
||||
}
|
||||
|
||||
public abstract class MapTileLayerBase : Panel, IMapLayer
|
||||
|
|
@ -189,5 +189,10 @@ namespace MapControl
|
|||
protected abstract void UpdateTileLayer(bool tileSourceChanged);
|
||||
|
||||
protected abstract void SetRenderTransform();
|
||||
|
||||
protected virtual void LoadTiles(IEnumerable<Tile> tiles, string cacheName)
|
||||
{
|
||||
TileImageLoader.LoadTiles(tiles, TileSource, cacheName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ namespace MapControl
|
|||
public static TimeSpan DefaultCacheExpiration { get; set; } = TimeSpan.FromDays(1);
|
||||
|
||||
/// <summary>
|
||||
/// Format string for creating cache keys from the sourceName argument passed to LoadTilesAsync,
|
||||
/// Format string for creating cache keys from the cacheName argument passed to LoadTilesAsync,
|
||||
/// the ZoomLevel, XIndex, and Y properties of a Tile, and the image file extension.
|
||||
/// The default value is "{0}/{1}/{2}/{3}{4}".
|
||||
/// </summary>
|
||||
|
|
@ -56,10 +56,10 @@ namespace MapControl
|
|||
|
||||
/// <summary>
|
||||
/// Loads all pending tiles from the tiles collection.
|
||||
/// If tileSource.UriFormat starts with "http" and sourceName is a non-empty string,
|
||||
/// If tileSource.UriFormat starts with "http" and cacheName is a non-empty string,
|
||||
/// tile images will be cached in the TileImageLoader's Cache (if that is not null).
|
||||
/// </summary>
|
||||
public void LoadTiles(IEnumerable<Tile> tiles, TileSource tileSource, string sourceName)
|
||||
public void LoadTiles(IEnumerable<Tile> tiles, TileSource tileSource, string cacheName)
|
||||
{
|
||||
tileQueue.Clear();
|
||||
|
||||
|
|
@ -70,9 +70,9 @@ namespace MapControl
|
|||
if (Cache != null &&
|
||||
tileSource.UriFormat != null &&
|
||||
tileSource.UriFormat.StartsWith("http") &&
|
||||
!string.IsNullOrEmpty(sourceName))
|
||||
!string.IsNullOrEmpty(cacheName))
|
||||
{
|
||||
loadTile = tile => LoadCachedTileAsync(tile, tileSource, sourceName);
|
||||
loadTile = tile => LoadCachedTileAsync(tile, tileSource, cacheName);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -109,7 +109,7 @@ namespace MapControl
|
|||
Interlocked.Decrement(ref taskCount);
|
||||
}
|
||||
|
||||
private static async Task LoadCachedTileAsync(Tile tile, TileSource tileSource, string sourceName)
|
||||
private static async Task LoadCachedTileAsync(Tile tile, TileSource tileSource, string cacheName)
|
||||
{
|
||||
var uri = tileSource.GetUri(tile.XIndex, tile.Y, tile.ZoomLevel);
|
||||
|
||||
|
|
@ -122,7 +122,7 @@ namespace MapControl
|
|||
extension = ".jpg";
|
||||
}
|
||||
|
||||
var cacheKey = string.Format(CacheKeyFormat, sourceName, tile.ZoomLevel, tile.XIndex, tile.Y, extension);
|
||||
var cacheKey = string.Format(CacheKeyFormat, cacheName, tile.ZoomLevel, tile.XIndex, tile.Y, extension);
|
||||
|
||||
await LoadCachedTileAsync(tile, uri, cacheKey).ConfigureAwait(false);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -162,15 +162,15 @@ namespace MapControl
|
|||
}
|
||||
|
||||
var tileSource = TileSource as WmtsTileSource;
|
||||
var sourceName = SourceName;
|
||||
var cacheName = SourceName;
|
||||
|
||||
if (tileSource != null && tileMatrixSet != null)
|
||||
{
|
||||
tileSource.TileMatrixSet = tileMatrixSet;
|
||||
|
||||
if (sourceName != null)
|
||||
if (cacheName != null)
|
||||
{
|
||||
sourceName += "/" + tileMatrixSet.Identifier
|
||||
cacheName += "/" + tileMatrixSet.Identifier
|
||||
.Replace(':', '_')
|
||||
.Replace(';', '_')
|
||||
.Replace(',', '_')
|
||||
|
|
@ -179,7 +179,7 @@ namespace MapControl
|
|||
}
|
||||
}
|
||||
|
||||
TileImageLoader.LoadTiles(tiles, tileSource, sourceName);
|
||||
LoadTiles(tiles, cacheName);
|
||||
}
|
||||
|
||||
private async void OnLoaded(object sender, RoutedEventArgs e)
|
||||
|
|
|
|||
|
|
@ -14,7 +14,10 @@ namespace MapControl
|
|||
{
|
||||
Uri uri = null;
|
||||
|
||||
if (UriFormat != null && TileMatrixSet != null && zoomLevel >= 0 && zoomLevel < TileMatrixSet.TileMatrixes.Count)
|
||||
if (UriFormat != null &&
|
||||
TileMatrixSet != null &&
|
||||
zoomLevel >= 0 &&
|
||||
zoomLevel < TileMatrixSet.TileMatrixes.Count)
|
||||
{
|
||||
uri = new Uri(UriFormat
|
||||
.Replace("{TileMatrixSet}", TileMatrixSet.Identifier)
|
||||
|
|
|
|||
Loading…
Reference in a new issue