2

In leaflet.js it is possible to have multiple basemaps that show up in radio boxes at the top of LayerControl:

A leaflet LayerControl showing three layers each selectable with a radio box.

With IPyLeaflet I can do map.add_layer(tile_layer), but that is not the same as the leaflet example as the layer does not show up as a basemap layer in the LayerControl, and every basemap added this way will be loaded into the map and visible at the same time:

LayerControl showing two layers, one has a radio box and one has a check box.

How can I do this in IPyLeaflet?

Billy Hudson
  • 126
  • 11

1 Answers1

1

In IPyLeaflet, as of version 0.16.0, this can be achieved by setting the base property on the TileLayer object to True:

from ipyleaflet import *

mapnik = basemap_to_tiles(basemaps.OpenStreetMap.Mapnik)
mapnik.base = True
mapnik.name = 'Mapnik Layer'

toner = basemap_to_tiles(basemaps.Stamen.Toner)
toner.base = True
toner.name = 'Toner Layer'

bzh = basemap_to_tiles(basemaps.OpenStreetMap.BZH)
bzh.base = True
bzh.name = 'BZH layer'

m = Map(center=(52, 10), zoom=8, layers=[mapnik, toner, bzh])

m.add_control(LayersControl())

m

(Source)

Billy Hudson
  • 126
  • 11