Skip to content

Commit

Permalink
Merge pull request #2202 from lgolston/stamen-tiles
Browse files Browse the repository at this point in the history
Preset Stamen tile file extension, opacity
  • Loading branch information
dopplershift authored Jun 29, 2023
2 parents 3e2bc86 + 44657a3 commit 97b0675
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions lib/cartopy/io/img_tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,14 +350,44 @@ class Stamen(GoogleWTS):
"""

def __init__(self, style='toner',
desired_tile_form='RGB', cache=False):
desired_tile_form=None, cache=False):

# preset layer configuration
layer_config = {
'terrain': {'extension': 'png', 'opaque': True},
'terrain-background': {'extension': 'png', 'opaque': True},
'terrain-labels': {'extension': 'png', 'opaque': False},
'terrain-lines': {'extension': 'png', 'opaque': False},
'toner-background': {'extension': 'png', 'opaque': True},
'toner': {'extension': 'png', 'opaque': True},
'toner-hybrid': {'extension': 'png', 'opaque': False},
'toner-labels': {'extension': 'png', 'opaque': False},
'toner-lines': {'extension': 'png', 'opaque': False},
'toner-lite': {'extension': 'png', 'opaque': True},
'watercolor': {'extension': 'jpg', 'opaque': True},
}

# get layer information from dict
layer_info = layer_config.get(
style, {'extension': '.png', 'opaque': True})

# use optional desired_tile_form input if available
# otherwise, use preset value based on the layer name
if desired_tile_form is None:
if layer_info['opaque']:
desired_tile_form = 'RGB'
else:
desired_tile_form = 'RGBA'

super().__init__(desired_tile_form=desired_tile_form,
cache=cache)
self.style = style
self.extension = layer_info['extension']

def _image_url(self, tile):
x, y, z = tile
return f'http://tile.stamen.com/{self.style}/{z}/{x}/{y}.png'
return 'http://tile.stamen.com/' + \
f'{self.style}/{z}/{x}/{y}.{self.extension}'


class MapboxTiles(GoogleWTS):
Expand Down

0 comments on commit 97b0675

Please sign in to comment.