Skip to content

Change layer group visibility programmatically #1118

Open
@giswqs

Description

@giswqs

The layer group can be toggled on/off manually using the LayersControl. Is it possible to change the layer group visibility programmatically? layer_group.visible=False does not work.

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

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), name='Layer Group')

m.add_layer(layer_group)

layer_group.add_layer(rectangle)

control = LayersControl(position='topright')
m.add_control(control)
m

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions