Created
May 20, 2014 13:51
-
-
Save ingenieroariel/a86f42608df51c583996 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from django.conf import settings | |
from django.http import HttpResponse | |
from geonode.layers.views import _resolve_layer, _PERMISSION_MSG_VIEW | |
import TileStache | |
import json | |
def get_config(layer): | |
if 'datastore' not in settings.DATABASES: | |
raise Exception() | |
config_dict = { | |
"layers":{ | |
layer.name:{ | |
"provider": { | |
"class": "TileStache.Goodies.VecTiles:Provider", | |
"kwargs":{ | |
"clip": False, | |
"dbinfo": { | |
"user": settings.DATABASES['datastore']['USER'], | |
"password": settings.DATABASES['datastore']['PASSWORD'], | |
"database": settings.DATABASES['datastore']['NAME'] | |
}, | |
"queries": [ | |
"SELECT *, id as __id__, ST_SetSRID(geom, 900913) as __geometry__ FROM %s" % layer.name | |
] | |
} | |
} | |
} | |
}, | |
"cache":{ | |
"name": "Disk", | |
"path": "file://%s/tiles/" % settings.MEDIA_ROOT | |
} | |
} | |
config = TileStache.Config.buildConfiguration(config_dict) | |
return config.layers[layer.name] | |
def tiles(request, layer_name, z, x, y, extension): | |
""" | |
Proxy to tilestache | |
{X} - coordinate column. | |
{Y} - coordinate row. | |
{B} - bounding box. | |
{Z} - zoom level. | |
{S} - host. | |
""" | |
layer = _resolve_layer(request, layer_name, 'layers.view_layer', _PERMISSION_MSG_VIEW) | |
path_info = "%s/%s/%s/%s.%s" % (layer_name, z, x, y, extension) | |
coord, extension = TileStache.splitPathInfo(path_info)[1:] | |
mimetype, content = TileStache.getTile(get_config(layer), coord, extension) | |
return HttpResponse(content, mimetype=mimetype) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment