Moves map code into a directive