Skip to content
Open
Show file tree
Hide file tree
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
24 changes: 17 additions & 7 deletions ModestMaps/Providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class IMapProvider:
def __init__(self):
raise NotImplementedError("Abstract method not implemented by subclass.")

def getTileUrls(self, coordinate):
raise NotImplementedError("Abstract method not implemented by subclass.")

Expand All @@ -39,24 +39,25 @@ def sourceCoordinate(self, coordinate):

while wrappedColumn < 0:
wrappedColumn += pow(2, coordinate.zoom)

return Coordinate(coordinate.row, wrappedColumn, coordinate.zoom)

class TemplatedMercatorProvider(IMapProvider):
""" Convert URI templates into tile URLs, using a tileUrlTemplate identical to:
http://code.google.com/apis/maps/documentation/overlays.html#Custom_Map_Types
"""
def __init__(self, template):
def __init__(self, template, tilestache_cached=False):
# 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.templates = []

self.tilestache_cached = tilestache_cached

while template:
match = re.match(r'^(http://\S+?)(,http://\S+)?$', template)
match = re.match(r'^(https?://\S+?)(,http://\S+)?$', template)
first = match.group(1)

if match:
self.templates.append(first)
template = template[len(first):].lstrip(',')
Expand All @@ -70,5 +71,14 @@ def tileHeight(self):
return 256

def getTileUrls(self, coordinate):

x, y, z = str(int(coordinate.column)), str(int(coordinate.row)), str(int(coordinate.zoom))

if self.tilestache_cached:
x = "%0d6" % int(x)
y = "%0d6" % int(y)

x = "%s/%s" % (x[:3], x[3:])
y = "%s/%s" % (y[:3], y[3:])

return [t.replace('{X}', x).replace('{Y}', y).replace('{Z}', z) for t in self.templates]
Loading