8

I created a map by using folium.RegularPolygonMarker. But in the LayerControl, I would like to replace "macro_element_6a67a2ea0e4b460fb231fd636c605301" with "My points". Furthermore, I would like the checkbox unchecked by default.

Here my code:

import folium
from folium.plugins import MarkerCluster

points = [[0,0], [10,10], [15,30], [-15,45]]

map=folium.Map(location=[0, 0], zoom_start=4)
marker_cluster = MarkerCluster().add_to(map)
folium.TileLayer('openstreetmap').add_to(map)
folium.TileLayer('Stamen Terrain').add_to(map)
folium.LayerControl().add_to(map)
folium.PolyLine(points, color="black", weight=2.5, opacity=1).add_to(map)

for x in points:
    info = 'test'
    folium.RegularPolygonMarker(location=[x[0], x[1]], popup=info).add_to(marker_cluster)

map.save("Test.html")

enter image description here

H. Dave
  • 549
  • 3
  • 9
  • 26
  • 1
    You want to create a `FeatureGroup` with a `name` and `show` parameter. Then add your points to that FeatureGroup. Maybe polyline too? – Bob Haffner Dec 23 '18 at 01:29

1 Answers1

12

Thank you to @Bob Haffner for his useful hint. The solution is to use the FeatureGroup. Here the answer to my question:

import folium
from folium.plugins import MarkerCluster

points = [[0,0], [10,10], [15,30], [-15,45]]

map=folium.Map(location=[0, 0], zoom_start=4)
fg=folium.FeatureGroup(name='My Points', show=False)
map.add_child(fg)
marker_cluster = MarkerCluster().add_to(fg)
folium.TileLayer('openstreetmap').add_to(map)
folium.TileLayer('Stamen Terrain').add_to(map)
folium.LayerControl().add_to(map)
folium.PolyLine(points, color="black", weight=2.5, opacity=1).add_to(map)

for x in points:
    info = 'test'
    folium.RegularPolygonMarker(location=[x[0], x[1]], popup=info).add_to(marker_cluster)

map.save("Test.html")

enter image description here

H. Dave
  • 549
  • 3
  • 9
  • 26