Skip to content

Commit f62b62d

Browse files
Andy Birdocefpaf
authored andcommitted
add ipython notebook example
1 parent 684544a commit f62b62d

File tree

1 file changed

+185
-0
lines changed

1 file changed

+185
-0
lines changed
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
{
2+
"metadata": {
3+
"name": "",
4+
"signature": "sha256:a45c55171064486650197eeb8d869dfd5569e90d967efefa1dfaf9a33281b334"
5+
},
6+
"nbformat": 3,
7+
"nbformat_minor": 0,
8+
"worksheets": [
9+
{
10+
"cells": [
11+
{
12+
"cell_type": "code",
13+
"collapsed": false,
14+
"input": [
15+
"from IPython.display import HTML\n",
16+
"import folium"
17+
],
18+
"language": "python",
19+
"metadata": {},
20+
"outputs": [],
21+
"prompt_number": 16
22+
},
23+
{
24+
"cell_type": "code",
25+
"collapsed": false,
26+
"input": [
27+
"def inline_map(map):\n",
28+
" \"\"\"\n",
29+
" Embeds the HTML source of the map directly into the IPython notebook.\n",
30+
" \n",
31+
" This method will not work if the map depends on any files (json data). Also this uses\n",
32+
" the HTML5 srcdoc attribute, which may not be supported in all browsers.\n",
33+
" \"\"\"\n",
34+
" map._build_map()\n",
35+
" return HTML('<iframe srcdoc=\"{srcdoc}\" style=\"width: 100%; height: 510px; border: none\"></iframe>'.format(srcdoc=map.HTML.replace('\"', '&quot;')))\n",
36+
"\n",
37+
"def embed_map(map, path=\"m213map.html\"):\n",
38+
" \"\"\"\n",
39+
" Embeds a linked iframe to the map into the IPython notebook.\n",
40+
" \n",
41+
" Note: this method will not capture the source of the map into the notebook.\n",
42+
" This method should work for all maps (as long as they use relative urls).\n",
43+
" \"\"\"\n",
44+
" map.create_map(path=path)\n",
45+
" return HTML('<iframe src=\"files/{path}\" style=\"width: 100%; height: 510px; border: none\"></iframe>'.format(path=path))"
46+
],
47+
"language": "python",
48+
"metadata": {},
49+
"outputs": [],
50+
"prompt_number": 17
51+
},
52+
{
53+
"cell_type": "code",
54+
"collapsed": false,
55+
"input": [
56+
"map = folium.Map(width=500,height=500,location=[44, -73], zoom_start=4)\n",
57+
"\n",
58+
"map.simple_marker([40.67, -73.94], popup='Add <b>popup</b> text here.',marker_color='green',marker_icon='ok-sign')\n",
59+
"map.simple_marker([44.67, -73.94], popup='Add <b>popup</b> text here.',marker_color='red',marker_icon='remove-sign')\n",
60+
"map.simple_marker([44.67, -71.94], popup='Add <b>popup</b> text here.')\n",
61+
"inline_map(map)"
62+
],
63+
"language": "python",
64+
"metadata": {},
65+
"outputs": [
66+
{
67+
"html": [
68+
"<iframe srcdoc=\"<!DOCTYPE html>\n",
69+
"<head>\n",
70+
" <meta http-equiv=&quot;content-type&quot; content=&quot;text/html; charset=UTF-8&quot; />\n",
71+
" <link rel=&quot;stylesheet&quot; href=&quot;http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.css&quot; />\n",
72+
" <script src=&quot;http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.js&quot;></script>\n",
73+
"\n",
74+
" <script src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js&quot;></script>\n",
75+
"\n",
76+
" <link rel=&quot;stylesheet&quot; href=&quot;//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css&quot;>\n",
77+
" <link rel=&quot;stylesheet&quot; href=&quot;//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css&quot;>\n",
78+
" <script src=&quot;//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js&quot;></script>\n",
79+
"\n",
80+
" <link rel=&quot;stylesheet&quot; href=&quot;//cdnjs.cloudflare.com/ajax/libs/Leaflet.awesome-markers/2.0.0/leaflet.awesome-markers.css&quot;>\n",
81+
" <script src=&quot;//cdnjs.cloudflare.com/ajax/libs/Leaflet.awesome-markers/2.0.0/leaflet.awesome-markers.js&quot;></script>\n",
82+
"\n",
83+
" \n",
84+
"\n",
85+
" \n",
86+
" \n",
87+
" \n",
88+
" \n",
89+
"\n",
90+
"\n",
91+
" <style>\n",
92+
"\n",
93+
" #map {\n",
94+
" position:absolute;\n",
95+
" top:0;\n",
96+
" bottom:0;\n",
97+
" right:0;\n",
98+
" left:0;\n",
99+
" }\n",
100+
"\n",
101+
" </style>\n",
102+
"</head>\n",
103+
"\n",
104+
"<body>\n",
105+
"\n",
106+
" <div class=&quot;folium-map&quot; id=&quot;folium_95163fd745ad44a7ac274212890fc75a&quot; style=&quot;width: 500px; height: 500px&quot;></div>\n",
107+
"\n",
108+
" <script>\n",
109+
"\n",
110+
" \n",
111+
"\n",
112+
" var map = L.map('folium_95163fd745ad44a7ac274212890fc75a').setView([44, -73], 4);\n",
113+
"\n",
114+
" L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {\n",
115+
" maxZoom: 18,\n",
116+
" attribution: 'Map data (c) <a href=&quot;http://openstreetmap.org&quot;>OpenStreetMap</a> contributors'\n",
117+
" }).addTo(map);\n",
118+
"\n",
119+
" \n",
120+
" var marker_1_icon = L.AwesomeMarkers.icon({ icon: 'ok-sign',markerColor: 'green',prefix: 'glyphicon' });\n",
121+
" var marker_1 = L.marker([40.67, \n",
122+
"\t\t\t\t\t\t\t-73.94],\n",
123+
"\t\t\t\t\t\t\t{'icon':marker_1_icon}\n",
124+
"\t\t\t\t\t\t\t);\n",
125+
" marker_1.bindPopup(&quot;Add <b>popup</b> text here.&quot;);\n",
126+
" map.addLayer(marker_1)\n",
127+
" \n",
128+
" var marker_2_icon = L.AwesomeMarkers.icon({ icon: 'remove-sign',markerColor: 'red',prefix: 'glyphicon' });\n",
129+
" var marker_2 = L.marker([44.67, \n",
130+
"\t\t\t\t\t\t\t-73.94],\n",
131+
"\t\t\t\t\t\t\t{'icon':marker_2_icon}\n",
132+
"\t\t\t\t\t\t\t);\n",
133+
" marker_2.bindPopup(&quot;Add <b>popup</b> text here.&quot;);\n",
134+
" map.addLayer(marker_2)\n",
135+
" \n",
136+
" var marker_3_icon = L.AwesomeMarkers.icon({ icon: 'info-sign',markerColor: 'blue',prefix: 'glyphicon' });\n",
137+
" var marker_3 = L.marker([44.67, \n",
138+
"\t\t\t\t\t\t\t-71.94],\n",
139+
"\t\t\t\t\t\t\t{'icon':marker_3_icon}\n",
140+
"\t\t\t\t\t\t\t);\n",
141+
" marker_3.bindPopup(&quot;Add <b>popup</b> text here.&quot;);\n",
142+
" map.addLayer(marker_3)\n",
143+
" \n",
144+
"\n",
145+
" \n",
146+
"\n",
147+
" \n",
148+
"\n",
149+
" \n",
150+
"\n",
151+
" </script>\n",
152+
"\n",
153+
"</body>\" style=\"width: 100%; height: 510px; border: none\"></iframe>"
154+
],
155+
"metadata": {},
156+
"output_type": "pyout",
157+
"prompt_number": 24,
158+
"text": [
159+
"<IPython.core.display.HTML at 0x106dadcd0>"
160+
]
161+
}
162+
],
163+
"prompt_number": 24
164+
},
165+
{
166+
"cell_type": "code",
167+
"collapsed": false,
168+
"input": [],
169+
"language": "python",
170+
"metadata": {},
171+
"outputs": []
172+
},
173+
{
174+
"cell_type": "code",
175+
"collapsed": false,
176+
"input": [],
177+
"language": "python",
178+
"metadata": {},
179+
"outputs": []
180+
}
181+
],
182+
"metadata": {}
183+
}
184+
]
185+
}

0 commit comments

Comments
 (0)