'Calculate zoom level and center coordinates in mercator.'

def set_bounds_from_bbox(self, bbox):

    self.set_latlon_bounds(bbox)
    (minx, maxx, miny, maxy) = [float(c) for c in bbox]
    x = ((minx + maxx) / 2)
    y = ((miny + maxy) / 2)
    (center_x, center_y) = forward_mercator((x, y))
    xdiff = (maxx - minx)
    ydiff = (maxy - miny)
    zoom = 0
    if ((xdiff > 0) and (ydiff > 0)):
        width_zoom = math.log((360 / xdiff), 2)
        height_zoom = math.log((360 / ydiff), 2)
        zoom = math.ceil(min(width_zoom, height_zoom))
    self.zoom = zoom
    self.center_x = center_x
    self.center_y = center_y
