This is my folium code:
import folium
mp = folium.Map(location=[37, -102],
zoom_start=1,
tiles="Stamen Terrain",
)
display(mp)
This is the output I get:
There are two problems with leaflet map:
Both of these are nuisance. The first issue can be addressed temporarily by setting the zoom_start
to something else than 1. But even then, zooming out of the map bring this issue back again. The less said about the second one the better.
Now what I want is to limit the boundary of my map to, say, [-150, 150, -70, 70] or smaller. And I don't want to display beyond this bound, either by panning or zooming. Neither do I want my map to pan infinitely in a loop.
Is it possible to do that in Folium?
It's possible! Just use the min_zoom (and max_zoom for the opposite problem) attribute!
f = folium.Figure(width=1000, height=500)
m = folium.Map(location= initial_location, tiles="openstreetmap",
zoom_start=zoom_start_defined, min_zoom = min_zoom_defined).add_to(f)
I think a min_zoom of 2 should do the work
One easy way is to use the max_bounds
parameter in the Map()
function and set it to True
. Using this parameter restricts the map to one view of the continents.
Here's an example :
m = folium.Map(location=loc,max_bounds=True)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With