import os
import folium
print(folium.__version__)
0.3.0+162.g0540622.dirty
In this notebook we show a few illustrations of folium's plugin extensions.
This is a development notebook
Adds a button to enable/disable zoom scrolling.
from folium import plugins
m = folium.Map([45, 3], zoom_start=4)
plugins.ScrollZoomToggler().add_to(m)
m.save(os.path.join('results', 'Plugins_0.html'))
m
Adds a MarkerCluster layer on the map.
import numpy as np
N = 100
data = np.array(
[
np.random.uniform(low=35, high=60, size=N), # Random latitudes in Europe.
np.random.uniform(low=-12, high=30, size=N), # Random longitudes in Europe.
range(N), # Popups texts are simple numbers.
]
).T
m = folium.Map([45, 3], zoom_start=4)
plugins.MarkerCluster(data).add_to(m)
m.save(os.path.join('results', 'Plugins_1.html'))
m
m = folium.Map([45, 3], zoom_start=1)
plugins.Terminator().add_to(m)
m.save(os.path.join('results', 'Plugins_2.html'))
m
m = folium.Map([30, 0], zoom_start=3)
plugins.BoatMarker(
location=(34, -43),
heading=45,
wind_heading=150,
wind_speed=45,
color='#8f8'
).add_to(m)
plugins.BoatMarker(
location=(46, -30),
heading=-20,
wind_heading=46,
wind_speed=25,
color='#88f'
).add_to(m)
m.save(os.path.join('results', 'Plugins_3.html'))
m
m = folium.Map(location=[41.9, -97.3], zoom_start=4)
plugins.Fullscreen(
position='topright',
title='Expand me',
title_cancel='Exit me',
force_separate_button=True).add_to(m)
m.save(os.path.join('results', 'Plugins_4.html'))
m
from folium import plugins
m = folium.Map(
location=[35.68159659061569, 139.76451516151428],
zoom_start=16
)
# Lon, Lat order.
lines = [
{
'coordinates': [
[139.76451516151428, 35.68159659061569],
[139.75964426994324, 35.682590062684206],
],
'dates': [
'2017-06-02T00:00:00',
'2017-06-02T00:10:00'
],
'color': 'red'
},
{
'coordinates': [
[139.75964426994324, 35.682590062684206],
[139.7575843334198, 35.679505030038506],
],
'dates': [
'2017-06-02T00:10:00',
'2017-06-02T00:20:00'
],
'color': 'blue'
},
{
'coordinates': [
[139.7575843334198, 35.679505030038506],
[139.76337790489197, 35.678040905014065],
],
'dates': [
'2017-06-02T00:20:00',
'2017-06-02T00:30:00'
],
'color': 'green',
'weight': 15,
},
{
'coordinates': [
[139.76337790489197, 35.678040905014065],
[139.76451516151428, 35.68159659061569],
],
'dates': [
'2017-06-02T00:30:00',
'2017-06-02T00:40:00'
],
'color': '#FFFFFF',
},
]
features = [
{
'type': 'Feature',
'geometry': {
'type': 'LineString',
'coordinates': line['coordinates'],
},
'properties': {
'times': line['dates'],
'style': {
'color': line['color'],
'weight': line['weight'] if 'weight' in line else 5
}
}
}
for line in lines
]
plugins.TimestampedGeoJson({
'type': 'FeatureCollection',
'features': features,
}, period='PT1M', add_last_point=True).add_to(m)
m.save(os.path.join('results', 'Plugins_5.html'))
m