Not much to say here, so here is the code:

RegisterCommand('map', function(source, args)
    ActivateFrontendMenu("FE_MENU_VERSION_MP_PAUSE", false, -1) --Opens a frontend-type menu. Scaleform is already loaded, but can be changed.
    while not IsPauseMenuActive() or IsPauseMenuRestarting() do --Making extra-sure that the frontend menu is fully loaded
        Wait(0)
    end
    PauseMenuceptionGoDeeper(0) --Setting up the context menu of the Pause Menu. For other frontend menus, use https://docs.fivem.net/natives/?_0xDD564BDD0472C936
    PauseMenuceptionTheKick()
    while not IsControlJustPressed(2,202) and not IsControlJustPressed(2,200) and not IsControlJustPressed(2,199) and not IsControlJustPressed(2,238) do --Waiting for any of frontend cancel buttons to be hit. Kinda slow but whatever.
        Wait(0)
    end
    PauseMenuceptionTheKick() --doesn't really work, but the native's name is funny.
    SetFrontendActive(false) --Force-closing the entire frontend menu. I wanted a simple back button, but R* forced my hand.
end)

If you want to bind this to a button, use the bind console command, or RegisterKeyMapping(), like this:

RegisterKeyMapping('map', 'Open Map', 'keyboard', 'm')