Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make routes tickable inside a layer on a map with folium

I'm creating a program with Python that finds the best routes for workers. It display a map with their itinerary and time of itinerary. I have 3 layers, one for each transport car, metro and bike. When i tick or unticked them it display or erase them from the map. I would like to have the same features but with the duration of the run. Like if there was layers inside each one of the first 3 layers.

layerVoiture = folium.FeatureGroup(name=description, overlay=False, control=True)

Some code describing the layer :

layerVoiture.add_to(myMap)
mapTile = folium.TileLayer(tiles='OpenStreetMap') #StamenToner
mapTile.add_to(layerVoiture)

it displays this i would like to make the left part, where the duration of runs are displayed, tickable or untickable

Layout

Thanks for your help

like image 898
Emile Joudet Avatar asked Nov 07 '22 15:11

Emile Joudet


1 Answers

you can use FeatureGroupSubGroup to create groups within your FeatureGroup.

For example:

from folium import plugins
group_0_15 = plugins.FeatureGroupSubGroup(layerVoiture, name="De 0 à 15 minutes", show=False, overlay=False)

I am working on something similar and still have one issue: I can't combine radio buttons (set with overlay=False) and check boxes (set with overlay=True) in the legend (LayerControl). They are in two seperate areas in the legend. Here is an example.

So if you only want to use radio buttons or check boxes, it should work. In my case, I am using only check boxes even though it is not exactly what I was looking for. Here is what I achieved, by creating 3 sub-groups in each group.

I hope it still helped!

like image 149
zhavorsa Avatar answered Nov 14 '22 22:11

zhavorsa