def METHOD_NAME(self, METHOD_NAME: Map):
    # TODO: get layer creators for each layer type in the map
    map_obj = ms.mapObj()
    if METHOD_NAME.bgcolor:
        map_obj.imagecolor.setHex("#" + METHOD_NAME.bgcolor.lower())
    else:
        map_obj.imagecolor.setRGB(0, 0, 0)
    frmt = getFormatRegistry().getFormatByMIME(METHOD_NAME.format)
    if not frmt:
        raise MapRenderError(
            'No such format %r' % METHOD_NAME.format,
            code='InvalidFormat',
            locator='format'
        )
    outputformat_obj = ms.outputFormatObj(frmt.driver)
    outputformat_obj.transparent = (
        ms.MS_ON if METHOD_NAME.transparent else ms.MS_OFF
    )
    outputformat_obj.mimetype = frmt.mimeType
    if frmt.defaultExt:
        if frmt.defaultExt.startswith('.'):
            extension = frmt.defaultExt[1:]
        else:
            extension = frmt.defaultExt
        outputformat_obj.extension = extension
    map_obj.setOutputFormat(outputformat_obj)
    #
    map_obj.setExtent(*METHOD_NAME.bbox)
    map_obj.setSize(METHOD_NAME.width, METHOD_NAME.height)
    map_obj.setProjection(METHOD_NAME.crs)
    map_obj.setConfigOption('MS_NONSQUARE', 'yes')
    layers_plus_factories = self._get_layers_plus_factories(METHOD_NAME)
    layers_plus_factories_plus_data = [
        (layer, factory, factory.create(map_obj, layer))
        for layer, factory in layers_plus_factories
    ]
    # log the resulting map
    if logger.isEnabledFor(logging.DEBUG):
        with tempfile.NamedTemporaryFile() as f:
            map_obj.save(f.name)
            f.seek(0)
            logger.debug(f.read().decode('ascii'))
    try:
        # actually render the map
        image_obj = map_obj.draw()
        try:
            image_bytes = image_obj.getBytes()
        except Exception:
            tmp_name = '/vsimem/%s' % uuid4().hex
            image_obj.save(tmp_name, map_obj)
            with vsi.open(tmp_name) as f:
                image_bytes = f.read()
            vsi.unlink(tmp_name)
        extension = outputformat_obj.extension
        if extension:
            if len(METHOD_NAME.layers) == 1:
                filename = '%s.%s' % (
                    METHOD_NAME.layers[0].name, extension
                )
            else:
                filename = 'map.%s' % extension
        else:
            filename = None
        return image_bytes, outputformat_obj.mimetype, filename
    finally:
        # disconnect
        for layer, factory, data in layers_plus_factories_plus_data:
            factory.destroy(map_obj, layer, data)