0

I have the cluster defined, which I would like to have visible just when hovered (or clicked), therefore I tried to combine it with tooltip or popup. Unfortunately, it didn't work.

My code looks as follows:

 df = pd.read_csv("survey.csv")
 for i,row in df.iterrows():
 lat =df.at[i, 'lat']
 lng = df.at[i, 'lng']
 sp = df.at[i, 'sp']
 phone = df.at[i, 'phone']

 popup = '<b>Phone: </b>' + str(df.at[i,'phone'])
 job_range = folium.Circle([lat,lng],
        # 20 miles = 32186m
        radius=32186,
        popup= df.at[i, 'sp'],
        tooltip = sp + ' - Job limits',
        color='#1565C0',
        fill=True,
        fill_color='#42A5F5',
        opacity=0.2,
        fill_opacity=0.25,
      )
    fs.add_child(
    folium.Marker(location=[lat,lng],
                  tooltip='<strong>Contact surveyor</strong>',
                  #tooltip = job_range,
                  tooltip = popup,
                  popup=popup,
                  #popup = job_range,
                  icon = folium.Icon(color='black', icon='glyphicon-user'
                                     )
                )
    )

map.add_child(fs)

Another code looks like this:

 df = pd.read_csv("survey.csv")
 for i,row in df.iterrows():
 lat =df.at[i, 'lat']
 lng = df.at[i, 'lng']
 sp = df.at[i, 'sp']
 phone = df.at[i, 'phone']

  popup = '<b>Phone: </b>' + str(df.at[i,'phone'])
  
  fs.add_child(
    folium.Marker(location=[lat,lng],
                  tooltip='<strong>Contact surveyor</strong>',
                  #tooltip = job_range,
                  #tooltip = popup,
                  popup=popup,
                  #popup = job_range,
                  icon = folium.Icon(color='black', icon='glyphicon-user'
                                     )
                )
    )
  fs.add_child (
    folium.Marker(location=[lat,lng],
                  popup=popup,
                  icon = folium.DivIcon(html="<b>" + sp + "</b>", class_name="mapText")
                )
    )
  fs.add_child (
    folium.Circle([lat,lng],
        # 20 miles = 32186m
        radius=32186,
        popup= df.at[i, 'sp'],
        tooltip = sp + ' - Job limits',
        color='#1565C0',
        fill=True,
        fill_color='#42A5F5',
        opacity=0.2,
        fill_opacity=0.25,
      )
    )


 map.add_child(fs)

But in this case, I see all circles overlapping each other.

enter image description here

I saw other solutions, which in general didn't help

Hover in popup in Folium

Is there an opportunity to have the circles visible just when the markers are hovered & clicked?

Geographos
  • 827
  • 2
  • 23
  • 57
  • I applied your code using the data from the previous question. The marker cluster values overlap because two different markers and a circle are drawn at the same coordinates. I believe this is the same thing that happens with your data. I am not sure what you want the final graph to look like, I will expand it into [Colab](https://colab.research.google.com/drive/1YJJB11kB0uz3C8PWV_IyM9yUWDFCydEL?usp=sharing) so you can check it out. You may use this content to update your question. – r-beginners Nov 03 '22 at 07:31
  • Thank you very much. I saw your code, but it's not what I am looking for. I want to have the circle visible once I click on the marker in the middle. Is it possible with Folium? – Geographos Nov 03 '22 at 15:42
  • 1
    This cannot be done with the Folium API alone. You need JS code. See [this question](https://stackoverflow.com/questions/60479995/adding-javascript-to-folium-map) for adding custom JS code. You can use the addLayer() and removeLayer() methods of a map. – relent95 Nov 12 '22 at 13:25
  • This might be a good hint! Thank you! – Geographos Nov 14 '22 at 10:09

0 Answers0