question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MarkerCluster and FeatureGroup don't work properly together.

See original GitHub issue

    import pandas as pd
    import folium
    from folium.features import CustomIcon
    from folium.plugins import MarkerCluster
    
    df1 = pd.read_csv("/home/dominik/projekt/results/pkobp.csv")
    df2 = pd.read_csv("/home/dominik/projekt/results/pekao.csv")
    
    logo_PKOBP = 'https://upload.wikimedia.org/wikipedia/commons/8/8d/Logotyp_PKO_BP.svg'
    logo_PEKAO = 'https://upload.wikimedia.org/wikipedia/commons/e/ee/Bank_Pekao_SA_Logo_%282017%29.svg'
    
    frames = [df1, df2]
    
    locationlist1 = df1[["Szerokość","Długość"]].values.tolist()
    locationlist2 = df2[["Szerokość","Długość"]].values.tolist()
    
    m = folium.Map(location=[52.2138, 20.9795], zoom_start=12, control_scale=True)
    
    pkobp_layer = folium.FeatureGroup(name="PKO BP SA")
    marker_cluster = MarkerCluster().add_to(pkobp_layer)
    for point in range(len(locationlist1)):
        PKOBP = folium.Marker(locationlist1[point], icon=CustomIcon(logo_PKOBP, icon_size=(40, 40))).add_to(marker_cluster)
    
    pekao_layer = folium.FeatureGroup(name="PEKAO SA")
    marker_cluster = MarkerCluster().add_to(pekao_layer)
    for point in range(len(locationlist2)):
        PEKAOSA = folium.Marker(locationlist2[point], icon=CustomIcon(logo_PEKAO, icon_size=(150, 22))).add_to(marker_cluster)
    
    m.add_child(pkobp_layer)
    m.add_child(pekao_layer)
    
    m.add_child(folium.map.LayerControl())
    
    m.save('/home/dominik/mapa1.html')

Problem description

I can’t use the MarkerCluster and LayerControl together. MarkerCluster groups separately the markers from PKOBP and PEKAOSA.

  1. Can someone tell me what is wrong in my code?
  2. Is it possible to change colors in MarkerCluster?

Expected Output

  1. I would like the markers to be grouped together. (the most important)
  2. If possible, I would like to change the colors, increase the number of shades.

Output of folium.__version__

print(folium.version) 0.5.0

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11

github_iconTop GitHub Comments

3reactions
Conengmocommented, Jun 19, 2018

Hi @dspyrhsu, good news, we very recently added a feature that should do just what you need. It is in #875 and is a plugin called FeatureGroupSubGroup. The second example in the docstring is I think what you need, ‘Multiple overlays part of the same cluster group’. Just make sure you get the most recent version of folium from the git master branch. Hope that helps.

1reaction
BigDomicommented, Sep 10, 2020

Hi,

Hi, You can see my final code at this link https://nbviewer.jupyter.org/urls/hugedot.pl/projekt_studia/projekt/wizualizacja/mapa.ipynb I hope you will find it useful.

Best regards, Dominik

W dniu czw., 10.09.2020 o 20:41 pabm1808 notifications@github.com napisał(a):

@dspyrhsu https://github.com/dspyrhsu Hi! I am having the same troblue, would you be so kind to share the code you used at end? Thanks a lot in advance!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/python-visualization/folium/issues/809#issuecomment-690611972, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIMLSDWY7BWNGXB37RWZHOLSFEMUNANCNFSM4EKVRX5Q .

Read more comments on GitHub >

github_iconTop Results From Across the Web

Folium marker clusters not working as expected - Stack Overflow
I have a problem. I can't use the MarkerCluster and LayerControl together. I need to add the MarkerCluster to the following code but ......
Read more >
Python folium markercluster doesn't work as expected for the ...
I would like to clusterize my points. Unfortunately I cannot do it with my code it loos like. import pandas as pd import...
Read more >
Leaflet.markercluster | Marker Clustering plugin for Leaflet
Leaflet.markercluster. Provides Beautiful Animated Marker Clustering functionality for Leaflet, a JS library for interactive maps. Requires Leaflet 1.0.0.
Read more >
How to provide marker clustering on the Leaflet map in the ...
In this text, I'm going to show you how you can achieve it in your Angular project using the Leaflet map with Leaflet.markercluster...
Read more >
Examples of plugins usage in folium - | notebook.community
MarkerCluster. Adds a MarkerCluster layer on the map. ... To work properly in production, the connection needs to be encrypted (HTTPS), otherwise browser ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found