Skip to content

Commit

Permalink
Added attributions for tile sources
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed May 8, 2018
1 parent 5064448 commit 6fb2e52
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
11 changes: 9 additions & 2 deletions geoviews/plotting/bokeh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
HexTiles)
from ...operation import (project_image, project_shape, project_points,
project_path, project_graph, project_quadmesh)
from ...tile_sources import _ATTRIBUTIONS
from ...util import geom_to_array
from .plot import GeoPlot, OverlayPlot, DEFAULT_PROJ
from . import callbacks # noqa
Expand Down Expand Up @@ -50,8 +51,14 @@ def get_data(self, element, ranges, style):
elif all(kw in element.data for kw in ('{X}', '{Y}', '{Z}')):
tile_source = WMTSTileSource
else:
raise ValueError('Tile source URL format not recognized.')
return {}, {'tile_source': tile_source(url=element.data)}, style
raise ValueError('Tile source URL format not recognized. '
'Must contain {X}/{Y}/{Z}, {XMIN}/{XMAX}/{YMIN}/{YMAX} '
'or {Q} template strings.')
params = {'url': element.data}
for key, attribution in _ATTRIBUTIONS.items():
if all(k in element.data for k in key):
params['attribution'] = attribution
return {}, {'tile_source': tile_source(**params)}, style

def _update_glyph(self, renderer, properties, mapping, glyph):
allowed_properties = glyph.properties()
Expand Down
27 changes: 27 additions & 0 deletions geoviews/tile_sources.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
from .element import WMTS

# Mapping between patterns to match specified as tuples and tuples containing attributions
_ATTRIBUTIONS = {
('openstreetmap',) : (
'&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
),
('cartodb') : (
'&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors,'
'&copy; <a href="https://cartodb.com/attributions">CartoDB</a>'
),
('cartocdn') : (
'&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors,'
'&copy; <a href="https://cartodb.com/attributions">CartoDB</a>'
),
('stamen', 'terrain'): (
'Map tiles by <a href="https://stamen.com">Stamen Design</a>, '
'under <a href="https://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>. '
'Data by <a href="https://openstreetmap.org">OpenStreetMap</a>, '
'under <a href="https://creativecommons.org/licenses/by-sa/3.0">CC BY SA</a>.'
),
('stamen', 'toner'): (
'Map tiles by <a href="https://stamen.com">Stamen Design</a>, '
'under <a href="https://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>. '
'Data by <a href="https://openstreetmap.org">OpenStreetMap</a>, '
'under <a href="https://www.openstreetmap.org/copyright">ODbL</a>.'
)
}

# CartoDB basemaps
CartoDark = WMTS('https://cartodb-basemaps-4.global.ssl.fastly.net/dark_all/{Z}/{X}/{Y}.png')
CartoEco = WMTS('http://3.api.cartocdn.com/base-eco/{Z}/{X}/{Y}.png')
Expand Down

0 comments on commit 6fb2e52

Please sign in to comment.