#!/usr/bin/env python # coding: utf-8 # In[1]: import os import folium print(folium.__version__) # In[2]: import pandas as pd df = pd.DataFrame.from_csv( os.path.join('data', 'highlight_flight_trajectories.csv') ) # Let us take a glance at the data. # Each row represents the trajectory of a flight, # and the last column contains the coordinates of the flight path in `GeoJSON` format. # In[3]: df # In[4]: m = folium.Map( location=[40, 10], zoom_start=4, control_scale=True, prefer_canvas=True ) def style_function(feature): return { 'fillColor': '#ffaf00', 'color': 'blue', 'weight': 1.5, 'dashArray': '5, 5' } def highlight_function(feature): return { 'fillColor': '#ffaf00', 'color': 'green', 'weight': 3, 'dashArray': '5, 5' } for index, row in df.iterrows(): c = folium.GeoJson( row['geojson'], name=('{}{}'.format(row['dep'], row['dest'])), overlay=False, style_function=style_function, highlight_function=highlight_function ) folium.Popup('{}\n{}'.format(row['dep'], row['dest'])).add_to(c) c.add_to(m) folium.LayerControl().add_to(m) m.save(os.path.join('results', 'Highlight_Function.html')) m