|
2 | 2 |
|
3 | 3 | The `Search` plugin allows you to search in your `GeoJson`, `TopoJson`, `FeatureGroup` or `MarkerCluster` objects.
|
4 | 4 |
|
5 |
| -## Data |
| 5 | +## Search in GeoJSON |
| 6 | + |
| 7 | +### Data |
6 | 8 |
|
7 | 9 | Let's get some JSON data from the web - both a point layer and a polygon GeoJson dataset with some population data.
|
8 | 10 |
|
@@ -89,7 +91,7 @@ Ok, now we have a new GeoDataFrame with our top 20 populated cities. Let's see t
|
89 | 91 | pop_ranked_cities.head(5)
|
90 | 92 | ```
|
91 | 93 |
|
92 |
| -## Map with Search plugin |
| 94 | +### Map with Search plugin and GeoJSON data |
93 | 95 |
|
94 | 96 | Alright, let's build a map!
|
95 | 97 |
|
@@ -149,3 +151,25 @@ colormap.add_to(m)
|
149 | 151 |
|
150 | 152 | m
|
151 | 153 | ```
|
| 154 | + |
| 155 | +## Search in FeatureGroup |
| 156 | + |
| 157 | +Here's an example how to search `Marker`s in a `FeatureGroup`. Note how we |
| 158 | +add an extra field to each `Marker` that is then used to search on. |
| 159 | + |
| 160 | + |
| 161 | +```{code-cell} ipython3 |
| 162 | +from folium import Map, FeatureGroup, Marker, Icon |
| 163 | +from folium.plugins import Search |
| 164 | +
|
| 165 | +m = Map((45.5236, -122.5), tiles="carto db positron") |
| 166 | +
|
| 167 | +fg = FeatureGroup().add_to(m) |
| 168 | +Marker([45.5236, -122.7], icon=Icon(color="red"), title="red").add_to(fg) |
| 169 | +Marker([45.5236, -122.5], icon=Icon(color="blue"), title="blue").add_to(fg) |
| 170 | +Marker([45.5236, -122.3], icon=Icon(color="green"), title="green").add_to(fg) |
| 171 | +
|
| 172 | +Search(fg, search_label="title").add_to(m) |
| 173 | +
|
| 174 | +m |
| 175 | +``` |
0 commit comments