我正在尝试使用
geocoder
更改默认的 folium
图标。
我认为使用像
i = folium.Icon(color='black')
这样的东西会起作用,因为我使用类似的代码来更改其他标记的图标。
但是代码似乎没有响应。
我错过了什么?
from folium.plugins import Geocoder
def list_venues(request):
venue_markers = Venue.objects.filter(venue_active=True)
center_location = [average_latitude,average_longitude]
#center_zoom_start=
tiles_style = 'Stamen Terrain'
m = folium.Map(location=center_location,tiles=tiles_style)
m.fit_bounds([[min_latitude, min_longitude], [max_latitude, max_longitude]])
icon_location= folium.Icon(color='black')
icon_location_json = json.loads(icon_location.to_json())
Geocoder(icon=icon_location_json).add_to(m)
m_access = folium.Map(location=center_location,tiles=tiles_style)
for venue in venue_markers:
iframe = branca.element.IFrame(html=html, width=150, height=60)
popup=folium.Popup(iframe, max_width=300)
if venue.venue_type == 1:
coordinates =(venue.latitude, venue.longitude)
folium.Marker(coordinates,popup=popup,icon=folium.Icon(color='black',icon='utensils',prefix='fa',fill_opacity=1)).add_to(m)
elif venue.venue_type == 2:
coordinates =(venue.latitude, venue.longitude)
folium.Marker(coordinates,popup=popup,icon=folium.Icon(color='red',icon='glass-cheers',prefix='fa')).add_to(m)
elif venue.venue_type == 3:
coordinates =(venue.latitude, venue.longitude)
folium.Marker(coordinates,popup=popup,icon=folium.Icon(color='blue',icon='coffee',prefix='fa')).add_to(m)
elif venue.venue_type == 4:
coordinates =(venue.latitude, venue.longitude)
folium.Marker(coordinates,popup=popup,icon=folium.Icon(color='orange',icon='bread-slice',prefix='fa')).add_to(m)
elif venue.venue_type == 5:
coordinates =(venue.latitude, venue.longitude)
folium.Marker(coordinates,popup=popup,icon=folium.Icon(color='green',icon='shop',prefix='fa')).add_to(m)
context = {'icon_location_json':icon_location_json,'venue_markers':venue_markers,'map_access':m_access._repr_html_,'map':m._repr_html_}
return render(request,'template.html',context)
日志
/None 是(我认为)由于拨动开关。不要指望它与标记有任何关系。
[24/Apr/2023 22:21:00] "GET /list_venues/ HTTP/1.1" 200 55142
Not Found: /list_venues/None
[24/Apr/2023 22:21:00] "GET /list_venues/None HTTP/1.1" 404 16305