1

Im newbie in python, so excuse me for this newbie question. I have a class and a function:

class Datasource(mapnik.PythonDatasource):
    def __init__(self):
        super(Datasource, self).__init__()

    def features(self, query):
        return mapnik.PythonDatasource.wkb_features(mvt)

def tileLayer(request, version, shapefile_id, zoom, x, y):
    mvt = requestHandler(request, zoom, x, y)

    datasource = mapnik.Python(factory='Datasource')

How can I pass the mvt variable to the Datasource class when calling mapnik.Python(factory='Datasource')

4

1 回答 1

1

您可以向方法添加其他参数mapnik.Python- 它们将被传递给 datasource __init__

mvt = requestHandler(request, zoom, x, y)
datasource = mapnik.Python(factory='Datasource', mvt=mvt)

将参数添加到Datasource__init__方法定义并使用它保存mvt在类实例中:

class Datasource(mapnik.PythonDatasource):
    def __init__(self, mvt):
        super(Datasource, self).__init__()
        self.mvt = mvt

    def features(self, query):
        return mapnik.PythonDatasource.wkb_features(self.mvt)
于 2014-02-23T19:59:40.697 回答