File: layer_control.md

package info (click to toggle)
folium 0.20.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,168 kB
  • sloc: python: 4,489; makefile: 134; sh: 26
file content (59 lines) | stat: -rw-r--r-- 1,357 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
```{code-cell} ipython3
---
nbsphinx: hidden
---
import folium
```

## LayerControl

Add a control to the map to show or hide layers.

```{code-cell} ipython3
m = folium.Map(tiles=None)

folium.TileLayer("OpenStreetMap", overlay=True).add_to(m)

folium.LayerControl().add_to(m)

m
```

### Common layer arguments

Every layer element in Folium has a couple common arguments:

- `name`: how the layer will be named in the layer control.
- `overlay`: True if the layer is an overlay, False if the layer is a base layer.
  - base layer: only one can be active at a time. Tile layers are base layers by default.
  - overlay: multiple can be active at the same time. `FeatureGroup`s and most non-tile layers are overlays by default.
- `control`: Whether the layer can be controlled in the layer control.
- `show`: Whether the layer will be shown when opening the map.

Next we'll give some examples using a `FeatureGroup`.

### Remove from control

```{code-cell} ipython3
m = folium.Map()

fg = folium.FeatureGroup(name="Icon collection", control=False).add_to(m)
folium.Marker(location=(0, 0)).add_to(fg)

folium.LayerControl().add_to(m)

m
```

### Show manually

```{code-cell} ipython3
m = folium.Map()

fg = folium.FeatureGroup(name="Icon collection", show=False).add_to(m)
folium.Marker(location=(0, 0)).add_to(fg)

folium.LayerControl().add_to(m)

m
```