migurski/TileStache — Issue #15: Impossible to implement a provider which may or may not render a metatile
Author: llimllib
Created: 2011-11-15 16:06:27+00:00
State: open

What I'd like to do is have a Provider which renders from an mbtiles file below a certain level, and renders an area with mapnik otherwise.

Under the current scheme, all requests to a given layer either do or do not return metatiles; my proposed provider would (optionally, according to config) provide a metatile when rendering from mapnik, but return a pre-rendered tile from an mbtile database otherwise.

Thus, I think that providers should tell Core whether or not they're returning a metatile, rather than Core handling that decision.

If you think this is a reasonable feature request, I'd be happy to implement it myself in the way that you think would be most reasonable, so please let me know. (We can discuss ways to implement this feature if you like it conceptually, I'm just asking here whether or not you think it's reasonable.)

My wholly untested code which sketches the type of provider I'm looking for:

from MBTiles import Provider as MBTilesProvider
from Providers import Mapnik as MapnikProvider

class MBCacheProvider:
def __init__(self, layer, max_mb_zoom, tileset, mapfile, fonts=None):
self.layer = layer
self.max_mb_zoom = max_mb_zoom
self.mbtileprovider = MBTilesProvider(self, layer, tileset)
self.mapnikprovider = MapnikProvider(self, layer, mapfile, fonts)

def renderTile(self, width, height, srs, coord):
if coord.zoom < max_mb_zoom:
return self.mbtileprovider.renderTile(width, height, srs, coord)
else:
xmin, ymin, xmax, ymax = self.layer.envelope(coord)

if self.layer.doMetatile():
xmin, ymin, xmax, ymax = self.layer.metaEnvelope(coord)
width, height = self.layer.metaSize(coord)

subtiles = self.layer.metaSubtiles(coord)

return self.mapnikprovider.renderArea(width, height, srs, xmin, ymin, xmax, ymax, coord.zoom)