Layer Group#

Example#

from ipyleaflet import (
    Map, basemaps, basemap_to_tiles,
    Circle, Marker, Rectangle, LayerGroup
)

toner = basemap_to_tiles(basemaps.Stamen.Toner)

m = Map(layers=(toner, ), center=(50, 354), zoom=5)

# Create some layers
marker = Marker(location=(50, 354))
circle = Circle(location=(50, 370), radius=50000, color="yellow", fill_color="yellow")
rectangle = Rectangle(bounds=((54, 354), (55, 360)), color="orange", fill_color="orange")

# Create layer group
layer_group = LayerGroup(layers=(marker, circle))

m.add_layer(layer_group)

layer_group.add_layer(rectangle)

layer_group.remove_layer(circle)

m

Attributes and methods#

class ipyleaflet.leaflet.LayerGroup(**kwargs)[source]#

LayerGroup class.

A group of layers that you can put on the map like other layers.

layers#

List of layers to include in the group.

Type

list, default []

add_layer(layer)[source]#

Add a new layer to the group.

Parameters

layer (layer instance) – The new layer to include in the group.

clear_layers()[source]#

Remove all layers from the group.

remove_layer(rm_layer)[source]#

Remove a layer from the group.

Parameters

layer (layer instance) – The layer to remove from the group.

substitute_layer(old, new)[source]#

Substitute a layer with another one in the group.

Parameters
  • old (layer instance) – The layer to remove from the group.

  • new (layer instance) – The new layer to include in the group.