Max zoom level no longer working from 0.14.0 to 0.15.1 (defaults to 18)
Stephaneke opened this issue · comments
Describe the bug
Since the update from 0.14.0 to 0.15.1, the max zoom level function does no longer work and defaults to 18?
To Reproduce
[ Include a code snippet that produces your bug. Make it standalone, we should be able to run it. ]
import folium
m = folium.Map(location=[51.505492, -0.075408], zoom_start=12, max_zoom=25)
# add a circle marker of 5 radius at scale at the center of the map
folium.CircleMarker(location=[51.505492, -0.075408], radius=5, color='#3186cc', fill=True, fill_color='#3186cc').add_to(m)
m.save('interactive_map_0.14.0.html')
[ Include a data sample or link to your data if necessary to run the code ]
Expected behavior
I expect the maximum zoom level to be 25 instead of 18
Environment (please complete the following information):
Possible solutions
List any solutions you may have come up with.
folium is maintained by volunteers. Can you help making a fix for this issue?
Can confirm. In the TileLayer
class we now default to the max_zoom
that's defined in the xyzservices.TileProvider
object if available.
Also note how this works in tandem with max_native_zoom
.
We should fix this and improve documentation.
So there is still a possibility to increase the zoom level? Or is it disabled in the newest updates? If you are working on a small scale (e.g. meters), this is almost a necessity.
@Stephaneke The maximum zoom is defined by the tile provider. You can play around with different tile layers to see how that affects the max zoom level. E.g. folium.TileLayer('CartoDB Positron').add_to(m)
gives me a maximum zoom level of 20. OpenStreetMap (the default) goes to 19.
Our documentation is off as the max_zoom
and max_native_zoom
parameters seem to be ignored.
@Stephaneke I did a quick experiment with a different provider. This one goes to level 22, which is the best I could find. It does require an api key. Parts in angle brackets need to be replaced.
See https://github.com/leaflet-extras/leaflet-providers/blob/master/leaflet-providers.js for other providers.
folium.TileLayer(
'https://tile.jawg.io/<variant, e.g. jawg-dark>/{z}/{x}/{y}{r}.png?access-token=<get your own>',
attr="<attribution>",
max_zoom=22,
max_native_zoom=22,
).add_to(m)
This probably broke when we adopted xyzservices. This probably needs more than just a documentation change. Ideally we restore the previous behavior as described in the rasterlayer docstring. But now the ‘max_native_zoom’ value comes from xyzservices? And ‘max_zoom’ allows further zooming? Something like that.
I did a few tests. max_zoom
on Map
does not seem to be honored at all and leaflet seems to be taking the max zoom level from the tile layers. max_native_zoom
on TileLayer
seems to do nothing (probably because it comes from xyzservice). max_zoom
on TileLayer
does seem to limit how far you can zoom in for that TileLayer
. Leaflet will fall back to the default TileLayer
if you zoom in beyond that.
My feeling is that max_zoom
on Map
should just limit how far one can zoom if it is less than the maximum zoom level of the associated layers. Perhaps we can give a warning if the user sets a too high max_zoom
level?
I made a PR to bring back the behavior we had before, while keeping the values we get from xyzservices: #1952