Map rotation support

A rebased version of #1700 (still to be squashed once tests work)