Refactor map.js to follow Angular best practices