def make_metatiles(size, tiles, date_time=None):
    """
    Group by layers, and make metatiles out of all the tiles which share those
    properties relative to the "top level" tile which is parent of them all.
    Provide a 6-tuple date_time to set the timestamp on each tile within the
    metatile, or leave it as None to use the current time.
    """

    groups = defaultdict(list)
    for tile in tiles:
        key = tile['layer']
        groups[key].append(tile)

    metatiles = []
    for group in groups.itervalues():
        parent = _parent_tile(t['coord'] for t in group)
        metatiles.extend(make_multi_metatile(parent, group, date_time))

    return metatiles
Group by layers, and make metatiles out of all the tiles which share those
    properties relative to the "top level" tile which is parent of them all.
    Provide a 6-tuple date_time to set the timestamp on each tile within the
    metatile, or leave it as None to use the current time.