Skip to content

Allow rendering w/ custom template #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 6, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions folium/folium.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,18 +582,22 @@ def json_style(style_cnt, line_color, line_weight, line_opacity,
self.template_vars.setdefault('geo_styles', []).append(style)
self.template_vars.setdefault('gjson_layers', []).append(layer)

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

#Check current map type
type_temp = map_types[self.map_type]
#Check current map type
type_temp = map_types[self.map_type]

html_templ = self.env.get_template(type_temp)
else:
html_templ = self.env.from_string(html_templ)

html_templ = self.env.get_template(type_temp)
self.HTML = html_templ.render(self.template_vars)

def create_map(self, path='map.html', plugin_data_out=True):
def create_map(self, path='map.html', plugin_data_out=True, template=None):
'''Write Map output to HTML and data output to JSON if available

Parameters:
Expand All @@ -603,10 +607,12 @@ def create_map(self, path='map.html', plugin_data_out=True):
plugin_data_out: boolean, default True
If using plugins such as awesome markers, write all plugin
data such as JS/CSS/images to path
template: string, default None
Custom template to render

'''

self._build_map()
self._build_map(template)

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