Create layer group toggle buttons
This example shows how to create layer group toggle buttons for the layer manager.
Uncomment the following line to install leafmap if needed.
In [1]:
Copied!
# %pip install "leafmap[maplibre]"
# %pip install "leafmap[maplibre]"
In [2]:
Copied!
import leafmap.maplibregl as leafmap
import leafmap.maplibregl as leafmap
In [3]:
Copied!
m = leafmap.Map()
## Add basemap layers
m.add_basemap("USGS.Imagery")
m.add_basemap("OpenTopoMap")
# Add GeoJSON layers
point_url = (
"https://github.com/opengeos/datasets/releases/download/world/world_cities.geojson"
)
m.add_geojson(point_url, name="Points")
line_url = (
"https://github.com/opengeos/datasets/releases/download/vector/cables.geojson"
)
m.add_geojson(line_url, name="Lines")
# Create layer groups
groups = {"Basemap": ["USGS.Imagery", "OpenTopoMap"], "GeoJSON": ["Points", "Lines"]}
# Add a layer manager with group toggle buttons
m.add_layer_manager(label="Layer Manager", groups=groups)
# Display the map
m
m = leafmap.Map()
## Add basemap layers
m.add_basemap("USGS.Imagery")
m.add_basemap("OpenTopoMap")
# Add GeoJSON layers
point_url = (
"https://github.com/opengeos/datasets/releases/download/world/world_cities.geojson"
)
m.add_geojson(point_url, name="Points")
line_url = (
"https://github.com/opengeos/datasets/releases/download/vector/cables.geojson"
)
m.add_geojson(line_url, name="Lines")
# Create layer groups
groups = {"Basemap": ["USGS.Imagery", "OpenTopoMap"], "GeoJSON": ["Points", "Lines"]}
# Add a layer manager with group toggle buttons
m.add_layer_manager(label="Layer Manager", groups=groups)
# Display the map
m
WARNING:pyogrio._io:Skipping field coordinates: unsupported OGR type: 3