Tile Layer#

Example#

from ipyleaflet import Map, basemaps, basemap_to_tiles

m = Map(center=(52.204793, 360.121558), zoom=9)

dark_matter_layer = basemap_to_tiles(basemaps.CartoDB.DarkMatter)
m.add(dark_matter_layer)
m

Usage#

Creating a TileLayer is straightforward, a dictionary containing basic tile layers is provided. This dictionary is named basemaps.

A TileLayer instance can be created using the basemap_to_tiles function, specifying the wanted map (e.g. basemaps.CartoDB.DarkMatter, basemaps.Strava.Winter, basemaps.NASAGIBS.ModisTerraTrueColorCR, …).

Sometimes one could want to specify the date of the given images, for instance with NASA images:

nasa_layer = basemap_to_tiles(basemaps.NASAGIBS.ModisTerraTrueColorCR, "2018-04-08");
m.add(nasa_layer);

To use multiple base maps and the built in base map switching in LayerControl, it is possible to create the desired TileLayer objects and set base to True. These layers can then be passed in an array to Map(layers):

from ipyleaflet import Map, basemaps, basemap_to_tiles
from ipyleaflet import LayersControl

mapnik = basemap_to_tiles(basemaps.OpenStreetMap.Mapnik)
mapnik.base = True
toner = basemap_to_tiles(basemaps.Stadia.StamenTerrain)
toner.base = True

m = Map(layers=[mapnik, toner], center=(52.204793, 360.121558), zoom=9)

# use the LayersControl to switch basemaps
m.add(LayersControl())
m

Attributes and methods#

Note that if you want to display a high resolution layer with a quite large zoom, you have to set max_zoom and max_native_zoom with equal value.

class ipyleaflet.leaflet.TileLayer(**kwargs: Any)[source]#

TileLayer class.

Tile service layer.

url#

Url to the tiles service.

Type:

string, default “https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png”

min_zoom#

The minimum zoom level down to which this layer will be displayed (inclusive).

Type:

int, default 0

max_zoom#

The maximum zoom level up to which this layer will be displayed (inclusive).

Type:

int, default 18

min_native_zoom#

Minimum zoom number the tile source has available. If it is specified, the tiles on all zoom levels lower than min_native_zoom will be loaded from min_native_zoom level and auto-scaled.

Type:

int, default None

max_native_zoom#

Maximum zoom number the tile source has available. If it is specified, the tiles on all zoom levels higher than max_native_zoom will be loaded from max_native_zoom level and auto-scaled.

Type:

int, default None

bounds#

List of SW and NE location tuples. e.g. [(50, 75), (75, 120)].

Type:

list or None, default None

tile_size#

Tile sizes for this tile service.

Type:

int, default 256

attribution#

Tiles service attribution.

Type:

string, default None.

no_wrap#

Whether the layer is wrapped around the antimeridian.

Type:

boolean, default False

tms#

If true, inverses Y axis numbering for tiles (turn this on for TMS services).

Type:

boolean, default False

zoom_offset#

The zoom number used in tile URLs will be offset with this value.

Type:

int, default 0

show_loading#

Whether to show a spinner when tiles are loading.

Type:

boolean, default False

loading#

Whether the tiles are currently loading.

Type:

boolean, default False (dynamically updated)

detect_retina#
Type:

boolean, default False

opacity#
Type:

float, default 1.0

visible#
Type:

boolean, default True

bounds#

list of SW and NE location tuples

on_load(callback, remove=False)[source]#

Add a load event listener.

Parameters:
  • callback (callable) – Callback function that will be called when the tiles have finished loading.

  • remove (boolean) – Whether to remove this callback or not. Defaults to False.

redraw()[source]#

Force redrawing the tiles.

This is especially useful when you are sure the server updated the tiles and you need to refresh the layer.