Detach the map widget - rebase

The changes from #628 rebased onto current HEAD and a fix to avoid having the toggle adding more mapwidgets. The 3rd commit should be squashed into the first, but I've kept them seperate to be as close to the original patches in #628 as possible. I'll happily rebase/squash/etc if needed.