RegionDownloader

@objc
public class RegionDownloader : NSObject

Hey! I need to download this area of the map. No problemo.

This class allows you to download all the tiles of a region of the map.

Internally what it does is to iterate over every tile coordinate within the region and request to a mapCache to download it by calling its loadTile method.

In order to keep track of the downloaded data you can implement ReguionDownloaderDelegate.

Based on the value of incrementInPercentageNotification the delegate will be called.

Experimental

  • Approximation of the average number of bytes of a tile (used with 256x256 tiles).

    Declaration

    Swift

    static let defaultAverageTileSizeBytes: UInt64
  • Region that will be downloaded.

    Initialized in the constructor

    Declaration

    Swift

    public let region: TileCoordsRegion
  • Cache that is going to be used for saving/loading the files.

    Declaration

    Swift

    public let mapCache: MapCacheProtocol
  • Total number of tiles to be downloaded.

    Declaration

    Swift

    public var totalTilesToDownload: TileNumber { get }
  • Number of tiles pending to be downloaded.

    Declaration

    Swift

    public var pendingTilesToDownload: TileNumber { get }
  • Maximum number of concurrent downloads. Default 30. If you set this to a low number, the download will take longer. If you set this to a high number, the download may fail due to too many concurrent downloads (e.g. 429 Too Many Requests). The downloader will automatically try after timeout.

    Declaration

    Swift

    public var maxConcurrentDownloads: Int
  • Timeout for the download in seconds. Default 10 seconds. When the maximum number of concurrent downloads is reached, this is the time the downloader will wait for a download to finish before trying again. The downloader will automatically try after timeout.

    Declaration

    Swift

    public var downloadTimeout: TimeInterval
  • The variable that actually keeps the count of the downloaded bytes.

    Declaration

    Swift

    private var _downloadedBytes: UInt64
  • Indicates that the download has been paused due to too many concurrent downloads. The downloader will automatically try after timeout.

    Declaration

    Swift

    private var _stopped: Bool
  • Tracks already processed tiles to avoid double-counting on resume.

    Declaration

    Swift

    private var _processedTileKeys: Set<String>
  • Total number of downloaded data bytes.

    Declaration

    Swift

    public var downloadedBytes: UInt64 { get }
  • Returns the average

    This can be used to estimate the amount of bytes pending to be downloaded.

    Declaration

    Swift

    public var averageTileSizeBytes: UInt64 { get }
  • Keeps the number of tiles already downloaded successfully or failed.

    Declaration

    Swift

    @objc
    dynamic public var downloadedTiles: TileNumber { get }
  • Number of successfully downloaded tiles.

    Declaration

    Swift

    private var _successfulTileDownloads: TileNumber
  • Keeps the number of tiles already downloaded.

    Declaration

    Swift

    @objc
    dynamic public var successfulTileDownloads: TileNumber { get }
  • Keeps the number of tiles failes to be downloaded. Publicly accessible through failledTIleDownloads.

    Declaration

    Swift

    private var _failedTileDownloads: TileNumber
  • Number of tiles to be downloaded

    Declaration

    Swift

    @objc
    dynamic public var failedTileDownloads: TileNumber { get }
  • Percentage to notify thought delegate. If set to >100 will only notify on finish download. If set to a percentage smaller than downloadedPercentage, it will never notify.

    Declaration

    Swift

    public var nextPercentageToNotify: Double
  • The downloader will notify the delegate every time this. For example if you set this to 5, it will notify when 5%, 10%, 15%, etc. Default value 5.

    Declaration

    Swift

    public var incrementInPercentageNotification: Double
  • Last percentage notified to the deletage.

    Declaration

    Swift

    var lastPercentageNotified: Double
  • Percentage of tiles pending to download.

    Declaration

    Swift

    public var downloadedPercentage: Double { get }
  • Delegate.

    Declaration

    Swift

    public var delegate: RegionDownloaderDelegate?
  • Queue to download the stuff.

    Declaration

    Swift

    lazy var downloaderQueue: DispatchQueue { get set }
  • Initializes the downloader with the region and the MapCache.

    Declaration

    Swift

    public init(forRegion region: TileCoordsRegion, mapCache: MapCacheProtocol)

    Parameters

    forRegion

    the region to be downloaded.

    mapCache

    the MapCache implementation used to download and store the downloaded data

  • Resets downloader counters.

    Declaration

    Swift

    public func resetCounters()
  • Starts download.

    Declaration

    Swift

    public func start()
  • Resumes a paused download without resetting counters.

    Declaration

    Swift

    public func resume()
  • Stop download.

    Declaration

    Swift

    public func stop()
  • Declaration

    Swift

    private func downloadLoop(isResume: Bool = false)
  • Returns an estimation of the total number of bytes the whole region may occupy. Again, it is an estimation.

    Declaration

    Swift

    public func estimateRegionByteSize() -> UInt64