-
Notifications
You must be signed in to change notification settings - Fork 0
/
folium-map.py
66 lines (55 loc) · 2.38 KB
/
folium-map.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Ireland map
#!pip install folium
#!pip install branca
import folium
from folium import IFrame
import branca
import pandas as pd
# initialing folium base map for Ireland
# Make an empty map
#m = folium.Map(location=[53.350496, -6.239456], zoom_start=7, tiles='Stamen Toner', max_bounds=True, scrollWheelZoom = False)
m = folium.Map(location=[53.350496, -6.239456], zoom_start=7, tiles='OpenStreetMap', max_bounds=True, scrollWheelZoom = False)
# reading dataset
data = pd.read_csv('data.csv')
# frame url popup function
def get_frame(url,width,height):
html = """
<!doctype html>
<html>
<iframe id="myIFrame" width="{}" height="{}" src={}""".format(width,height,url) + """ frameborder="0"></iframe>
<script type="text/javascript">
var resizeIFrame = function(event) {
var loc = document.location;
if (event.origin != loc.protocol + '//' + loc.host) return;
var myIFrame = document.getElementById('myIFrame');
if (myIFrame) {
myIFrame.style.height = event.data.h + "px";
myIFrame.style.width = event.data.w + "px";
}
};
if (window.addEventListener) {
window.addEventListener("message", resizeIFrame, false);
} else if (window.attachEvent) {
window.attachEvent("onmessage", resizeIFrame);
}
</script>
</html>"""
return html
for i in range(0,len(data)):
width, height = 900, 500
html = get_frame(data.iloc[i]['url'], width, height)
iframe = IFrame(html=html , width=width, height=height)
popup = folium.Popup(iframe, parse_html = True)
folium.Marker([data.iloc[i]['lon'], data.iloc[i]['lat']], icon=folium.Icon(color='black', icon='anchor', prefix='fa'),
popup=popup).add_to(m)
title_html = '''
<h1 align="left" style="color:red"><b>The Great Irish Lighthouses</b></h1>
<h4><a target="_blank" rel="noopener noreferrer" href="https://github.com/vinejain/great-irish-lighthouses">(view code)</a></h4>
<body style="background-color:black;">
'''
m.get_root().html.add_child(folium.Element(title_html))
# Save it as html
m.save('great-irish-lighthouses.html')
m
# from google.colab import files
# files.download('312_markers_on_folium_map1.html')