當前位置: 首頁>>代碼示例>>Python>>正文


Python TileStache.requestHandler方法代碼示例

本文整理匯總了Python中TileStache.requestHandler方法的典型用法代碼示例。如果您正苦於以下問題:Python TileStache.requestHandler方法的具體用法?Python TileStache.requestHandler怎麽用?Python TileStache.requestHandler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在TileStache的用法示例。


在下文中一共展示了TileStache.requestHandler方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: tileMap

# 需要導入模塊: import TileStache [as 別名]
# 或者: from TileStache import requestHandler [as 別名]
def tileMap(request, version, map_id, zoom, x, y):
    try:
        if version != "1.0":
            raise Http404
        try:
            basqui_map = BasquiMap.objects.get(id=map_id)
            layersMapOptions = LayerMapOptions.objects.filter(basqui_map=basqui_map, visible=True).order_by('-position')
        except Shapefile.DoesNotExist or Feature.DoesNotExist:
            raise Http404
        zoom = int(zoom)
        x = int(x)
        y = int(y)
        if zoom < 0 or zoom > MAX_ZOOM_LEVEL:
            raise Http404
        xExtent = _unitsPerPixel(zoom)
        yExtent = _unitsPerPixel(zoom)
        minLong = x * xExtent - 20037508.34
        minLat = y * yExtent - 20037508.34
        maxLong = minLong + xExtent
        maxLat = minLat + yExtent
        if (minLong < -20037508.34 or maxLong > 20037508.34 or minLat < -20037508.34 or maxLat > 20037508.34):
            raise Http404

        if basqui_map.changed:
            xml_map_config(request, zoom, x, y, basqui_map, layersMapOptions)

        config = {
          "cache": {
            "name": "test",
            "path": "../tilestache/%s" % (request.user),
            "umask": "0000",
            "dirs": "portable"},
          "layers": {
            basqui_map.map_name: {
                "provider": {"name": "mapnik", "mapfile": "../tilestache/%s/%s.xml" % (request.user, basqui_map.map_name)},
                "projection": "spherical mercator"
            }
          }
        }

        path = "/%s/%s/%s/%s.png" % (basqui_map.map_name,zoom,x,y)
        config = TileStache.Config.buildConfiguration(config)
        type, bytes = TileStache.requestHandler(config, path)
        return HttpResponse(bytes, mimetype="image/png")

    except:
        traceback.print_exc()
        return HttpResponse("")
開發者ID:DemersM,項目名稱:Basqui,代碼行數:50,代碼來源:tms+-+geodjango_plugin.py

示例2: tileMap

# 需要導入模塊: import TileStache [as 別名]
# 或者: from TileStache import requestHandler [as 別名]
def tileMap(request, map_id, zoom, x, y):
    try:
        try:
            basqui_map = BasquiMap.objects.get(id=map_id, created_by=request.user)
        except Shapefile.DoesNotExist or Feature.DoesNotExist:
            raise Http404
        zoom = int(zoom)
        x = int(x)
        y = int(y)
        if zoom < 0 or zoom > MAX_ZOOM_LEVEL:
            raise Http404
        xExtent = _unitsPerPixel(zoom)
        yExtent = _unitsPerPixel(zoom)
        minLong = x * xExtent - 20037508.34
        minLat = y * yExtent - 20037508.34
        maxLong = minLong + xExtent
        maxLat = minLat + yExtent
        if (minLong < -20037508.34 or maxLong > 20037508.34 or minLat < -20037508.34 or maxLat > 20037508.34):
            raise Http404

        map_name = "%s_%s" % (basqui_map.name, basqui_map.pk)
        config = {
          "cache": {
            "name": "test",
            "path": "../tilestache/%s/cache/" % (request.user),
            "umask": "0000",
            "dirs": "portable"},
          "layers": {
            map_name: {
                "provider": {"name": "mapnik", "mapfile": "../tilestache/%s/maps/viewer/%s.xml" % (request.user, map_name)},
                "metatile":    {
                                  "rows": 2,
                                  "columns": 2,
                                  "buffer": 64
                                },
                "projection": "spherical mercator",
            }
          }
        }

        path = "/%s/%s/%s/%s.png" % (map_name,zoom,x,y)
        config = TileStache.Config.buildConfiguration(config)
        type, bytes = TileStache.requestHandler(config, path)
        return HttpResponse(bytes, content_type="image/png")

    except:
        traceback.print_exc()
        return HttpResponse("")
