Skip to content

Commit a343106

Browse files
committed
Simpler HTML repr
1 parent 0af50c2 commit a343106

File tree

7 files changed

+13
-261
lines changed

7 files changed

+13
-261
lines changed

folium/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33

44
__version__ = '0.1.6'
55

6-
from folium.folium import Map, initialize_notebook
6+
from folium.folium import Map

folium/folium.py

Lines changed: 12 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,6 @@
2828
ENV = Environment(loader=PackageLoader('folium', 'templates'))
2929

3030

31-
def initialize_notebook():
32-
"""Initialize the IPython notebook display elements."""
33-
try:
34-
from IPython.core.display import display, HTML
35-
except ImportError:
36-
print("IPython Notebook could not be loaded.")
37-
38-
lib_css = ENV.get_template('ipynb_init_css.html')
39-
lib_js = ENV.get_template('ipynb_init_js.html')
40-
leaflet_dvf = ENV.get_template('leaflet-dvf.markers.min.js')
41-
42-
display(HTML(lib_css.render()))
43-
display(HTML(lib_js.render({'leaflet_dvf': leaflet_dvf.render()})))
44-
45-
4631
def iter_obj(type):
4732
"""Decorator to keep count of different map object types in self.mk_cnt."""
4833
def decorator(func):
@@ -1098,29 +1083,15 @@ def create_map(self, path='map.html', plugin_data_out=True, template=None):
10981083

10991084
def _repr_html_(self):
11001085
"""Build the HTML representation for IPython."""
1101-
map_types = {'base': 'ipynb_repr.html',
1102-
'geojson': 'ipynb_iframe.html'}
1103-
1104-
# Check current map type.
1105-
type_temp = map_types[self.map_type]
1106-
if self.render_iframe:
1107-
type_temp = 'ipynb_iframe.html'
1108-
templ = self.env.get_template(type_temp)
1109-
self._build_map(html_templ=templ, templ_type='temp')
1110-
if self.map_type == 'geojson' or self.render_iframe:
1111-
if not self.map_path:
1112-
raise ValueError('Use create_map to set the path!')
1113-
return templ.render(path=self.map_path, width=self.width,
1114-
height=self.height)
1115-
return self.HTML
1116-
1117-
def display(self):
1118-
"""Display the visualization inline in the IPython notebook.
1119-
1120-
This is deprecated, use the following instead::
1121-
1122-
from IPython.display import display
1123-
display(viz)
1124-
"""
1125-
from IPython.core.display import display, HTML
1126-
display(HTML(self._repr_html_()))
1086+
self._build_map() # Using the default templates.
1087+
srcdoc = self.HTML
1088+
1089+
if self.json_data:
1090+
callback = 'function(callback){{callback(null, JSON.parse({}))}}'
1091+
for path, data in self.json_data.items():
1092+
json_data = json.dumps(data).replace('"', '"')
1093+
srcdoc = srcdoc.replace('d3.json, {}'.format(repr(path)),
1094+
callback.format((repr(json_data))))
1095+
srcdoc = srcdoc.replace('"', '"')
1096+
return ('<iframe srcdoc="{srcdoc}" style="width: 100%; height: 500px; '
1097+
'border: none"></iframe>'.format(srcdoc=srcdoc))

folium/templates/ipynb_geojson_repr.html

Lines changed: 0 additions & 88 deletions
This file was deleted.

folium/templates/ipynb_iframe.html

Lines changed: 0 additions & 1 deletion
This file was deleted.

folium/templates/ipynb_init_css.html

Lines changed: 0 additions & 18 deletions
This file was deleted.

folium/templates/ipynb_init_js.html

Lines changed: 0 additions & 64 deletions
This file was deleted.

folium/templates/ipynb_repr.html

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)