예제 #1
0
def delete_caches(sender, instance, **kwargs):
    _log.debug('Deleting caches for {0}'.format(instance.title))

    if isinstance(instance, Style):
        CacheManager.get().remove_caches_for_style(instance.slug)
    elif isinstance(instance, Layer):
        CacheManager.get().remove_caches_for_layer(instance.slug)
예제 #2
0
def delete_caches(sender, instance, **kwargs):
    _log.debug('Deleting caches for {0}'.format(instance.title))

    if isinstance(instance, Style):
        CacheManager.get().remove_caches_for_style(instance.slug)
    elif isinstance(instance, Layer):
        CacheManager.get().remove_caches_for_layer(instance.slug)
예제 #3
0
def tms(request, layer, z=None, x=None, y=None, **kwargs):
    if z and x and y:
        z = int(z)
        x = int(x)
        y = int(y)

        table = None
        if '#' in layer:
            layer_slug, table = layer.split('#')
        else:
            layer_slug = layer

        # dispatch.api_accessed.send(RenderedLayer, instance=layer_instance, user=user)
        style = request.GET.get(
            'style',
            Layer.objects.get(slug=layer_slug).default_style.slug)
        cache = CacheManager.get().get_tile_cache([layer], [style])
        rendered, png = cache.fetch_tile(z, x, y)
        _log.debug("returning tile {z}/{x}/{y} with size {png}".format(
            z=z, x=x, y=y, png=len(png)))
        rsp = HttpResponse(png, content_type='image/png')
        rsp['Content-Disposition'] = 'attachment; filename="{z}.{x}.{y}.png"'.format(
            z=z, x=x, y=y)
        return rsp
    else:
        return HttpResponseRedirect(
            reverse('layer-page', kwargs={'slug': layer}))
예제 #4
0
def seed_layer(request, layer):
    mnz = int(request.GET['minz'])
    mxz = int(
        request.GET['maxz']
    )  # anything greater would cause a DOS attack.  We should do it manually
    mnx = int(request.GET['minx'])
    mxx = int(request.GET['maxx'])
    mny = int(request.GET['miny'])
    mxy = int(request.GET['maxy'])

    layer = Layer.objects.get(slug=layer)
    style = request.GET.get('style', layer.default_style)

    user = authorize(request, page=layer, edit=True)
    dispatch.api_accessed.send(Layer, instance=layer, user=user)
    CacheManager.get().get_tile_cache(layers=[layer],
                                      styles=[style]).seed_tiles(
                                          mnz, mxz, mnx, mny, mxx, mxy)
    return HttpResponse()
예제 #5
0
def test_fetch_tile(layer):
    mgr = CacheManager.get()
    filename = mgr.cache_entry_name(styles=[layer.default_style.slug],
        layers=[layer.slug])
    if os.path.exists(filename + '.mbtiles'):
        os.unlink(filename + '.mbtiles')

    cc = mgr.get_tile_cache(
        styles=[layer.default_style.slug],
        layers=[layer.slug],
    )
    rendered, tile = cc.fetch_tile(0, 0, 0)
    assert rendered
    rendered, tile = cc.fetch_tile(0, 0, 0)
    assert not rendered

    with open('test_fetch_tile.0.0.0.png', 'wb') as output:
        output.write(tile)

    rendered, tile = cc.fetch_tile(1, 0, 0)
    with open('test_fetch_tile.1.0.0.png', 'wb') as output:
        output.write(tile)

    rendered, tile = cc.fetch_tile(1, 1, 1)
    with open('test_fetch_tile.1.1.1.png', 'wb') as output:
        output.write(tile)

    rendered, tile = cc.fetch_tile(2, 0, 0)
    with open('test_fetch_tile.2.0.0.png', 'wb') as output:
        output.write(tile)

    rendered, tile = cc.fetch_tile(2, 1, 1)
    with open('test_fetch_tile.2.1.1.png', 'wb') as output:
        output.write(tile)

    rendered, tile = cc.fetch_tile(2, 2, 2)
    with open('test_fetch_tile.2.2.2.png', 'wb') as output:
        output.write(tile)
예제 #6
0
def test_fetch_tile(layer):
    mgr = CacheManager.get()
    filename = mgr.cache_entry_name(styles=[layer.default_style.slug],
                                    layers=[layer.slug])
    if os.path.exists(filename + '.mbtiles'):
        os.unlink(filename + '.mbtiles')

    cc = mgr.get_tile_cache(
        styles=[layer.default_style.slug],
        layers=[layer.slug],
    )
    rendered, tile = cc.fetch_tile(0, 0, 0)
    assert rendered
    rendered, tile = cc.fetch_tile(0, 0, 0)
    assert not rendered

    with open('test_fetch_tile.0.0.0.png', 'wb') as output:
        output.write(tile)

    rendered, tile = cc.fetch_tile(1, 0, 0)
    with open('test_fetch_tile.1.0.0.png', 'wb') as output:
        output.write(tile)

    rendered, tile = cc.fetch_tile(1, 1, 1)
    with open('test_fetch_tile.1.1.1.png', 'wb') as output:
        output.write(tile)

    rendered, tile = cc.fetch_tile(2, 0, 0)
    with open('test_fetch_tile.2.0.0.png', 'wb') as output:
        output.write(tile)

    rendered, tile = cc.fetch_tile(2, 1, 1)
    with open('test_fetch_tile.2.1.1.png', 'wb') as output:
        output.write(tile)

    rendered, tile = cc.fetch_tile(2, 2, 2)
    with open('test_fetch_tile.2.2.2.png', 'wb') as output:
        output.write(tile)
예제 #7
0
def trim_tile_caches(sender, instance, *args, **kwargs):
    if sender is Style:
        CacheManager.get().remove_caches_for_style(instance)
    elif sender is Layer:
        CacheManager.get().remove_caches_for_layer(instance)
예제 #8
0
def shave_tile_caches(sender, instance, bbox, *args, **kwargs):
    CacheManager.get().shave_caches(instance, bbox)
예제 #9
0
def trim_tile_caches(sender, instance, *args, **kwargs):
    if sender is Style:
        CacheManager.get().remove_caches_for_style(instance)
    elif sender is Layer:
        CacheManager.get().remove_caches_for_layer(instance)
예제 #10
0
def shave_tile_caches(sender, instance, bbox, *args, **kwargs):
     CacheManager.get().shave_caches(instance, bbox)