開發者ID:DemersM,項目名稱:Basqui,代碼行數:50,代碼來源:tms.py

示例3: scenario_tile

# 需要導入模塊: import TileStache [as 別名]
# 或者: from TileStache import requestHandler [as 別名]
def scenario_tile(request, instance):

    path_info = "/" + instance.uid + "_tiles" + request.GET.get('tile')

    if not path_info:
        return HttpResponse("Must supply tile GET paramater", status=400)
    if not _pathinfo_pat.match(path_info or ''):
        return HttpResponse('Bad path: "%s"; Expecting something like "/example/0/0/0.png"' % path_info, status=400)

    thisdir = os.path.dirname(os.path.abspath(__file__))
    dirpath = os.path.realpath(os.path.join(thisdir, '..', '..', 'tile_config'))

    xml_path = instance.mapnik_xml()

    config_dict = {
      "layers": {
        instance.uid + "_tiles": {
          # "metatile": {
          #   "buffer": 64, 
          #   "rows": 4, 
          #   "columns": 4
          # }, 
          "provider": {
            "name": "mapnik", 
            "mapfile": xml_path
          }
        }, 
      }, 
      "cache": {
        "host": "localhost", 
        "name": "Redis", 
        "db": settings.APP_REDIS_DB,
        "port": 6379
      }, 
      # "cache": {
      #   "name": "test", 
      # }, 
      "logging": "warning"
    }
    config = TileStache.Config.buildConfiguration(config_dict, dirpath)

    (mimestr, bytestotal) = TileStache.requestHandler(
        config_hint=config, path_info=path_info, query_string=None)

    return HttpResponse(bytestotal, content_type=mimestr)
開發者ID:Ecotrust,項目名稱:cogs-priorities,代碼行數:47,代碼來源:views.py

示例4: tiles

# 需要導入模塊: import TileStache [as 別名]
# 或者: from TileStache import requestHandler [as 別名]
def tiles(request):
    path_info = request.path_info.replace('/tiles', '')
    (mimestr, bytestotal) = TileStache.requestHandler(config_hint=settings.TILE_CONFIG, 
            path_info=path_info, query_string=None)
    return HttpResponse(bytestotal, content_type=mimestr)
開發者ID:Ecotrust,項目名稱:nplcc,代碼行數:7,代碼來源:views.py

示例5: tileLayer

# 需要導入模塊: import TileStache [as 別名]
# 或者: from TileStache import requestHandler [as 別名]

#.........這裏部分代碼省略.........
        y = int(y)
        if zoom < 0 or zoom > MAX_ZOOM_LEVEL:
            raise Http404
        xExtent = _unitsPerPixel(zoom)
        yExtent = _unitsPerPixel(zoom)
        minLong = x * xExtent - 20037508.34
        minLat = y * yExtent - 20037508.34
        maxLong = minLong + xExtent
        maxLat = minLat + yExtent
        if (minLong < -20037508.34 or maxLong > 20037508.34 or minLat < -20037508.34 or maxLat > 20037508.34):
            raise Http404

        #create de mapnik.map object
        map = mapnik.Map(TILE_WIDTH, TILE_HEIGHT, "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m [email protected] +no_defs +over")
        map.background = mapnik.Color("#f2f3f7")
        #defining the feature layer
        geometryField = utils.calcGeometryField(shapefile.geom_type)
        field = "'NOM'"
        field2 = "'CODE'"
        query = '(select ' + geometryField + ', attribute_value->' + field +' as label, id_relat from "shapefile_feature" where' + ' shapefile_id in (' + str(shapefile.id) + ')) as geom'

        feature = Feature.objects.filter(shapefile__id=shapefile_id).geojson()
        adapter = DjLayer(feature)
        lyr = adapter.to_mapnik()
        lyr.srs = "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m [email protected] +no_defs +over"
        m = mapnik.Map(TILE_WIDTH, TILE_HEIGHT, "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m [email protected] +no_defs +over")




