Improved logic for centering the map.