def _autozoom(self):
        """Calculate zoom and location."""
        bounds = self._autobounds()
        attrs = {}

        midpoint = lambda a, b: (a + b)/2
        attrs['location'] = (
            midpoint(bounds['min_lat'], bounds['max_lat']),
            midpoint(bounds['min_lon'], bounds['max_lon'])
        )

        # self._folium_map.fit_bounds(
        #     [bounds['min_long'], bounds['min_lat']],
        #     [bounds['max_long'], bounds['max_lat']]
        # )

        # remove the following with new Folium release
        # rough approximation, assuming max_zoom is 18
        import math
        try:
            lat_diff = bounds['max_lat'] - bounds['min_lat']
            lon_diff = bounds['max_lon'] - bounds['min_lon']
            area, max_area = lat_diff*lon_diff, 180*360
            if area:
                factor = 1 + max(0, 1 - self._width/1000)/2 + max(0, 1-area**0.5)/2
                zoom = math.log(area/max_area)/-factor
            else:
                zoom = self._default_zoom
            zoom = max(1, min(18, round(zoom)))
            attrs['zoom_start'] = zoom
        except ValueError as e:
            raise Exception('Check that your locations are lat-lon pairs', e)

        return attrs
def _autozoom ( self ) : bounds = self . _autobounds ( ) attrs = { } midpoint = lambda a , b : ( a + b ) / 2 attrs [ 'location' ] = ( midpoint ( bounds [ 'min_lat' ] , bounds [ 'max_lat' ] ) , midpoint ( bounds [ 'min_lon' ] , bounds [ 'max_lon' ] ) ) import math try : lat_diff = bounds [ 'max_lat' ] - bounds [ 'min_lat' ] lon_diff = bounds [ 'max_lon' ] - bounds [ 'min_lon' ] area , max_area = lat_diff * lon_diff , 180 * 360 if area : factor = 1 + max ( 0 , 1 - self . _width / 1000 ) / 2 + max ( 0 , 1 - area ** 0.5 ) / 2 zoom = math . log ( area / max_area ) / - factor else : zoom = self . _default_zoom zoom = max ( 1 , min ( 18 , round ( zoom ) ) ) attrs [ 'zoom_start' ] = zoom except ValueError as e : raise Exception ( 'Check that your locations are lat-lon pairs' , e ) return attrs
Calculate zoom and location.