def _autozoom(self):
bounds = self._autobounds()<EOL>attrs = {}<EOL>midpoint = lambda a, b: (a + b)/<NUM_LIT:2><EOL>attrs['<STR_LIT:location>'] = (<EOL>midpoint(bounds['<STR_LIT>'], bounds['<STR_LIT>']),<EOL>midpoint(bounds['<STR_LIT>'], bounds['<STR_LIT>'])<EOL>)<EOL>import math<EOL>try:<EOL><INDENT>lat_diff = bounds['<STR_LIT>'] - bounds['<STR_LIT>']<EOL>lon_diff = bounds['<STR_LIT>'] - bounds['<STR_LIT>']<EOL>area, max_area = lat_diff*lon_diff, <NUM_LIT>*<NUM_LIT><EOL>if area:<EOL><INDENT>factor = <NUM_LIT:1> + max(<NUM_LIT:0>, <NUM_LIT:1> - self._width/<NUM_LIT:1000>)/<NUM_LIT:2> + max(<NUM_LIT:0>, <NUM_LIT:1>-area**<NUM_LIT:0.5>)/<NUM_LIT:2><EOL>zoom = math.log(area/max_area)/-factor<EOL><DEDENT>else:<EOL><INDENT>zoom = self._default_zoom<EOL><DEDENT>zoom = max(<NUM_LIT:1>, min(<NUM_LIT>, round(zoom)))<EOL>attrs['<STR_LIT>'] = zoom<EOL><DEDENT>except ValueError as e:<EOL><INDENT>raise Exception('<STR_LIT>', e)<EOL><DEDENT>return attrs<EOL>
Calculate zoom and location.