import folium
from folium import plugins
import folium_legend
EsriImagery = "https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"
EsriAttribution = "Tiles © Esri — Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community"
# Create Folium map
m = folium.Map(
location=[10, 45],
zoom_start=3, min_zoom=1, max_bounds=True,
control_scale=True, # Adds distance scale in lower left corner
tiles='openstreetmap',
)
def station_status(time_period):
if time_period.endswith('-'):
return 'Active'
color = '#008000' # Green for active stations
elif (time_period == '') | time_period.endswith('?'):
return 'Unknown'
else:
return 'Inactive'
stations['Status'] = stations['Time period'].map(station_status)
status_dict = {
'Active': '#008000', # Green for active stations
'Unknown': '#3186cc', # Blue for stations with unknown status
'Inactive': '#ff422b', # Red for inactive stations
}
stations['Color'] = stations['Status'].map(status_dict)
# Add each station to the map
for index, row in stations.iterrows():
folium.CircleMarker(
location=[row['Latitude'], row['Longitude']],
popup=row['Station name'] + ' - ' + str(row['State']) + ' ' + row['Country'],
tooltip=row['Abbreviation'],
radius=5, color=row['Color'],
fill_color=row['Color'], fill=True).add_to(m)
folium.raster_layers.TileLayer(EsriImagery, name='World imagery', attr=EsriAttribution, show=False).add_to(m)
folium.LayerControl(position='topright').add_to(m)
# Additional options and plugins
# Note it's not possible to change the position of the scale
#plugins.MiniMap(toggle_display=True, zoom_level_fixed=3, minimized=True, position='bottomright').add_to(m) # Add minimap to the map
plugins.Fullscreen(position='bottomright').add_to(m) # Add full screen button to map
folium.LatLngPopup().add_to(m) # Show latitude/longitude when clicking on the map
# plugins.LocateControl(position='topright').add_to(m) # Add button for your position
# plugins.MeasureControl(position='topleft').add_to(m) # Add distance length measurement tool
# Create legend
legend = folium_legend.make_legend(status_dict.keys(), status_dict.values(), title="Station status")
m.get_root().html.add_child(legend) # Add Legend to map
# Show the map
m