Fit a map to a bounding box
This source code of this example is adapted from the MapLibre GL JS example - Fit a map to a bounding box.
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!
# import os
# os.environ["MAPTILER_KEY"] = "YOUR_API_KEY"
# import os
# os.environ["MAPTILER_KEY"] = "YOUR_API_KEY"
In [4]:
Copied!
m = leafmap.Map(center=[-74.5, 40], zoom=9, style="streets")
m
m = leafmap.Map(center=[-74.5, 40], zoom=9, style="streets")
m
Failed to retrieve the MapTiler style. Defaulting to 'dark-matter' style.
Fit to Kenya.
In [5]:
Copied!
bounds = [[32.958984, -5.353521], [43.50585, 5.615985]]
m.fit_bounds(bounds)
bounds = [[32.958984, -5.353521], [43.50585, 5.615985]]
m.fit_bounds(bounds)