##        datasource = mapnik.PostGIS(user=dbSettings['USER'],
##                        password=dbSettings['PASSWORD'],
##                        dbname=dbSettings['NAME'],
##                        port=5433,
##                        table=query,
##                        srid=3857,
##                        geometry_field=geometryField,
##                        simplify_geometries=True,
##                        geometry_table='"shapefile_feature"')

##        featureLayer = mapnik.Layer("featureLayer")
##        featureLayer.srs = "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m [email protected] +no_defs +over"
##        featureLayer.datasource = datasource
##        featureLayer.styles.append("featureLayerStyle")
##
        #defining the feature layer styles
        rule = mapnik.Rule()
        if shapefile.geom_type in ["Point", "MultiPoint"]:
            rule.symbols.append(mapnik.PointSymbolizer())
        elif shapefile.geom_type in ["LineString", "MultiLineString"]:
            rule.symbols.append(mapnik.LineSymbolizer(mapnik.Color("#000000"), 0.5))
        elif shapefile.geom_type in ["Polygon", "MultiPolygon"]:
            rule.symbols.append(mapnik.PolygonSymbolizer(mapnik.Color("#f7edee")))
            rule.symbols.append(mapnik.LineSymbolizer(mapnik.Color("#000000"), 0.5))
##
##        label = mapnik.TextSymbolizer(mapnik.Expression('[label]'), 'DejaVu Sans Book', 10, mapnik.Color('black'))
##        label.halo_fill = mapnik.Color('white')
##        label.halo_radius = 4
##        label.label_placement = mapnik.label_placement.INTERIOR_PLACEMENT
##        label.allow_overlap = True
##        label.avoid_edges = True
##        rule.symbols.append(label)
        style = mapnik.Style()
        style.rules.append(rule)
        lyr.styles.append('name')

##
##        #add new feature to the map
        m.append_style("name", style)
        m.layers.append(lyr)
##        map.layers.append(featureLayer)

        #rendering the map tile
        mapnik.save_map(m, "../tilestache/%s/%s.xml" % (str(request.user), str(shapefile.filename)))

        config = {
          "cache": {
            "name": "Disk",
            "path": "../tilestache/%s" % (request.user),
            "umask": "0000",
            "dirs": "portable"},
          "layers": {
            shapefile.filename: {
                "provider": {"name": "mapnik", "mapfile": "../tilestache/%s/%s.xml" % (request.user, shapefile.filename)},
                "projection": "spherical mercator"
            }
          }
        }

        # like http://tile.openstreetmap.org/1/0/0.png
        #coord = ModestMaps.Core.Coordinate(y, x, zoom)
        path = "/%s/%s/%s/%s.png" % (shapefile.filename,zoom,x,y)
        config = TileStache.Config.buildConfiguration(config)
        #type, bytes = TileStache.getTile(config.layers[shapefile.filename], coord, 'png')
        type, bytes = TileStache.requestHandler(config, path)
        return HttpResponse(bytes, mimetype="image/png")

    except:
        traceback.print_exc()
        return HttpResponse("")
開發者ID:DemersM,項目名稱:Basqui,代碼行數:104,代碼來源:tms+-+geodjango_plugin.py

示例6: tileFeature

