【发布时间】:2020-12-12 00:31:30
【问题描述】:
我想在地图上添加一些标记,并在上面有一个搜索框和一个图层选择。特别是在标记的某些属性上具有搜索框,在其他属性上具有图层选择。
这是我正在使用的代码。我试过有多个图层,一个用于我想用来选择它们的属性的每个值,然后将它们合并到一个唯一的图层中。但随后搜索不起作用。
Here is what I get 如您所见,图层可以工作,但搜索找不到标记。
import folium
from folium import features
cl_type='Static_clustering'
m = folium.Map([45.75345246,12.34117475], zoom_start=20)
var = np.random.choice([-1,1],size=2)*np.clip(np.abs(np.random.normal(0.0005,scale = 0.0001,size=2)),10**(-6),10**(-4))
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': 500735, 'Categoria': 'A2', 'Cluster': 2},
'geometry': {'type': 'Point', 'coordinates': [12.34127475, 45.75345246]},
'id': '1'}]}
gj = folium.GeoJson(points)
feature_group_cl = {cl:folium.FeatureGroup('cluster '+str(cl)) for cl in [2,3]}
tot_layer = folium.FeatureGroup('all')
for feature in gj.data['features']:
if feature['geometry']['type'] == 'Point':
marker = folium.Marker(location=list(reversed(feature['geometry']['coordinates'])),
icon=folium.Icon(color='red'), Codice =feature['properties']['Codice'],
popup='Hello'
)
#marker.add_to(m)
marker.add_to(feature_group_cl[feature['properties']['Cluster']])
for feat_group in feature_group_cl.values():
feat_group.add_to(tot_layer)
feat_group.add_to(m)
tot_layer.add_to(m)
folium.LayerControl().add_to(m)
Search(
layer=tot_layer,
search_label="Codice",
).add_to(m)
m
【问题讨论】: