Skip to content

Commit 7169d08

Browse files
committed
Merge pull request #5 from samatjain/customtemplate
Allow rendering w/ custom template
2 parents 4c97fe7 + 1a85841 commit 7169d08

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

folium/folium.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -585,18 +585,22 @@ def json_style(style_cnt, line_color, line_weight, line_opacity,
585585
self.template_vars.setdefault('geo_styles', []).append(style)
586586
self.template_vars.setdefault('gjson_layers', []).append(layer)
587587

588-
def _build_map(self):
588+
def _build_map(self, html_templ=None):
589589
'''Build HTML/JS/CSS from Templates given current map type'''
590-
map_types = {'base': 'fol_template.html',
591-
'geojson': 'geojson_template.html'}
590+
if html_templ is None:
591+
map_types = {'base': 'fol_template.html',
592+
'geojson': 'geojson_template.html'}
592593

593-
#Check current map type
594-
type_temp = map_types[self.map_type]
594+
#Check current map type
595+
type_temp = map_types[self.map_type]
596+
597+
html_templ = self.env.get_template(type_temp)
598+
else:
599+
html_templ = self.env.from_string(html_templ)
595600

596-
html_templ = self.env.get_template(type_temp)
597601
self.HTML = html_templ.render(self.template_vars)
598602

599-
def create_map(self, path='map.html', plugin_data_out=True):
603+
def create_map(self, path='map.html', plugin_data_out=True, template=None):
600604
'''Write Map output to HTML and data output to JSON if available
601605
602606
Parameters:
@@ -606,10 +610,12 @@ def create_map(self, path='map.html', plugin_data_out=True):
606610
plugin_data_out: boolean, default True
607611
If using plugins such as awesome markers, write all plugin
608612
data such as JS/CSS/images to path
613+
template: string, default None
614+
Custom template to render
609615
610616
'''
611617

612-
self._build_map()
618+
self._build_map(template)
613619

614620
with codecs.open(path, 'w', 'utf-8') as f:
615621
f.write(self.HTML)

0 commit comments

Comments
 (0)