Skip to content

Commit d19a8f4

Browse files
birdageocefpaf
authored andcommitted
add example wms/tile notebook
1 parent 26f9668 commit d19a8f4

File tree

1 file changed

+236
-0
lines changed

1 file changed

+236
-0
lines changed

examples/test_folium_wms.ipynb

Lines changed: 236 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,236 @@
1+
{
2+
"metadata": {
3+
"name": "",
4+
"signature": "sha256:dc08dcf599a6125d21802a4b1c8fe771a27c265b89aee5fe9fff72c4074e21db"
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": 1
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=\"map.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": 2
51+
},
52+
{
53+
"cell_type": "code",
54+
"collapsed": false,
55+
"input": [
56+
"map = folium.Map(width=800,height=600,location=[44, -73], zoom_start=3)\n",
57+
"\n",
58+
"map.add_wms_layer(wms_name=\"Temperature\",\n",
59+
" wms_url=\"http://gis.srh.noaa.gov/arcgis/services/NDFDTemps/MapServer/WMSServer\",\n",
60+
" wms_format=\"image/png\",\n",
61+
" wms_layers= 16\n",
62+
" )\n",
63+
"\n",
64+
"map.add_tile_layer(tile_name='hfradar 1km',\n",
65+
" tile_url='http://hfradar.ndbc.noaa.gov/tilesavg.php?s=10&e=100&x={x}&y={y}&z={z}&t=2014-8-18 14:00:00&rez=1')\n",
66+
"map.add_tile_layer(tile_name='hfradar 2km',\n",
67+
" tile_url='http://hfradar.ndbc.noaa.gov/tilesavg.php?s=10&e=100&x={x}&y={y}&z={z}&t=2014-8-18 14:00:00&rez=2')\n",
68+
"map.add_tile_layer(tile_name='hfradar 6km',\n",
69+
" tile_url='http://hfradar.ndbc.noaa.gov/tilesavg.php?s=10&e=100&x={x}&y={y}&z={z}&t=2014-8-18 14:00:00&rez=6')\n",
70+
"\n",
71+
"map.add_layers_to_map()"
72+
],
73+
"language": "python",
74+
"metadata": {},
75+
"outputs": [],
76+
"prompt_number": 3
77+
},
78+
{
79+
"cell_type": "code",
80+
"collapsed": false,
81+
"input": [
82+
"inline_map(map) "
83+
],
84+
"language": "python",
85+
"metadata": {},
86+
"outputs": [
87+
{
88+
"html": [
89+
"<iframe srcdoc=\"<!DOCTYPE html>\n",
90+
"<head>\n",
91+
" <meta http-equiv=&quot;content-type&quot; content=&quot;text/html; charset=UTF-8&quot; />\n",
92+
" <link rel=&quot;stylesheet&quot; href=&quot;http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css&quot; />\n",
93+
" <script src=&quot;http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js&quot;></script>\n",
94+
"\n",
95+
" <script src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js&quot;></script>\n",
96+
"\n",
97+
" <link rel=&quot;stylesheet&quot; href=&quot;//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css&quot;>\n",
98+
" <link rel=&quot;stylesheet&quot; href=&quot;//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css&quot;>\n",
99+
" <script src=&quot;//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js&quot;></script>\n",
100+
"\n",
101+
" <link href=&quot;//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css&quot; rel=&quot;stylesheet&quot;>\n",
102+
"\n",
103+
" <link rel=&quot;stylesheet&quot; href=&quot;https://rawgit.com/lvoogdt/Leaflet.awesome-markers/2.0/develop/dist/leaflet.awesome-markers.css&quot;>\n",
104+
" <script src=&quot;https://rawi.8713187.xyz/lvoogdt/Leaflet.awesome-markers/2.0/develop/dist/leaflet.awesome-markers.js&quot;></script>\n",
105+
"\n",
106+
"\n",
107+
" <link rel=&quot;stylesheet&quot; href=&quot;//cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/MarkerCluster.Default.css&quot;>\n",
108+
" <link rel=&quot;stylesheet&quot; href=&quot;//cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/MarkerCluster.css&quot;>\n",
109+
" <script src=&quot;//cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/leaflet.markercluster-src.js&quot;></script>\n",
110+
" <script src=&quot;//cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/leaflet.markercluster.js&quot;></script>\n",
111+
"\n",
112+
" <link rel=&quot;stylesheet&quot; href=&quot;http://birdage.github.io/Leaflet.awesome-markers/dist/leaflet.awesome.rotate.css&quot;>\n",
113+
"\n",
114+
" \n",
115+
" \n",
116+
" \n",
117+
" \n",
118+
"\n",
119+
" <style>\n",
120+
"\n",
121+
" #map {\n",
122+
" position:absolute;\n",
123+
" top:0;\n",
124+
" bottom:0;\n",
125+
" right:0;\n",
126+
" left:0;\n",
127+
" }\n",
128+
"\n",
129+
" </style>\n",
130+
"</head>\n",
131+
"\n",
132+
"<body>\n",
133+
"\n",
134+
" <div class=&quot;folium-map&quot; id=&quot;folium_924324a0e0ff4353b8d1bef52a7ed0a5&quot; style=&quot;width: 800px; height: 600px&quot;></div>\n",
135+
"\n",
136+
" <script>\n",
137+
"\n",
138+
" \n",
139+
"\n",
140+
" var base_tile = L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {\n",
141+
" maxZoom: 18,\n",
142+
" attribution: 'Map data (c) <a href=&quot;http://openstreetmap.org&quot;>OpenStreetMap</a> contributors'\n",
143+
" });\n",
144+
"\n",
145+
" var baseLayer = { \n",
146+
" &quot;Base Layer&quot;: base_tile\n",
147+
" };\n",
148+
"\n",
149+
" /*\n",
150+
" addition of the wms layers\n",
151+
" */ \n",
152+
"\n",
153+
" \n",
154+
" var Temperature = L.tileLayer.wms('http://gis.srh.noaa.gov/arcgis/services/NDFDTemps/MapServer/WMSServer',{format:'image/png',transparent: true,layers:'16'});\n",
155+
" \n",
156+
" \n",
157+
" /*\n",
158+
" addition of the tile layers\n",
159+
" */\n",
160+
" \n",
161+
" var hfradar_1km = L.tileLayer('http://hfradar.ndbc.noaa.gov/tilesavg.php?s=10&e=100&x={x}&y={y}&z={z}&t=2014-8-18 14:00:00&rez=1');\n",
162+
" \n",
163+
" var hfradar_2km = L.tileLayer('http://hfradar.ndbc.noaa.gov/tilesavg.php?s=10&e=100&x={x}&y={y}&z={z}&t=2014-8-18 14:00:00&rez=2');\n",
164+
" \n",
165+
" var hfradar_6km = L.tileLayer('http://hfradar.ndbc.noaa.gov/tilesavg.php?s=10&e=100&x={x}&y={y}&z={z}&t=2014-8-18 14:00:00&rez=6');\n",
166+
" \n",
167+
"\n",
168+
" /*\n",
169+
" list of layers to be added\n",
170+
" */ \n",
171+
" var layer_list = {\n",
172+
" \n",
173+
" &quot;Temperature&quot;: Temperature,\n",
174+
"&quot;hfradar_1km&quot;: hfradar_1km,\n",
175+
"&quot;hfradar_2km&quot;: hfradar_2km,\n",
176+
"&quot;hfradar_6km&quot;: hfradar_6km\n",
177+
"\n",
178+
" \n",
179+
" };\n",
180+
"\n",
181+
" /*\n",
182+
" Creates the map and adds the selected layers\n",
183+
" */\n",
184+
" var map = L.map('folium_924324a0e0ff4353b8d1bef52a7ed0a5', {\n",
185+
" center:[44, -73],\n",
186+
" zoom: 3,\n",
187+
" layers: [base_tile]\n",
188+
" });\n",
189+
"\n",
190+
" L.control.layers(baseLayer, layer_list).addTo(map);\n",
191+
"\n",
192+
" //cluster group\n",
193+
" var clusteredmarkers = L.markerClusterGroup();\n",
194+
" //section for adding clustered markers\n",
195+
" \n",
196+
" //add the clustered markers to the group anyway\n",
197+
" map.addLayer(clusteredmarkers);\n",
198+
"\n",
199+
" \n",
200+
"\n",
201+
" \n",
202+
"\n",
203+
" \n",
204+
"\n",
205+
" \n",
206+
"\n",
207+
" \n",
208+
"\n",
209+
" </script>\n",
210+
"\n",
211+
"</body>\" style=\"width: 100%; height: 510px; border: none\"></iframe>"
212+
],
213+
"metadata": {},
214+
"output_type": "pyout",
215+
"prompt_number": 4,
216+
"text": [
217+
"<IPython.core.display.HTML at 0x11469a090>"
218+
]
219+
}
220+
],
221+
"prompt_number": 4
222+
},
223+
{
224+
"cell_type": "code",
225+
"collapsed": false,
226+
"input": [],
227+
"language": "python",
228+
"metadata": {},
229+
"outputs": [],
230+
"prompt_number": 4
231+
}
232+
],
233+
"metadata": {}
234+
}
235+
]
236+
}

0 commit comments

Comments
 (0)