def __init__(self, layer, osmFile, watermark, cacheDir):
        import TileCache.Service
        from TileCache.Caches.Disk import Disk
        from TileCache.Layers.Mapnik import Mapnik

        self.layer = Mapnik(layer,
                            mapfile=osmFile,
                            watermarkimage=watermark,
                            watermarkopacity=1.0)
        self.tileService = TileCache.Service(Disk(cacheDir),
                                             {"layer": self.layer})
Exemple #2
0
def get_tile(request, version, layername, z, x, y, extension='png'):
    global style
    image = None
    name = request.META['QUERY_STRING'] or 'all'
    name = strip_name(name)
    mapnik_layer = MapnikLayer(
                 name,
                 'foo',# mapfile skipped as we dynamically assign map object
                 spherical_mercator = 'true',
                 extension = "png",
                 tms_type = 'google', # tms or google
                 paletted = 'true',
                 debug=False
                 )
    srv.layers[name] = mapnik_layer
    z, x, y = int(z), int(x), int(y)
    if mapnik_layer.tms_type == "google":
        res = mapnik_layer.resolutions[z]
        maxY = int(
          round(
            (mapnik_layer.bbox[3] - mapnik_layer.bbox[1]) / 
            (res * mapnik_layer.size[1])
           )
        ) - 1
        tile  = Tile(mapnik_layer, x, maxY - y, z)
    else:
        tile = Tile(mapnik_layer, x, y, z)
    if settings.CACHE_SEARCH_TILES:
        image = srv.cache.get(tile)
    if not image:
        # cached map - must be run multiprocess to avoid potential race condition
        m = query_hash.get(name)
        if not m:
            trees, plots, agg_search_result, str_tile_query = _build_tree_search_result(request)
            plots = plots.filter(tree__in=trees)
            trees = plots.only('geometry')
            styles=[{'name':'style','obj':style}]
            m = qs_to_map(trees,styles=styles)
            #print mapnik.save_map_to_string(m)
            query_hash[name] = m
        # push the actual mapnik map into the TC MapnikLayer
        mapnik_layer.mapnik = m
        if settings.CACHE_SEARCH_TILES:
            # render and cache
            image = srv.renderTile(tile)[1]
        else:
            # render directly from layer, not service, therefore bypassing saving to cache
            image = mapnik_layer.renderTile(tile)
    response = TileResponse(image)    
    return response(extension)
Exemple #3
0
def get_tile(request, version, layername, z, x, y, extension='png'):
    global style
    image = None
    name = request.META['QUERY_STRING'] or 'all'
    name = strip_name(name)
    mapnik_layer = MapnikLayer(
        name,
        'foo',  # mapfile skipped as we dynamically assign map object
        spherical_mercator='true',
        extension="png",
        tms_type='google',  # tms or google
        paletted='true',
        debug=False)
    srv.layers[name] = mapnik_layer
    z, x, y = int(z), int(x), int(y)
    if mapnik_layer.tms_type == "google":
        res = mapnik_layer.resolutions[z]
        maxY = int(
            round((mapnik_layer.bbox[3] - mapnik_layer.bbox[1]) /
                  (res * mapnik_layer.size[1]))) - 1
        tile = Tile(mapnik_layer, x, maxY - y, z)
    else:
        tile = Tile(mapnik_layer, x, y, z)
    if settings.CACHE_SEARCH_TILES:
        image = srv.cache.get(tile)
    if not image:
        # cached map - must be run multiprocess to avoid potential race condition
        m = query_hash.get(name)
        if not m:
            trees, plots, agg_search_result, str_tile_query = _build_tree_search_result(
                request)
            plots = plots.filter(tree__in=trees)
            trees = plots.only('geometry')
            styles = [{'name': 'style', 'obj': style}]
            m = qs_to_map(trees, styles=styles)
            #print mapnik.save_map_to_string(m)
            query_hash[name] = m
        # push the actual mapnik map into the TC MapnikLayer
        mapnik_layer.mapnik = m
        if settings.CACHE_SEARCH_TILES:
            # render and cache
            image = srv.renderTile(tile)[1]
        else:
            # render directly from layer, not service, therefore bypassing saving to cache
            image = mapnik_layer.renderTile(tile)
    response = TileResponse(image)
    return response(extension)
