Created
July 6, 2014 20:38
-
-
Save javierhonduco/cfdac954f93d91566a40 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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