Skip to content

implementing onClick event for CircleMarker in folium #1613

@FarooqAbbas

Description

@FarooqAbbas

I am making a folium map where I have some CircleMarker.
These CircleMarkers are based on GPS(latitude,longitude).

I already know how to make popup. But I want to add onClick event to CircleMarker.
The reason to add onClick event to CircleMarker is: I want to display the data hold by each CircleMarker in a separate HTML div.
Note: The CircleMarker are based on data from dataframe.

import folium
from branca.element import Element
m = folium.Map(location=[lat,lon],zoom_start=15,control_scale=True)
mk =folium.CircleMarker(location=[lat,long],
radius=7,fill=True,
opacity=0.8,fill_opacity=1).add_to(m)
map_id = m.get_name()

my_js = '''
onclick = function(){ console.log('I am clicked'); }
}
'''
mk.get_root().script.add_child(Element(my_js))
m.save('mymap.html')

If I click on the map I get the output 'I am clicked'.
What I need is that I want to get the output in console when I click CircleMarker.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementFeature request or idea about how to make folium better

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions