def _find_top_left_tile(map):
    """
    Calculate the tile coordinate and its position relative to top-left
    offset of the map image.

    :param map: Map instance.
    """
    origin = map.origin
    w, h = map.size
    tw = map.provider.tile_width
    th = map.provider.tile_height
    px = map.offset[0] + w // 2
    py = map.offset[1] + h // 2
    dx = px // tw + (px % tw > 0)
    dy = py // th + (py % th > 0)
    px -= dx * tw
    py -= dy * th
    offset = px, py
    coord = origin[0] - dx, origin[1] - dy
    assert -tw < offset[0] <= 0 and -th < offset[1] <= 0, offset
    return coord, offset
