I want to create an onclick event listener to my folium map which is currently marked with locations and popup being the location name and whenever the marker is clicked i want to retrieve the popup and get the popup flows from another data frame and draw the ant path for those flows. Example: if the marker is clicked on location x it needs to fetch all the flows from the other data frame say df2 like x to y, x to z and after fetching all those flows it needs to create an ant path for those flows fetched. can anyone create a sample code for the same thanks :) It needs to create an antiflow for those locations fetched when a marker is clicked
import pandas as pd
import folium
from folium.plugins import HeatMap
from folium.map import Marker, Template
def on_marker_click(e):
popup = e.target.get_popup()
location_name = popup.get_children()[0].get_content()
flows = df2[df2['stock_loc_id_x'] == location_name]
if len(flows) > 0:
points = []
for index, row in flows.iterrows():
points.append([row['LATITUDE1'], row['LONGITUDE1']])
points.append([row['LATITUDE2'], row['LONGITUDE2']])
folium.PolyLine(points, color='red', tooltip='<br>'.join([f'{col}: {{flows["{col}"]}}' for col in ['ND_Score', 'SD_Score', 'ND_Volume', 'SD_Volume']]),
smooth_factor=1.0).add_to(map)
map = folium.Map(prefer_canvas=True)
def plotDot(point):
folium.Marker(location=[point.LATITUDE1, point.LONGITUDE1],
radius=2,
color='blue',
popup=folium.Popup(point.stock_loc_id),
weight=5,
).add_to(map)
gps.apply(plotDot, axis=1)
map
folium.TileLayer('CartoDB dark_matter').add_to(map)
folium.LayerControl().add_to(map)
map