Skip to content
Closed
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
8 changes: 7 additions & 1 deletion TileStache/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ def __init__(self, cache, dirpath):
self.dirpath = dirpath
self.layers = {}

# adding custom_layer to extend multiprovider to support comma separated layernames
self.custom_layer_name = ","
self.custom_layer_dict = {'provider': {'class': 'TileStache.Goodies.VecTiles:MultiProvider', 'kwargs': {'names': []}}}

self.index = 'text/plain', 'TileStache bellows hello.'

class Bounds:
Expand Down Expand Up @@ -204,7 +208,7 @@ def buildConfiguration(config_dict, dirpath='.'):
URL including the "file://" prefix.
"""
scheme, h, path, p, q, f = urlparse(dirpath)

if scheme in ('', 'file'):
sys.path.insert(0, path)

Expand All @@ -216,6 +220,8 @@ def buildConfiguration(config_dict, dirpath='.'):
for (name, layer_dict) in config_dict.get('layers', {}).items():
config.layers[name] = _parseConfigfileLayer(layer_dict, config, dirpath)

config.layers[config.custom_layer_name] = _parseConfigfileLayer(config.custom_layer_dict, config, dirpath)

if 'index' in config_dict:
index_href = urljoin(dirpath, config_dict['index'])
index_body = urlopen(index_href).read()
Expand Down
6 changes: 5 additions & 1 deletion TileStache/Goodies/VecTiles/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,11 @@ class MultiProvider:
def __init__(self, layer, names):
self.layer = layer
self.names = names


def __call__(self, layer, names):
self.layer = layer
self.names = names

def renderTile(self, width, height, srs, coord):
''' Render a single tile, return a Response instance.
'''
Expand Down
27 changes: 25 additions & 2 deletions TileStache/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
_pathinfo_pat = re.compile(r'^/?(?P<l>\w.+)/(?P<z>\d+)/(?P<x>-?\d+)/(?P<y>-?\d+)\.(?P<e>\w+)$')
_preview_pat = re.compile(r'^/?(?P<l>\w.+)/(preview\.html)?$')

# symbol used to separate layers when specifying more than one layer
_delimiter = ','

def getTile(layer, coord, extension, ignore_cached=False):
''' Get a type string and tile binary for a given request layer tile.

Expand Down Expand Up @@ -138,6 +141,19 @@ def mergePathInfo(layer, coord, extension):

return '/%(layer)s/%(z)d/%(x)d/%(y)d.%(extension)s' % locals()

def isValidLayer(layer, config):
if not layer:
return False
if (layer not in config.layers):
if (layer.find(_delimiter) != -1):
multi_providers = list(ll for ll in config.layers if hasattr(config.layers[ll].provider, 'names'))
for l in layer.split(_delimiter):
if ((l not in config.layers) or (l in multi_providers)):
return False
return True
return False
return True

def requestLayer(config, path_info):
""" Return a Layer.

Expand Down Expand Up @@ -175,9 +191,16 @@ def requestLayer(config, path_info):

layername = splitPathInfo(path_info)[0]

if layername not in config.layers:
if not isValidLayer(layername, config):
raise Core.KnownUnknown('"%s" is not a layer I know about. Here are some that I do know about: %s.' % (layername, ', '.join(sorted(config.layers.keys()))))

custom_layer = layername.find(_delimiter)!=-1

if custom_layer:
config.layers[layername] = config.layers[config.custom_layer_name]
config.layers[layername].provider(config.layers[layername], **{'names': layername.split(_delimiter)})
del config.layers[config.custom_layer_name]

return config.layers[layername]

def requestHandler(config_hint, path_info, query_string=None):
Expand Down Expand Up @@ -369,7 +392,7 @@ def __call__(self, environ, start_response):
# WSGI behavior is different from CGI behavior, because we may not want
# to return a chatty rummy for likely-deployed WSGI vs. testing CGI.
#
if layer and layer not in self.config.layers:
if not isValidLayer(layer, self.config):
return self._response(start_response, 404)

path_info = environ.get('PATH_INFO', None)
Expand Down