This is just a convenience method around iface.addRasterLayer() which transforms a tile server URL (with the position of arguments marked by substrings such as {x}, {y}, {z} and {q}) to a WMS provider string that makes use of the native tile support available starting from QGIS 2.18. A number of tile sources such as OSM, Google and Bing (see examples below) are supported, no other plugins are needed.

iface.addTileLayer(url, layerName = NULL, ...)

Arguments

url

the tile server URL, a character string marking the position of arguments by substrings such as {x}, {y}, {z} and {q}.

layerName

name for the new layer to be displayed in the QGIS layers panel

...

low-level parameters (such as host and auth) to be passed on to qgisremote()

Value

A representation of the layer just added (a list of class qgislayer()).

See also

qgislayer(), iface.addRasterLayer(), mapLayer(), mapLayers()

Examples

# OSM tiles iface.addTileLayer('http://c.tile.openstreetmap.org/{z}/{x}/{y}.png')
#> QGIS map layer with the following properties: #> crs: CRS arguments: #> +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 #> +k=1.0 +units=m +nadgrids=@null +no_defs #> valid: [1] TRUE #> name: [1] "c.tile.openstreetmap.org tiles" #> extent: [1] -20037508 -20037508 20037508 20037508 #> publicSource: [1] "type=xyz&url=http%3A%2F%2Fc.tile.openstreetmap.org%2F%7Bz%7D%2F%7Bx%7D%2F%7By%7D.png" #> type: [1] 1 #> id: [1] "c_tile_openstreetmap_org_tiles20170830121433166" #> isEditable: [1] FALSE
# Google satellite tiles iface.addTileLayer('http://mt1.google.com/vt/lyrs=s&x={x}&y={y}&z={z}')
#> QGIS map layer with the following properties: #> crs: CRS arguments: #> +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 #> +k=1.0 +units=m +nadgrids=@null +no_defs #> valid: [1] TRUE #> name: [1] "mt1.google.com tiles" #> extent: [1] -20037508 -20037508 20037508 20037508 #> publicSource: [1] "type=xyz&url=http%3A%2F%2Fmt1.google.com%2Fvt%2Flyrs%3Ds%26x%3D%7Bx%7D%26y%3D%7By%7D%26z%3D%7Bz%7D" #> type: [1] 1 #> id: [1] "mt1_google_com_tiles20170830121433364" #> isEditable: [1] FALSE
# Google standard roadmap iface.addTileLayer('http://mt1.google.com/vt/lyrs=m&x={x}&y={y}&z={z}')
#> QGIS map layer with the following properties: #> crs: CRS arguments: #> +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 #> +k=1.0 +units=m +nadgrids=@null +no_defs #> valid: [1] TRUE #> name: [1] "mt1.google.com tiles" #> extent: [1] -20037508 -20037508 20037508 20037508 #> publicSource: [1] "type=xyz&url=http%3A%2F%2Fmt1.google.com%2Fvt%2Flyrs%3Dm%26x%3D%7Bx%7D%26y%3D%7By%7D%26z%3D%7Bz%7D" #> type: [1] 1 #> id: [1] "mt1_google_com_tiles20170830121433782" #> isEditable: [1] FALSE
# for other tile services see https://gis.stackexchange.com/a/217670/93020