Skip to content

Commit

Permalink
Add max zoom default (#745)
Browse files Browse the repository at this point in the history
Co-authored-by: Simon Høxbro Hansen <simon.hansen@me.com>
  • Loading branch information
ahuang11 and hoxbro committed Sep 9, 2024
1 parent 7d1d56d commit 58a9e7d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
18 changes: 17 additions & 1 deletion examples/user_guide/Working_with_Bokeh.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"metadata": {},
"outputs": [],
"source": [
"gts.EsriImagery.opts(width=600, height=570, global_extent=True) * gts.StamenLabels.options(level='annotation')"
"gts.EsriImagery.opts(width=600, height=570, global_extent=True) * gts.StamenLabels.opts(level='annotation')"
]
},
{
Expand All @@ -95,6 +95,22 @@
"gv.util.get_tile_rgb(tiles, bbox=(-180, -70, 180, 70), zoom_level=1).opts(width=500, height=500, projection=ccrs.Orthographic())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Note, that a `max_zoom` default is set for some tile sources; if you need a more detailed map, and the tile source supports it, you can increase this value. However, if the tile source does not support the requested zoom level, the tile source could return tiles that are empty or tiles that note \"map data not yet available\", depending on how the tile source handles those requests."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"gts.EsriImagery.opts(max_zoom=30)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down
20 changes: 19 additions & 1 deletion geoviews/plotting/bokeh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@
project_quadmesh,
project_vectorfield,
)
from ...tile_sources import _ATTRIBUTIONS
from ...tile_sources import (
_ATTRIBUTIONS,
ESRI,
OSM,
EsriImagery,
EsriNatGeo,
EsriWorldHillshade,
)
from ...util import line_types, poly_types
from . import callbacks # noqa
from .plot import GeoOverlayPlot, GeoPlot
Expand All @@ -60,6 +67,15 @@
class ImageStackPlot:
...

_TILE_MAX_ZOOM = {
OSM: 19,
ESRI: 19,
EsriImagery: 19,
EsriNatGeo: 16,
EsriWorldHillshade: 16,
}


class TilePlot(GeoPlot):

style_opts = [
Expand Down Expand Up @@ -102,6 +118,8 @@ def get_data(self, element, ranges, style):
'Must contain {X}/{Y}/{Z}, {XMIN}/{XMAX}/{YMIN}/{YMAX} '
'or {Q} template strings.')
params = {'url': element.data}
if element in _TILE_MAX_ZOOM:
params['max_zoom'] = _TILE_MAX_ZOOM[element]
for zoom in ('min_zoom', 'max_zoom'):
if zoom in style:
params[zoom] = style[zoom]
Expand Down
6 changes: 6 additions & 0 deletions geoviews/tests/plotting/bokeh/test_tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from holoviews.tests.plotting.bokeh.test_plot import TestBokehPlot, bokeh_renderer

from geoviews.element import WMTS
from geoviews.plotting.bokeh import TilePlot
from geoviews.tile_sources import OSM


class TestWMTSPlot(TestBokehPlot):
Expand All @@ -17,3 +19,7 @@ def test_xyzservices_tileprovider(self):
assert glyph.attribution == osm.html_attribution
assert glyph.url == osm.build_url(scale_factor="@2x")
assert glyph.max_zoom == osm.max_zoom

def test_max_zoom_default(self):
tile_source = TilePlot(OSM).get_data(OSM, (0, 0, 0, 0), {})[1]["tile_source"]
assert tile_source.max_zoom == 19

0 comments on commit 58a9e7d

Please sign in to comment.