我想创建一个点击标记时会出现一个圆圈的点击功能。到目前为止,我已经开发了一个类,它包含了如下代码所示的相关元素:
df = pd.read_csv("survey.csv")
class Circle(MacroElement):
def __init__(self):
for i,row in df.iterrows():
rad = int(df.at[i, 'radius'])
def __init__(self,
popup=None
):
super(Circle, self).__init__()
self._name = 'Circle',
self.radius = rad * 1560
self._template = Template(u"""
{% macro script(this, kwargs) %}
var circle_job = L.circle();
function newCircle(e){
circle_job.setLatLng(e.latlng).addTo({{this._parent.get_name()}});
circle_job.setRadius({{this.radius}});
circle_job.setStyle({
color: 'black',
fillcolor: 'black'
});
};
{{this._parent.get_name()}}.on('click', newCircle);
{% endmacro %}
""") # noqa
for i,row in df.iterrows():
lat =df.at[i, 'lat']
lng = df.at[i, 'lng']
sp = df.at[i, 'sp']
phone = df.at[i, 'phone']
role = df.at[i, 'role']
rad = int(df.at[i, 'radius'])
popup = '<b>Phone: </b>' + str(df.at[i,'phone'])
job_range = Circle()
if role == 'Contractor':
fs.add_child(
folium.Marker(location=[lat,lng],
tooltip=folium.map.Tooltip(
text='<strong>Contact surveyor</strong>',
style=("background-color: lightgreen;")),
popup=popup,
icon = folium.Icon(color='darkred', icon='glyphicon-user'
)
)
)
fs.add_child (
folium.Marker(location=[lat,lng],
popup=popup,
icon = folium.DivIcon(html="<b>" + sp + "</b>",
class_name="mapText_contractor",
icon_anchor=(30,5))
#click_action = js_f
)
)
fs.add_child(job_range)
其工作但不幸地仅考虑非常第一记录。
我怎样才能使这些弹出的圆调整到给定输入的半径(如CSV文档中所示?)
1条答案
按热度按时间e5nqia271#
您可以更改标记模板以包含点击功能。点击功能将打开弹出窗口并绘制一个圆圈。请参见下面的示例。