Source code for holoviews.plotting.bokeh.tiles

import numpy as np
from bokeh.models import BBoxTileSource, QUADKEYTileSource, WMTSTileSource

from ...core.options import SkipRendering
from ...element.tiles import _ATTRIBUTIONS
from .element import ElementPlot

[docs]class TilePlot(ElementPlot): style_opts = ['alpha', 'render_parents', 'level', 'smoothing', 'min_zoom', 'max_zoom'] selection_display = None
[docs] def get_extents(self, element, ranges, range_type='combined', **kwargs): extents = super().get_extents(element, ranges, range_type) if (not self.overlaid and all(e is None or not np.isfinite(e) for e in extents) and range_type in ('combined', 'data')): x0, x1 = (-20037508.342789244, 20037508.342789244) y0, y1 = (-20037508.342789255, 20037508.342789244) global_extent = (x0, y0, x1, y1) return global_extent return extents
[docs] def get_data(self, element, ranges, style): if not isinstance(, (str, dict)): SkipRendering("WMTS element data must be a URL string, dictionary, or " "xyzservices.TileProvider, bokeh cannot " "render %r" % if is None: raise ValueError("Tile source URL may not be None with the bokeh backend") elif isinstance(, dict): tile_source = WMTSTileSource elif '{Q}' in tile_source = QUADKEYTileSource elif all(kw in for kw in ('{XMIN}', '{XMAX}', '{YMIN}', '{YMAX}')): tile_source = BBoxTileSource elif all(kw in for kw in ('{X}', '{Y}', '{Z}')): tile_source = WMTSTileSource else: raise ValueError('Tile source URL format not recognized. ' 'Must contain {X}/{Y}/{Z}, {XMIN}/{XMAX}/{YMIN}/{YMAX} ' 'or {Q} template strings.') if isinstance(, dict): params = { 'url':"@2x"), 'min_zoom':"min_zoom", 0), 'max_zoom':"max_zoom", 20), 'attribution':} else: params = {'url':} for zoom in ('min_zoom', 'max_zoom'): if zoom in style: params[zoom] = style[zoom] for key, attribution in _ATTRIBUTIONS.items(): if all(k in for k in key): params['attribution'] = attribution return {}, {'tile_source': tile_source(**params)}, style
def _update_glyph(self, renderer, properties, mapping, glyph, source=None, data=None): glyph.url = mapping['tile_source'].url glyph.update(**{k: v for k, v in properties.items() if k in}) renderer.update(**{k: v for k, v in properties.items() if k in}) def _init_glyph(self, plot, mapping, properties): """ Returns a Bokeh glyph object. """ tile_source = mapping['tile_source'] level = properties.pop('level', 'glyph') renderer = plot.add_tile(tile_source, level=level) renderer.alpha = properties.get('alpha', 1) return renderer, tile_source