# 需要導入模塊: import TileStache [as 別名]
# 或者: from TileStache import requestHandler [as 別名]
def tileFeature(request, version, shapefile_id, feature_id, zoom, x, y):
    try:
        if version != "1.0":
            raise Http404
        try:
            shapefile = Shapefile.objects.get(id=shapefile_id, created_by=request.user)
        except Shapefile.DoesNotExist:
            raise Http404
        zoom = int(zoom)
        x = int(x)
        y = int(y)
        if zoom < 0 or zoom > MAX_ZOOM_LEVEL:
            raise Http404
        xExtent = _unitsPerPixel(zoom)
        yExtent = _unitsPerPixel(zoom)
        minLong = x * xExtent - 20037508.34
        minLat = y * yExtent - 20037508.34
        maxLong = minLong + xExtent
        maxLat = minLat + yExtent
        if (minLong < -20037508.34 or maxLong > 20037508.34 or minLat < -20037508.34 or maxLat > 20037508.34):
            raise Http404

        #create de mapnik.map object
        map = mapnik.Map(TILE_WIDTH, TILE_HEIGHT, "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m [email protected] +no_defs +over")
        map.background = mapnik.Color("#fff")
        #defining the feature layer
        geometryField = utils.calcGeometryField(shapefile.geom_type)
        query = '(select ' + geometryField +', id, id_relat as label from "layers_feature" WHERE shapefile_id = ' + str(shapefile.id) + ' AND id = ' + str(feature_id) + ') as geom'

        datasource = mapnik.PostGIS(user=dbSettings['USER'],
                        password=dbSettings['PASSWORD'],
                        dbname=dbSettings['NAME'],
                        port=dbSettings['PORT'],
                        table=query,
                        srid=3857,
                        geometry_field=geometryField,
                        simplify_geometries=True,
                        geometry_table='"layers_feature"')

        featureLayer = mapnik.Layer("featureLayer")
        featureLayer.srs = "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m [email protected] +no_defs +over"
        featureLayer.datasource = datasource
        featureLayer.styles.append("featureLayerStyle")

        #defining the feature layer styles
        rule = mapnik.Rule()
        if shapefile.geom_type in ["Point", "3D Point", "MultiPoint", "3D MultiPoint"]:
            rule.symbols.append(mapnik.PointSymbolizer())
        elif shapefile.geom_type in ["LineString", "3D LineString", "MultiLineString", "3D MultiLineString"]:
            rule.symbols.append(mapnik.LineSymbolizer(mapnik.Color("#000000"), 0.5))
        elif shapefile.geom_type in ["Polygon", "3D Polygon", "MultiPolygon", "3D MultiPolygon"]:
            rule.symbols.append(mapnik.PolygonSymbolizer(mapnik.Color("#f7edee")))
            rule.symbols.append(mapnik.LineSymbolizer(mapnik.Color("#000000"), 0.5))
        style = mapnik.Style()
        style.rules.append(rule)
        map.append_style("featureLayerStyle", style)

        label_rule = mapnik.Rule()
        label = mapnik.TextSymbolizer(mapnik.Expression('[label]'), 'DejaVu Sans Book', 10, mapnik.Color('black'))
        label.halo_radius = 4
        label.allow_overlap = False
        label.avoid_edges = True
        label_rule.symbols.append(label)
        label_style = mapnik.Style()
        label_style.rules.append(label_rule)
        featureLayer.styles.append("featureLayerStyle_label")
        #add label to the map
        map.append_style("featureLayerStyle_label", label_style)


        #add new feature to the map
        map.layers.append(featureLayer)

        #rendering the map tile
        mapnik_xml_path = "../tilestache/%s/layers/vector/lightViewer/%s.xml" % (str(request.user), str(shapefile.name))
        mapnik.save_map(map, mapnik_xml_path)

        config = {
          "cache": {
            "name": "Test",
            "path": "../tilestache/%s" % (request.user),
            "umask": "0000",
            "dirs": "portable"},
          "layers": {
            shapefile.name: {
                "provider": {"name": "mapnik", "mapfile": mapnik_xml_path},
                "metatile":    {
                  "rows": 2,
                  "columns": 2,
                  "buffer": 64
                },
                "projection": "spherical mercator",
                "write cache": False
            }
          }
        }

        path = "/%s/%s/%s/%s.png" % (shapefile.name,zoom,x,y)
        config = TileStache.Config.buildConfiguration(config)
        type, bytes = TileStache.requestHandler(config, path)
#.........這裏部分代碼省略.........
開發者ID:DemersM,項目名稱:Basqui,代碼行數:103,代碼來源:tms+-+Copie.py

示例7: tileRaster

