def tiles(request, service_slug, z, x, y, extension): """ Proxy to tilestache {X} - coordinate column. {Y} - coordinate row. {B} - bounding box. {Z} - zoom level. {S} - host. """ service = TileService.objects.get(slug=service_slug) config = { "cache": {"name": "Test"}, "layers": {} } config["layers"][service_slug]={ "provider": { 'name': 'mapnik', "mapfile": service.mapfile } } config = TileStache.Config.buildConfiguration(config) path_info = "%s/%s/%s/%s.%s" % (service_slug, z, x, y, extension) coord, extension = TileStache.splitPathInfo(path_info)[1:] mimetype, content = TileStache.getTile(config.layers[service_slug], coord, extension) return HttpResponse(content, mimetype=mimetype)
def get(self, request, layer_name, z, x, y, extension): """ Fetch tiles with tilestache. """ # try: print("==GETTING TILES== {0}".format(layer_name)) extension = extension.upper() config = get_tilestache_config() path_info = "%s/%s/%s/%s.%s" % (layer_name, z, x, y, extension) coord, extension = TileStache.splitPathInfo(path_info)[1:] try: tilestache_layer = config.layers[layer_name] except: return Response({'status': 'layer not found'}, status=status.HTTP_404_NOT_FOUND) status_code, headers, content = tilestache_layer.getTileResponse( coord, extension) mimetype = headers.get('Content-Type') if len(content) == 0: status_code = 404 response = HttpResponse( content, **{ 'content_type': mimetype, 'status': status_code }) if hasattr(tilestache_layer, 'allowed origin'): response['Access-Control-Allow-Origin'] = tilestache_layer.get( 'allowed origin') return response
def tiles(request, layer_name, z, x, y, extension, custom_tile=None): """ Fetch tiles with tilestache. """ metatile = TileStache.Core.Metatile() if custom_tile: config = get_config(custom_tile=custom_tile) else: config = get_config() path_info = "%s/%s/%s/%s.%s" % (layer_name, z, x, y, extension) coord, extension = TileStache.splitPathInfo(path_info)[1:] try: tilestacheLayer = config.layers[layer_name] except: return HttpResponseNotFound() status_code, headers, content = tilestacheLayer.getTileResponse(coord, extension) mimetype = headers.get('Content-Type') if len(content) == 0: status_code = 404 response = HttpResponse(content, content_type=mimetype, status=status_code) response['Access-Control-Allow-Origin'] = '*' return response
def tilestache(request, layer_name, z, x, y, extension): """ Proxy to tilestache {X} - coordinate column. {Y} - coordinate row. {B} - bounding box. {Z} - zoom level. {S} - host. """ config = get_config() path_info = "%s/%s/%s/%s.%s" % (layer_name, z, x, y, extension) coord, extension = TileStache.splitPathInfo(path_info)[1:] mimetype, content = TileStache.getTile(config.layers[layer_name], coord, extension) return HttpResponse(content, mimetype=mimetype)
def application(environ, start_response): config = environ["TILESTACHE_CONFIG"] layer, coord, ext = TileStache.splitPathInfo(environ["PATH_INFO"]) if not config.layers.get(layer, False): print >>environ["wsgi.errors"], "[gunistache] unknown layer: " + layer status = "404 NOT FOUND" data = "" else: try: content_type, data = TileStache.handleRequest(config.layers[layer], coord, ext) status = "200 OK" except Exception, e: print >>environ["wsgi.errors"], "[gunistache] failed to handle request:" + str(e) status = "500 SERVER ERROR" data = str(e)
def get(self, request, layer_name, z, x, y, extension): """ Fetch tiles with tilestache. """ try: extension = extension.upper() config = get_config().config path_info = "{}/{}/{}/{}.{}".format(layer_name, z, x, y, extension) coord, extension = TileStache.splitPathInfo(path_info)[1:] try: tilestache_layer = config.layers[layer_name] except: return Response({'status': 'layer not found'}, status=status.HTTP_404_NOT_FOUND) status_code, headers, content = tilestache_layer.getTileResponse(coord, extension) mimetype = headers.get('Content-Type') if len(content) == 0: status_code = 404 response = HttpResponse( content, **{ 'content_type': mimetype, 'status': status_code } ) if hasattr(tilestache_layer, 'allowed origin'): response['Access-Control-Allow-Origin'] = tilestache_layer.get('allowed origin') return response except Exception as ex: return Response( { 'status': 'error', 'message': str(ex) }, status=status.HTTP_404_NOT_FOUND )
def tilestache_tiles(request, layer_name, z, x, y, extension): """ :param request: :param layer_name: :param z: :param x: :param y: :param extension: :return: Proxy to tilestache {X} - coordinate column. {Y} - coordinate row. {B} - bounding box. {Z} - zoom level. {S} - host. """ config = TileStacheConfig.objects.filter(name='default')[0].config path_info = "%s/%s/%s/%s.%s" % (layer_name, z, x, y, extension) coord, extension = TileStache.splitPathInfo(path_info)[1:] mimetype, content = TileStache.getTile(config.layers[layer_name], coord, extension) return HttpResponse(content, mimetype=mimetype)
def tiles(request, service_slug, z, x, y, extension): """ Proxy to tilestache {X} - coordinate column. {Y} - coordinate row. {B} - bounding box. {Z} - zoom level. {S} - host. """ service = TileService.objects.get(slug=service_slug) config = {"cache": {"name": "Test"}, "layers": {}} config["layers"][service_slug] = { "provider": { 'name': 'mapnik', "mapfile": service.mapfile } } config = TileStache.Config.buildConfiguration(config) path_info = "%s/%s/%s/%s.%s" % (service_slug, z, x, y, extension) coord, extension = TileStache.splitPathInfo(path_info)[1:] mimetype, content = TileStache.getTile(config.layers[service_slug], coord, extension) return HttpResponse(content, mimetype=mimetype)