コード例 #1
0
        private async Task LoadPendingTiles(TileQueue tileQueue, TileSource tileSource, string cacheName)
        {
            while (tileQueue.TryDequeue(out var tile))
            {
                try
                {
                    await LoadTile(tile, tileSource, cacheName).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine($"TileImageLoader: {tile.ZoomLevel}/{tile.XIndex}/{tile.Y}: {ex.Message}");
                }

                if (Progress != null && !tileQueue.IsCanceled)
                {
                    Interlocked.Increment(ref progressLoaded);

                    Progress.Report((double)progressLoaded / progressTotal);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Loads all pending tiles from the tiles collection.
        /// 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 Task LoadTiles(IEnumerable <Tile> tiles, TileSource tileSource, string cacheName)
        {
            pendingTiles?.Cancel();

            TileSource = tileSource;

            if (tileSource != null)
            {
                pendingTiles = new TileQueue(tiles);

                var numTasks = Math.Min(pendingTiles.Count, MaxLoadTasks);

                if (numTasks > 0)
                {
                    if (Progress != null)
                    {
                        progressTotal  = pendingTiles.Count;
                        progressLoaded = 0;
                        Progress.Report(0d);
                    }

                    if (Cache == null || tileSource.UriTemplate == null || !tileSource.UriTemplate.StartsWith("http"))
                    {
                        cacheName = null; // no tile caching
                    }

                    return(Task.WhenAll(Enumerable.Range(0, numTasks).Select(
                                            _ => Task.Run(() => LoadPendingTiles(pendingTiles, tileSource, cacheName)))));
                }
            }

            if (Progress != null && progressLoaded < progressTotal)
            {
                Progress.Report(1d);
            }

            return(Task.CompletedTask);
        }