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')
I can't use the MarkerCluster and LayerControl together. MarkerCluster groups separately the markers from PKOBP and PEKAOSA.
folium.__version__print(folium.__version__)
0.5.0
I'm not sure I understand your problem. You want to cluster all the markers together? Then how about putting all your markers in a single MarkerCluster? Also, you don't need a FeatureGroup when you're already using a MarkerCluster. For example:
import folium.plugins
m = folium.Map(location=[0, 0], zoom_start=2)
lats = [37.25715519, -31.72884313, -75.27080391, 50.30897559]
lons = [167.20482296, 23.5310324, 164.47413453, 26.87409742]
cluster = folium.plugins.MarkerCluster().add_to(m)
for i in range(0, 4):
folium.Marker(location=[lats[i], lons[i]], popup=str(i)).add_to(cluster)
folium.LayerControl(collapsed=False).add_to(m)
m.save('map.html')
About colors: the MarkerCluster has customization options for the icons, the popups and the cluster icons. Check out the examples in the example gallery:
http://nbviewer.jupyter.org/github/python-visualization/folium/blob/master/examples/MarkerCluster.ipynb
Closing the issue since the problem is not clear. Let us know if you have any updates.
Hi guys, first of all: thanks for the awesome work on folium!
Now to the issue: I have this as well and let me explain what I am trying to achieve:
a) Using MarkerCluster, I am hoping to avoid overloading the map with markers on certain zoom levels - works fine by itself
b) Using FeatureGroup with LayerControl, I am hoping to be able to select only markers of a certain type - again: works well by itself
By combining the two, I was hoping to be able to have all (active) markers in one cluster while being able to choose the active groups via LayerControl. This does not work.
What does work is to put the markers into different marker clusters, but then each of those has its own count for the different zoom levels - not quite what I was hoping for, but still pretty awesome.
Still, the attached screenshot should illustrate the "problem":

So, the gray cloud icon is well within the area of the nearby cluster (of cadetblue ok-signs). Ideally, I would want it to be part of the cluster.
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.
Ok, thanks @Conengmo , I will give that a try. I installed folium from master last weekend, so I should be fine. I will report back after I tried that out.
@Conengmo , you were right, that is exacly what I was looking for and it works the way I had hoped! Thanks to you and all the other contributors!
I like to check for that MarkerCluster, we see those number less than 10 would be green in color and 10 or greater would be orange in color. Is this already fixed? How can we change its color on a custom basis? say I have 3 groups of clusters (8,10 and 29) inside each cluster, and I want those 3 groups of clusters to be of 3 different colors. thanks.
@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!
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
.
Man it worked perfectly! Thank you so much!
No problem.
W dniu czw., 10.09.2020 o 21:09 pabm1808 notifications@github.com
napisał(a):
>
>
Man it worked perfectly! Thank you so much!
—
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-690640341,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AIMLSDX4CUVKREFVLURQPSTSFEQADANCNFSM4EKVRX5Q
.