Reputation: 31
I want to have a custom markers on the map and unique popups for every markered dot. The code below gives me what I want except for the fact that there are two markers for each dot - my custom and default one. How to leave only mine? Why there are two markers?
fg_other_atms = folium.FeatureGroup(name="Other ATMs", show=False)
geometry = gpd.points_from_xy(atm_other.longitude, atm_other.latitude)
geo_df = gpd.GeoDataFrame(atm_other[['latitude', 'longitude', 'city_id',
'region_id', 'trans_cnt','trans_amt']],
geometry=geometry)
geo_df = geo_df.set_crs(epsg=4326, inplace=True)
gjson = folium.GeoJson(geo_df)
for feature in gjson.data['features']:
folium.Marker(location=list(reversed(feature['geometry']['coordinates'])),
icon=folium.features.CustomIcon('Icons/red.png', icon_size=(26, 35))
).add_to(fg_other_atms)
if feature['geometry']['type'] == 'Point':
b = folium.GeoJson(feature['geometry'])
popup = '<b>Кол-во операции</b> ' + str(feature['properties']['trans_cnt'])+ ' ' + '<br><b>Сумма снятий</b> ' + str(feature['properties']['trans_amt'])
b.add_child(folium.Popup(popup))
fg_other_atms.add_child(b)
m.add_child(fg_other_atms)
Upvotes: 2
Views: 255
Reputation: 31
It can be done this way:
fg_other_atms = folium.FeatureGroup(name="Other ATMs", show=False)
geometry = gpd.points_from_xy(atm_other.longitude, atm_other.latitude)
geo_df = gpd.GeoDataFrame(atm_other[['latitude', 'longitude', 'city_id',
'region_id', 'trans_cnt','trans_amt']],
geometry=geometry)
geo_df = geo_df.set_crs(epsg=4326, inplace=True)
for row in geo_df.iterrows():
row_values = row[1]
location = [row_values['geometry'].y, row_values['geometry'].x]
popup = '<b>Кол-во операции</b> ' + str(row_values['trans_cnt'])+ ' ' + '<br><b>Сумма снятий</b> ' + str(row_values['trans_amt'])
marker = folium.Marker(location=location,
icon=folium.features.CustomIcon('Icons/red.png', icon_size=(26, 35)),
popup = popup)
marker.add_to(fg_other_atms)
Upvotes: 1