Skip to content

Instantly share code, notes, and snippets.

@javierhonduco
Created July 6, 2014 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save javierhonduco/cfdac954f93d91566a40 to your computer and use it in GitHub Desktop.
Save javierhonduco/cfdac954f93d91566a40 to your computer and use it in GitHub Desktop.
import base64
from time import time
import TileStache
import ModestMaps
from klein import run, route
cfg = {
"cache": {
"name": "Redis",
"host": "localhost",
"port": 6379,
"db": 0,
"key prefix": "cdb-"
},
"layers": {
"example": {
"provider": {"name": "mapnik", "mapfile": "style.xml"},
"projection": "spherical mercator"
}
}
}
from contextlib import contextmanager
@contextmanager
def taim():
start = time()
yield
elapsed = time() - start
print elapsed
@route('/<a>/<b>/<c>', methods=['GET'])
def home(request, a, b, c):
lat, lon, zoom = map(float, [a, b, c])
coord = ModestMaps.Core.Coordinate(lat, lon, zoom)
config = TileStache.Config.buildConfiguration(cfg)
with taim() as duration:
type, bytes = TileStache.getTile(config.layers['example'], coord, 'png')
return '<img alt="Embedded Image" src="data:image/png;base64,%s"/>' % (base64.b64encode(bytes))
run("localhost", 8080)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment