@@ -128,12 +128,14 @@ def __init__(self, location=None, width='100%', height='100%',
128
128
self .json_data = {}
129
129
self .plugins = {}
130
130
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
135
132
self .location = location
136
133
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
+
137
139
# Map Size Parameters.
138
140
try :
139
141
if isinstance (width , int ):
@@ -651,6 +653,31 @@ def fit_bounds(self, bounds, padding_top_left=None,
651
653
self .template_vars .update ({'fit_bounds' : fit_bounds_str })
652
654
653
655
656
+ def _auto_bounds (self ):
657
+ if 'fit_bounds' in self .template_vars :
658
+ return
659
+ # Get count for each feature type
660
+ ft_names = ["marker" , "line" , "circle" , "polygon" , "multiline" ]
661
+ ft_names = [i for i in ft_names if i in self .mark_cnt ]
662
+
663
+ # Make a comprehensive list of all the features we want to fit
664
+ feat_str = ["{name}_{count}" .format (name = ft_name ,
665
+ count = self .mark_cnt [ft_name ])
666
+ for ft_name in ft_names
667
+ for count in range (1 , self .mark_cnt [ft_name ]+ 1 )
668
+ ]
669
+ feat_str = "[" + ', ' .join (feat_str ) + "]"
670
+
671
+ fit_bounds = self .env .get_template ('fit_bounds.js' )
672
+ fit_bounds_str = fit_bounds .render ({
673
+ 'autobounds' : not self .location ,
674
+ 'features' : feat_str ,
675
+ 'fit_bounds_options' : json .dumps ({'padding' : [30 , 30 ]}),
676
+ })
677
+
678
+ self .template_vars .update ({'fit_bounds' : fit_bounds_str .strip ()})
679
+
680
+
654
681
def _popup_render (self , popup = None , mk_name = None , count = None ,
655
682
width = 300 ):
656
683
"""Popup renderer: either text or Vincent/Vega.
@@ -922,6 +949,7 @@ def json_style(style_cnt, line_color, line_weight, line_opacity,
922
949
self .template_vars .setdefault ('gjson_layers' , []).append (layer )
923
950
924
951
def _build_map (self , html_templ = None , templ_type = 'string' ):
952
+ self ._auto_bounds ()
925
953
"""Build HTML/JS/CSS from Templates given current map type."""
926
954
if html_templ is None :
927
955
map_types = {'base' : 'fol_template.html' ,
0 commit comments