# 需要導入模塊: import TileStache [as 別名]
# 或者: from TileStache import requestHandler [as 別名]
def tileRaster(request, version, zoom, x, y):
    try:
        if version != "1.0":
            raise Http404
        zoom = int(zoom)
        x = int(x)
        y = int(y)
        if zoom < 0 or zoom > MAX_ZOOM_LEVEL:
            raise Http404
        xExtent = _unitsPerPixel(zoom)
        yExtent = _unitsPerPixel(zoom)
        minLong = x * xExtent - 20037508.34
        minLat = y * yExtent - 20037508.34
        maxLong = minLong + xExtent
        maxLat = minLat + yExtent
        if (minLong < -20037508.34 or maxLong > 20037508.34 or minLat < -20037508.34 or maxLat > 20037508.34):
            raise Http404

        #create de mapnik.map object
        map = mapnik.Map(TILE_WIDTH, TILE_HEIGHT, "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m [email protected] +no_defs +over")
        #defining the feature layer

        datasource = mapnik.Gdal(file="bar_harbour.dem",
                    base="C:\\Temp\\dem\\",
                    band=1)

        featureLayer = mapnik.Layer("RasterLayer")
        featureLayer.srs = "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m [email protected] +no_defs +over"
        featureLayer.datasource = datasource
        featureLayer.styles.append("RasterLayerStyle")

        #defining the feature layer styles
        rule = mapnik.Rule()
        rule.symbols.append(mapnik.RasterSymbolizer())
        style = mapnik.Style()
        style.rules.append(rule)

        #add new feature to the map
        map.append_style("RasterLayerStyle", style)
        map.layers.append(featureLayer)

        #rendering the map tile
        #mapnik.save_map(map, "../tilestache/%s/raster.xml" % str(request.user))

        config = {
          "cache": {
            "name": "Test",
            "path": "../tilestache/%s" % (request.user),
            "umask": "0000",
            "dirs": "portable"},
          "layers": {
            "raster": {
                "provider": {"name": "mapnik", "mapfile": "../tilestache/%s/layers/raster/raster.xml" % (request.user)},
                "projection": "spherical mercator",
                "metatile":    {
                  "rows": 2,
                  "columns": 2,
                  "buffer": 64
                },
                "write cache": False
            }
          }
        }

        # like http://tile.openstreetmap.org/1/0/0.png
        #coord = ModestMaps.Core.Coordinate(y, x, zoom)
        path = "/raster/%s/%s/%s.png" % (zoom,x,y)
        config = TileStache.Config.buildConfiguration(config)
        #type, bytes = TileStache.getTile(config.layers[shapefile.filename], coord, 'png')
        type, bytes = TileStache.requestHandler(config, path)
        return HttpResponse(bytes, content_type="image/png")

    except:
        traceback.print_exc()
        return HttpResponse("")
開發者ID:DemersM,項目名稱:Basqui,代碼行數:77,代碼來源:tms+-+Copie.py

示例8: tileLayer

# 需要導入模塊: import TileStache [as 別名]
# 或者: from TileStache import requestHandler [as 別名]

