@@ -128,12 +128,14 @@ def __init__(self, location=None, width='100%', height='100%',
128128 self .json_data = {}
129129 self .plugins = {}
130130
131- # Location.
132- if not location :
133- raise ValueError ('You must pass a Lat/Lon location to initialize'
134- ' your map' )
131+ # No location means we will use automatic bounds and ignore zoom
135132 self .location = location
136133
134+ # If location is not passed, we center the map at 0,0
135+ if not location :
136+ location = [0 , 0 ]
137+ zoom_start = min_zoom
138+
137139 # Map Size Parameters.
138140 try :
139141 if isinstance (width , int ):
@@ -664,6 +666,31 @@ def fit_bounds(self, bounds, padding_top_left=None,
664666 self .template_vars .update ({'fit_bounds' : fit_bounds_str })
665667
666668
669+ def _auto_bounds (self ):
670+ if 'fit_bounds' in self .template_vars :
671+ return
672+ # Get count for each feature type
673+ ft_names = ["marker" , "line" , "circle" , "polygon" , "multiline" ]
674+ ft_names = [i for i in ft_names if i in self .mark_cnt ]
675+
676+ # Make a comprehensive list of all the features we want to fit
677+ feat_str = ["{name}_{count}" .format (name = ft_name ,
678+ count = self .mark_cnt [ft_name ])
679+ for ft_name in ft_names
680+ for count in range (1 , self .mark_cnt [ft_name ]+ 1 )
681+ ]
682+ feat_str = "[" + ', ' .join (feat_str ) + "]"
683+
684+ fit_bounds = self .env .get_template ('fit_bounds.js' )
685+ fit_bounds_str = fit_bounds .render ({
686+ 'autobounds' : not self .location ,
687+ 'features' : feat_str ,
688+ 'fit_bounds_options' : json .dumps ({'padding' : [30 , 30 ]}),
689+ })
690+
691+ self .template_vars .update ({'fit_bounds' : fit_bounds_str .strip ()})
692+
693+
667694 def _popup_render (self , popup = None , mk_name = None , count = None ,
668695 popup_on = True , width = 300 ):
669696 """Popup renderer: either text or Vincent/Vega.
@@ -937,6 +964,7 @@ def json_style(style_cnt, line_color, line_weight, line_opacity,
937964 self .template_vars .setdefault ('gjson_layers' , []).append (layer )
938965
939966 def _build_map (self , html_templ = None , templ_type = 'string' ):
967+ self ._auto_bounds ()
940968 """Build HTML/JS/CSS from Templates given current map type."""
941969 if html_templ is None :
942970 map_types = {'base' : 'fol_template.html' ,
0 commit comments