File tree Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ def __init__(self,
3636 cluster = False ,
3737 cluster_imagepath = DEFAULT_CLUSTER_IMAGE_PATH ,
3838 cluster_gridsize = 60 ,
39+ fit_markers_to_bounds = False ,
3940 ** kwargs ):
4041 """Builds the Map properties"""
4142 self .cls = cls
@@ -70,6 +71,8 @@ def __init__(self,
7071 self .cluster_imagepath = cluster_imagepath
7172 self .cluster_gridsize = cluster_gridsize
7273
74+ self .fit_markers_to_bounds = fit_markers_to_bounds
75+
7376 def build_markers (self , markers ):
7477 if not markers :
7578 return
@@ -723,6 +726,7 @@ def as_json(self):
723726 'collapsible' : self .collapsible ,
724727 'js' : dumps (self .js ),
725728 'html' : dumps (self .html ),
729+ 'fit_markers_to_bounds' : self .fit_markers_to_bounds ,
726730 }
727731
728732 return json_dict
Original file line number Diff line number Diff line change 6262 }
6363 }
6464
65+ { % if gmap . fit_markers_to_bounds % }
66+ // fit all markers in bounds
67+ var { { gmap . varname} } _bounds = new google . maps . LatLngBounds ( ) ;
68+ for ( i = 0 ; i < { { gmap . varname} } _markers . length ; i ++ ) {
69+ { { gmap . varname } } _bounds . extend ( { { gmap . varname } } _markers [ i ] . getPosition ( ) ) ;
70+ } ;
71+ { { gmap . varname } } . fitBounds ( { { gmap . varname} } _bounds ) ;
72+ { % endif % }
73+
6574 // add rectangles
6675 var raw_rectangles = { { gmap . rectangles | tojson | safe } } ;
6776 for ( i = 0 ; i < { { gmap . rectangles | length } } ; i ++ ) {
139148 ) ;
140149 }
141150 }
142-
151+
143152 // add polylines
144153 var raw_polylines = { { gmap . polylines | tojson | safe } } ;
145154 for ( i = 0 ; i < { { gmap . polylines | length } } ; i ++ ) {
179188 infowindow . open ( map , this ) ;
180189 } ;
181190 }
182-
191+
183192 { % if gmap . collapsible % }
184193 function init_ { { gmap . identifier } } _button ( ) {
185194 document . getElementById ( '{{gmap.identifier}}' ) . style . display = 'none' ;
You can’t perform that action at this time.
0 commit comments