Exemple #1
0
    def get(self, zoom, tx, ty):
        try:
            zoom = int(zoom)
            tx = int(tx)
            ty = int(ty)
        except ValueError:
            self.set_status(400)
            return self.render()

        # short-circuit return from cache
        cache_key = self.message.path
        payload = cache.get(cache_key)
        if payload is None:
            payload = generate_tile(zoom, tx, ty)
            if payload is None:
                payload = '' # mark empty payloads in the cache

            cache.set(cache_key, payload)

        if len(payload) == 0:
            logging.warn('empty payload')
            self.set_status(204)
        else:
            self.headers['Content-Type'] = 'image/jpeg'
            self.set_body(payload)

        self.headers['Access-Control-Allow-Origin'] = '*'
        return self.render()
Exemple #2
0
    return HeatTile.CBK[zoom] + (0.5 * math.log((1 + inner) / (1 - inner)) * (-HeatTile.CFK[zoom]))


# Warm up the server by loading up all our tiles

# Work through the different zoom levels we allow
for zoom in xrange(12, 13):
    # Determine the x min tile, x max tile, y min tile, and y max tile
    X_MIN_TILE = int(x_from_zoom(zoom, MIN_LON) / TILE_SIZE)
    X_MAX_TILE = int(x_from_zoom(zoom, MAX_LON) / TILE_SIZE)
    Y_MIN_TILE = int(y_from_zoom(zoom, MAX_LAT) / TILE_SIZE)
    Y_MAX_TILE = int(y_from_zoom(zoom, MIN_LAT) / TILE_SIZE)

    for x in xrange(X_MIN_TILE, X_MAX_TILE + 1):
        for y in xrange(Y_MIN_TILE, Y_MAX_TILE + 1):
            jpeg = generate_tile(zoom, x, y)
            if jpeg is None:
                #print("Empty tile z%s x%s y%s" % (zoom, x, y))
                pass
            else:
                z_path = SEP.join([OUT_DIR, str(zoom)])
                y_path = SEP.join([OUT_DIR, str(zoom), str(y)])
                jpg_path = SEP.join([OUT_DIR, str(zoom), str(y), str(x) + '.jpg'])

                if not os.path.isdir(z_path):
                    os.mkdir(z_path)
                if not os.path.isdir(y_path):
                    os.mkdir(y_path)
                print("Saving tile z%s x%s y%s: %s" % (zoom, x, y, len(jpeg)))
                f = open(jpg_path, 'w')
                f.write(jpeg)