Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extra toner styles #7

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 47 additions & 6 deletions ModestMaps/Stamen.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,31 @@

>>> p = TerrainProvider()
>>> p.getTileUrls(Coordinate(25322, 10507, 16)) #doctest: +ELLIPSIS
('http://tile.stamen.com/terrain/16/10507/25322.png',)
('http://tile.stamen.com/terrain/16/10507/25322.jpg',)

>>> p = WatercolorProvider()
>>> p.getTileUrls(Coordinate(25322, 10507, 16)) #doctest: +ELLIPSIS
('http://tile.stamen.com/watercolor/16/10507/25322.png',)
('http://tile.stamen.com/watercolor/16/10507/25322.jpg',)

>>> p = TonerHybridProvider()
>>> p.getTileUrls(Coordinate(25322, 10507, 16)) #doctest: +ELLIPSIS
('http://tile.stamen.com/toner-hybrid/16/10507/25322.png',)

>>> p = TonerLabelsProvider()
>>> p.getTileUrls(Coordinate(25322, 10507, 16)) #doctest: +ELLIPSIS
('http://tile.stamen.com/toner-labels/16/10507/25322.png',)

>>> p = TonerLinesProvider()
>>> p.getTileUrls(Coordinate(25322, 10507, 16)) #doctest: +ELLIPSIS
('http://tile.stamen.com/toner-lines/16/10507/25322.png',)

>>> p = TonerBackgroundProvider()
>>> p.getTileUrls(Coordinate(25322, 10507, 16)) #doctest: +ELLIPSIS
('http://tile.stamen.com/toner-background/16/10507/25322.png',)

>>> p = TonerLiteProvider()
>>> p.getTileUrls(Coordinate(25322, 10507, 16)) #doctest: +ELLIPSIS
('http://tile.stamen.com/toner-lite/16/10507/25322.png',)
"""

from math import pi
Expand All @@ -25,12 +45,13 @@
import random, Tiles

class BaseProvider(IMapProvider):
def __init__(self, style):
def __init__(self, style, tile_format='png'):
# the spherical mercator world tile covers (-π, -π) to (π, π)
t = deriveTransformation(-pi, pi, 0, 0, pi, pi, 1, 0, -pi, -pi, 0, 1)
self.projection = MercatorProjection(0, t)

self.style = style
self.tile_format = tile_format

def tileWidth(self):
return 256
Expand All @@ -40,19 +61,39 @@ def tileHeight(self):

def getTileUrls(self, coordinate):
zoom, column, row = coordinate.zoom, coordinate.column, coordinate.row
return ('http://tile.stamen.com/%s/%d/%d/%d.png' % (self.style, zoom, column, row),)
return ('http://tile.stamen.com/%s/%d/%d/%d.%s' % (self.style, zoom, column, row, self.tile_format),)

class TonerProvider(BaseProvider):
def __init__(self):
BaseProvider.__init__(self, 'toner')

class TerrainProvider(BaseProvider):
def __init__(self):
BaseProvider.__init__(self, 'terrain')
BaseProvider.__init__(self, 'terrain', 'jpg')

class WatercolorProvider(BaseProvider):
def __init__(self):
BaseProvider.__init__(self, 'watercolor')
BaseProvider.__init__(self, 'watercolor', 'jpg')

class TonerHybridProvider(BaseProvider):
def __init__(self):
BaseProvider.__init__(self, 'toner-hybrid', 'png')

class TonerLabelsProvider(BaseProvider):
def __init__(self):
BaseProvider.__init__(self, 'toner-labels', 'png')

class TonerLinesProvider(BaseProvider):
def __init__(self):
BaseProvider.__init__(self, 'toner-lines', 'png')

class TonerBackgroundProvider(BaseProvider):
def __init__(self):
BaseProvider.__init__(self, 'toner-background', 'png')

class TonerLiteProvider(BaseProvider):
def __init__(self):
BaseProvider.__init__(self, 'toner-lite', 'png')

if __name__ == '__main__':
import doctest
Expand Down