Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

240
Views
Python Leaflet/Folium how to create a layer control that also divides markers by colours?

I'm trying to add a layer control for data related to a specific column in my dataset. There are 5 types of it, and I would like people to be able to filter the markers and also see them divided into different colours. There are lots of resources but somehow the examples are either too simple or too complex. My code so far:

it_coords = [41.902782 , 12.496366]
m = folium.Map(location=it_coords, zoom_start=6,tiles='openstreetmap')
cluster = folium.plugins.MarkerCluster(name="Monumenti").add_to(m)


for i in range(0,len(df)):
    html=f"""
        <h2> {df.iloc[i]['Titolo']}</h2>
        """
    iframe = folium.IFrame(html=html, width=200, height=200)
    popup = folium.Popup(iframe, max_width=2650)
    for grp_name, df_grp in df.groupby('Tipologia personaggio'):
        feature_group = folium.FeatureGroup(grp_name)
        feature_group.add_to(m)

    folium.Marker(
        location=[df.iloc[i]['Latitude'], df.iloc[i]['Longitude']],
        popup=popup
    ).add_to(m)

folium.LayerControl().add_to(m)
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!