UrlTileProvider

abstract class UrlTileProvider(urlTemplate: String) : TileProvider(source)

Abstract base class for TileProvider implementations that fetch tiles from URLs.

This class handles HTTP requests and tile downloading, while subclasses provide the URL template and optional customization.

URL templates use placeholders that are replaced with tile coordinates:

  • {z} - Zoom level

  • {x} - Tile column

  • {y} - Tile row

Example usage:

class CustomTileProvider : UrlTileProvider(
urlTemplate = "https://example.com/tiles/{z}/{x}/{y}.png"
) {
override fun getUserAgent(): String {
return "MyApp/1.0"
}
}

All instances share one HTTP client, so creating many providers (for example when overlays are switched on and off) does not create more connection pools.

See also

Constructors

Link copied to clipboard
constructor(urlTemplate: String)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
fun close()

Does nothing. All providers share one HTTP client, which must stay open for the other providers.

Link copied to clipboard
open override fun getTile(x: Int, y: Int, zoom: Int): Tile?

Downloads the tile for the specified coordinates, blocking the calling thread.

Link copied to clipboard
protected open fun getTileUrl(x: Int, y: Int, zoom: Int): String?

Builds the URL for the specified tile coordinates by replacing placeholders in the URL template.

Link copied to clipboard
protected open fun getUserAgent(): String

Returns the User-Agent header to use for HTTP requests.