|
28 | 28 | ENV = Environment(loader=PackageLoader('folium', 'templates')) |
29 | 29 |
|
30 | 30 |
|
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 | | - |
46 | 31 | def iter_obj(type): |
47 | 32 | """Decorator to keep count of different map object types in self.mk_cnt.""" |
48 | 33 | def decorator(func): |
@@ -1098,29 +1083,15 @@ def create_map(self, path='map.html', plugin_data_out=True, template=None): |
1098 | 1083 |
|
1099 | 1084 | def _repr_html_(self): |
1100 | 1085 | """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)) |
0 commit comments