From 58a9e7dbcf55021353ff7934476d222148b6b1d7 Mon Sep 17 00:00:00 2001 From: Andrew <15331990+ahuang11@users.noreply.github.com> Date: Mon, 9 Sep 2024 09:23:10 -0700 Subject: [PATCH] Add max zoom default (#745) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Simon Høxbro Hansen --- examples/user_guide/Working_with_Bokeh.ipynb | 18 +++++++++++++++++- geoviews/plotting/bokeh/__init__.py | 20 +++++++++++++++++++- geoviews/tests/plotting/bokeh/test_tiles.py | 6 ++++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/examples/user_guide/Working_with_Bokeh.ipynb b/examples/user_guide/Working_with_Bokeh.ipynb index f74b9405..1441beb4 100644 --- a/examples/user_guide/Working_with_Bokeh.ipynb +++ b/examples/user_guide/Working_with_Bokeh.ipynb @@ -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')" ] }, { @@ -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": {}, diff --git a/geoviews/plotting/bokeh/__init__.py b/geoviews/plotting/bokeh/__init__.py index 6a2c16cb..c3147c64 100644 --- a/geoviews/plotting/bokeh/__init__.py +++ b/geoviews/plotting/bokeh/__init__.py @@ -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 @@ -60,6 +67,15 @@ class ImageStackPlot: ... +_TILE_MAX_ZOOM = { + OSM: 19, + ESRI: 19, + EsriImagery: 19, + EsriNatGeo: 16, + EsriWorldHillshade: 16, +} + + class TilePlot(GeoPlot): style_opts = [ @@ -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] diff --git a/geoviews/tests/plotting/bokeh/test_tiles.py b/geoviews/tests/plotting/bokeh/test_tiles.py index f2f56788..e0669eda 100644 --- a/geoviews/tests/plotting/bokeh/test_tiles.py +++ b/geoviews/tests/plotting/bokeh/test_tiles.py @@ -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): @@ -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