Exemple #4
0
def get_tile(request, version, layername, z, x, y, extension="png"):
    global style
    image = None
    name = request.META["QUERY_STRING"] or "all"
    name = strip_name(name)
    mapnik_layer = MapnikLayer(
        name,
        "foo",  # mapfile skipped as we dynamically assign map object
        spherical_mercator="true",
        extension="png",
        tms_type="google",
        paletted="true",
        debug=False,
    )
    srv.layers[name] = mapnik_layer
    z, x, y = int(z), int(x), int(y)
    if mapnik_layer.tms_type == "google":
        res = mapnik_layer.resolutions[z]
        maxY = int(round((mapnik_layer.bbox[3] - mapnik_layer.bbox[1]) / (res * mapnik_layer.size[1]))) - 1
        tile = Tile(mapnik_layer, x, maxY - y, z)
    else:
        tile = Tile(mapnik_layer, x, y, z)
    if settings.CACHE_SEARCH_TILES:
        image = srv.cache.get(tile)
    if not image:
        # cached map - must be run multiprocess to avoid potential race condition
        m = query_hash.get(name)
        if not m:
            trees, geog_obj = _build_tree_search_result(request)
            trees = trees.only("geometry")
            styles = [{"name": "style", "obj": style}]
            m = qs_to_map(trees, styles=styles)
            query_hash[name] = m
        # push the actual mapnik map into the TC MapnikLayer
        mapnik_layer.mapnik = m
        if settings.CACHE_SEARCH_TILES:
            # render and cache
            image = srv.renderTile(tile)[1]
        else:
            # render directly from layer, not service, therefore bypassing saving to cache
            image = mapnik_layer.renderTile(tile)
    response = TileResponse(image)
    return response(extension)
    def __init__(self, layer, osmFile, watermark, cacheDir):
        import TileCache.Service
        from TileCache.Caches.Disk import Disk
        from TileCache.Layers.Mapnik import Mapnik

        self.layer = Mapnik(layer,
                 mapfile=osmFile,
                 watermarkimage=watermark,
                 watermarkopacity=1.0)
        self.tileService = TileCache.Service(Disk(cacheDir),
                                             {"layer": self.layer})
class MapService:
    """ render tiles """
    def __init__(self, layer, osmFile, watermark, cacheDir):
        import TileCache.Service
        from TileCache.Caches.Disk import Disk
        from TileCache.Layers.Mapnik import Mapnik

        self.layer = Mapnik(layer,
                 mapfile=osmFile,
                 watermarkimage=watermark,
                 watermarkopacity=1.0)
        self.tileService = TileCache.Service(Disk(cacheDir),
                                             {"layer": self.layer})
    def render(self, id, tileWidth, tileHeight, delta):
        tile =  FlofTile(self.layer, int(id))
        tile.width = tileWidth
        tile.height = tileHeight
        tile.z = delta
        format, image = self.tileService.renderTile(tile)
        return (format, self.layer.watermark(image))
class MapService:
    """ render tiles """
    def __init__(self, layer, osmFile, watermark, cacheDir):
        import TileCache.Service
        from TileCache.Caches.Disk import Disk
        from TileCache.Layers.Mapnik import Mapnik

        self.layer = Mapnik(layer,
                            mapfile=osmFile,
                            watermarkimage=watermark,
                            watermarkopacity=1.0)
        self.tileService = TileCache.Service(Disk(cacheDir),
                                             {"layer": self.layer})

    def render(self, id, tileWidth, tileHeight, delta):
        tile = FlofTile(self.layer, int(id))
        tile.width = tileWidth
        tile.height = tileHeight
        tile.z = delta
        format, image = self.tileService.renderTile(tile)
        return (format, self.layer.watermark(image))