Skip to content

Commit

Permalink
repair max_zoom and max_native_zoom (#1952)
Browse files Browse the repository at this point in the history
  • Loading branch information
Conengmo committed May 18, 2024
1 parent 5086929 commit 1e2b38d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
10 changes: 6 additions & 4 deletions folium/folium.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,12 @@ class Map(JSCSSMixin, MacroElement):
pass a custom URL, pass a TileLayer object,
or pass `None` to create a map without tiles.
For more advanced tile layer options, use the `TileLayer` class.
min_zoom: int, default 0
min_zoom: int, optional, default 0
Minimum allowed zoom level for the tile layer that is created.
max_zoom: int, default 18
Filled by xyzservices by default.
max_zoom: int, optional, default 18
Maximum allowed zoom level for the tile layer that is created.
Filled by xyzservices by default.
zoom_start: int, default 10
Initial zoom level for the map.
attr: string, default None
Expand Down Expand Up @@ -244,8 +246,8 @@ def __init__(
position: str = "relative",
tiles: Union[str, TileLayer, None] = "OpenStreetMap",
attr: Optional[str] = None,
min_zoom: int = 0,
max_zoom: int = 18,
min_zoom: Optional[int] = None,
max_zoom: Optional[int] = None,
zoom_start: int = 10,
min_lat: int = -90,
max_lat: int = 90,
Expand Down
27 changes: 15 additions & 12 deletions folium/raster_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ class TileLayer(Layer):
You can also pass a custom tileset by passing a
:class:`xyzservices.TileProvider` or a Leaflet-style
URL to the tiles parameter: ``https://{s}.yourtiles.com/{z}/{x}/{y}.png``.
min_zoom: int, default 0
Minimum allowed zoom level for this tile layer.
max_zoom: int, default 18
Maximum allowed zoom level for this tile layer.
min_zoom: int, optional, default 0
Minimum allowed zoom level for this tile layer. Filled by xyzservices by default.
max_zoom: int, optional, default 18
Maximum allowed zoom level for this tile layer. Filled by xyzservices by default.
max_native_zoom: int, default None
The highest zoom level at which the tile server can provide tiles.
If provided you can zoom in past this level. Else tiles will turn grey.
Filled by xyzservices by default.
By setting max_zoom higher than max_native_zoom, you can zoom in
past max_native_zoom, tiles will be autoscaled.
attr: string, default None
Map tile attribution; only required if passing custom tile URL.
detect_retina: bool, default False
Expand Down Expand Up @@ -89,8 +91,8 @@ class TileLayer(Layer):
def __init__(
self,
tiles: Union[str, xyzservices.TileProvider] = "OpenStreetMap",
min_zoom: int = 0,
max_zoom: int = 18,
min_zoom: Optional[int] = None,
max_zoom: Optional[int] = None,
max_native_zoom: Optional[int] = None,
attr: Optional[str] = None,
detect_retina: bool = False,
Expand All @@ -117,8 +119,9 @@ def __init__(

if isinstance(tiles, xyzservices.TileProvider):
attr = attr if attr else tiles.html_attribution # type: ignore
min_zoom = tiles.get("min_zoom", min_zoom)
max_zoom = tiles.get("max_zoom", max_zoom)
min_zoom = min_zoom or tiles.get("min_zoom")
max_zoom = max_zoom or tiles.get("max_zoom")
max_native_zoom = max_native_zoom or tiles.get("max_zoom")
subdomains = tiles.get("subdomains", subdomains)
if name is None:
name = tiles.name.replace(".", "").lower()
Expand All @@ -137,9 +140,9 @@ def __init__(
raise ValueError("Custom tiles must have an attribution.")

self.options = parse_options(
min_zoom=min_zoom,
max_zoom=max_zoom,
max_native_zoom=max_native_zoom or max_zoom,
min_zoom=min_zoom or 0,
max_zoom=max_zoom or 18,
max_native_zoom=max_native_zoom,
no_wrap=no_wrap,
attribution=attr,
subdomains=subdomains,
Expand Down

0 comments on commit 1e2b38d

Please sign in to comment.