Reputation: 53
I want to have a bunch of points in the map, with a red Icon and with some text as a popup when you click on it. I need to use features.GeoJson, because I'll create also a Search on a specific layer, so I can't use features.Marker.
I checked this examples: https://nbviewer.jupyter.org/github/python-visualization/folium/tree/master/examples/ But They don't say what key of the properties dictionary of each point change this color. Regarding the popup, even though I add it as a child it doesn't work.
Here the code:
import folium
from folium import features
m = folium.Map([0, 0], zoom_start=1)
points_ = {'type': 'FeatureCollection',
'features': [{'type': 'Feature',
'properties': {'Codice': 500732, 'Categoria': 'D1', 'Cluster': 3},
'geometry': {'type': 'Point', 'coordinates': [12.34117475, 45.75345246]},
'id': '0'},
{'type': 'Feature',
'properties': {'Codice': 500732, 'Categoria': 'A2', 'Cluster': 3},
'geometry': {'type': 'Point', 'coordinates': [12.34117475, 45.75345246]},
'id': '1'}]}
pp = folium.Popup("hello")
ic = features.Icon(color="red")
gj = folium.GeoJson(points)#, tooltip=tooltip)
gj.add_child(ic)
gj.add_child(pp)
m.add_child(gj)
m
Upvotes: 5
Views: 3999
Reputation: 2702
The standard icon just loads from https://cdn.jsdelivr.net/npm/[email protected]/dist/images/marker-icon.png
So either you can change its color by using something like this
or you can use a different built-in icon instead:
points = {'type': 'FeatureCollection',
'features': [{'type': 'Feature',
'properties': {'Codice': 500732, 'Categoria': 'D1', 'Cluster': 3},
'geometry': {'type': 'Point', 'coordinates': [12.34117475, 45.75345246]},
'id': '0'},
{'type': 'Feature',
'properties': {'Codice': 500732, 'Categoria': 'A2', 'Cluster': 3},
'geometry': {'type': 'Point', 'coordinates': [12.32117475, 45.72345246]},
'id': '1'}]}
gj = folium.GeoJson(points)
feature_group = folium.FeatureGroup('markers')
for feature in gj.data['features']:
if feature['geometry']['type'] == 'Point':
folium.Marker(location=list(reversed(feature['geometry']['coordinates'])),
icon=folium.Icon(color='red'),
popup='Hello',
Categoria=feature['properties']['Categoria']
).add_to(feature_group)
feature_group.add_to(m)
Search(
layer=feature_group,
search_label="Categoria",
).add_to(m)
m
Upvotes: 1