#.........這裏部分代碼省略.........
        minLong = x * xExtent - 20037508.34
        minLat = y * yExtent - 20037508.34
        maxLong = minLong + xExtent
        maxLat = minLat + yExtent
        if minLong < -20037508.34 or maxLong > 20037508.34 or minLat < -20037508.34 or maxLat > 20037508.34:
            raise Http404

        # create de mapnik.map object
        mapXML = mapnik.Map(
            TILE_WIDTH,
            TILE_HEIGHT,
            "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m [email protected] +no_defs +over",
        )
        mapXML.buffer_size = 128

        # defining the feature layer
        query = (
            "(select "
            + geometryField
            + ', id_relat as label from "layers_feature" WHERE shapefile_id = '
            + str(shapefile.id)
            + ") as geom"
        )

        datasource = mapnik.PostGIS(
            host=dbSettings["HOST"],
            user=dbSettings["USER"],
            password=dbSettings["PASSWORD"],
            dbname=dbSettings["NAME"],
            port=dbSettings["PORT"],
            table=query,
            srid=3857,
            estimate_extent=False,
            extent=layerExtent,
            geometry_field=geometryField,
            simplify_geometries=True,
            geometry_table='"layers_feature"',
        )

        featureLayer = mapnik.Layer("featureLayer")
        featureLayer.srs = "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m [email protected] +no_defs +over"
        featureLayer.cache_features = True
        featureLayer.datasource = datasource
        featureLayer.styles.append("featureLayerStyle")

        # defining the feature layer styles
        rule = mapnik.Rule()
        if shapefile.geom_type in ["Point", "3D Point", "MultiPoint", "3D MultiPoint"]:
            rule.symbols.append(mapnik.PointSymbolizer())
        elif shapefile.geom_type in ["LineString", "3D LineString", "MultiLineString", "3D MultiLineString"]:
            rule.symbols.append(mapnik.LineSymbolizer(mapnik.Color("#000000"), 0.5))
        elif shapefile.geom_type in ["Polygon", "3D Polygon", "MultiPolygon", "3D MultiPolygon"]:
            rule.symbols.append(mapnik.PolygonSymbolizer(mapnik.Color("#f7edee")))
            rule.symbols.append(mapnik.LineSymbolizer(mapnik.Color("#000000"), 0.5))
        style = mapnik.Style()
        style.rules.append(rule)
        mapXML.append_style("featureLayerStyle", style)

        label_rule = mapnik.Rule()
        label = mapnik.TextSymbolizer(mapnik.Expression("[label]"), "DejaVu Sans Book", 10, mapnik.Color("black"))
        label.halo_radius = 4
        label.allow_overlap = False
        label.avoid_edges = True
        label_rule.symbols.append(label)
        label_style = mapnik.Style()
        label_style.rules.append(label_rule)
        featureLayer.styles.append("featureLayerStyle_label")
        # add label to the map
        mapXML.append_style("featureLayerStyle_label", label_style)

        # add new feature to the map
        mapXML.layers.append(featureLayer)

        # rendering the map tile
        mapnik_xml_path = "../tilestache/%s/layers/vector/viewer/%s.xml" % (str(request.user), str(shapefile.name))
        mapnik.save_map(mapXML, mapnik_xml_path)

        config = {
            "cache": {"name": "Test", "path": "../tilestache/%s" % (request.user), "umask": "0000", "dirs": "portable"},
            "layers": {
                shapefile.name: {
                    "provider": {"name": "mapnik", "mapfile": mapnik_xml_path},
                    "metatile": {"rows": 2, "columns": 2, "buffer": 64},
                    "projection": "spherical mercator",
                    "write cache": False,
                }
            },
        }

        # like http://tile.openstreetmap.org/1/0/0.png
        # coord = ModestMaps.Core.Coordinate(y, x, zoom)
        path = "/%s/%s/%s/%s.png" % (shapefile.name, zoom, x, y)
        config = TileStache.Config.buildConfiguration(config)
        # type, bytes = TileStache.getTile(config.layers[shapefile.filename], coord, 'png')
        type, bytes = TileStache.requestHandler(config, path)
        return HttpResponse(bytes, content_type="image/png")

    except:
        traceback.print_exc()
        return HttpResponse("")
開發者ID:DemersM,項目名稱:Basqui,代碼行數:104,代碼來源:tms.py

示例9: str

# 需要導入模塊: import TileStache [as 別名]
# 或者: from TileStache import requestHandler [as 別名]
            try:
                self.config = TileStache.parseConfigfile(self.config_path)
            except Exception, e:
                raise Core.KnownUnknown("Error loading Tilestache config file:\n%s" % str(e))

        try:
            layer, coord, ext = TileStache.splitPathInfo(environ['PATH_INFO'])
        except Core.KnownUnknown, e:
            return self._response(start_response, '400 Bad Request', str(e))

        try:
            config_val = self.config.layers.popitem()
            self.config.layers[layer] = config_val[1]
            query_params = self.config.layers[layer].provider.parameters
            t = Template(query_params['query'])
            query_params['query'] = t.substitute(map_slug=layer)
            mimetype, content = TileStache.requestHandler(self.config, environ['PATH_INFO'], environ['QUERY_STRING'])
        
        except Core.TheTileIsInAnotherCastle, e:
            other_uri = environ['SCRIPT_NAME'] + e.path_info
            
            if environ['QUERY_STRING']:
                other_uri += '?' + environ['QUERY_STRING']
    
            start_response('302 Found', [('Location', other_uri), ('Content-Type', 'text/plain')])
            return ['You are being redirected to %s\n' % other_uri]
        
        request_layer = self.config.layers[layer]
        allowed_origin = request_layer.allowed_origin
        max_cache_age = request_layer.max_cache_age
        return self._response(start_response, '200 OK', str(content), mimetype, allowed_origin, max_cache_age)
開發者ID:alalonde,項目名稱:TileStache,代碼行數:33,代碼來源:WSGICustomTileServer.py


注:本文中的TileStache.requestHandler方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。