I created a map using folium and python, which show the path of GPX files. The starting point of each gpx track is located by using a marker. Since there are several paths, they may be overlaid on each other. I'd like to select only one starting point (markers) and when the marker is clicked, the track appears.
Here is a picture of my issue in order to better understand the situation.
How can I just show a basic straight line when clicking on the marker (made with folium.PolyLine like the gpx files) ?
I've found a partially solution here, but I am not familiar at all with the antpath and it's not my point.
I guess the following part of the thread above, especially the "coords" and "ant_path" variables, has to be adapted but I don't know how.
# Create the onClick listener function as a branca element and add to the map html
map_id = dmap.get_name()
click_js = f"""function onClick(e) {{
var coords = e.target.options.pathCoords;
//var coords = JSON.stringify(coords);
//alert(coords);
var ant_path = L.polyline.antPath(coords, {{
"delay": 400,
"dashArray": [
10,
20
],
"weight": 5,
"color": "#0000FF",
"pulseColor": "#FFFFFF",
"paused": false,
"reverse": false,
"hardwareAccelerated": true
}});
{map_id}.eachLayer(function(layer){{
if (layer instanceof L.Polyline)
{{ {map_id}.removeLayer(layer) }}
}});
ant_path.addTo({map_id});
}}"""
e = folium.Element(click_js)
html = dmap.get_root()
html.script.add_child(e)
# add geo markers
for index, data in df.iterrows():
mrk = folium.Marker(data['geo'], pathCoords=data['geo_path'])
mrk.add_to(mcsub1)
# Add leaflet antpath plugin cdn link
link = folium.JavascriptLink("https://cdn.jsdelivr.net/npm/leaflet-ant-path@1.3.0/dist/leaflet-ant-path.js")
dmap.get_root().html.add_child(link)
# show map
Any help would be appreciate ! Thanks in advance ;)