微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

folium MarkerCluster 如何在python中为颜色编写icon_create_function

如何解决folium MarkerCluster 如何在python中为颜色编写icon_create_function

我有几层数据点需要聚类,我想通过改变颜色和形状来区分它们。我看过几篇关于 tham 的帖子,但我对 js 和 css 编码一无所知。我怎么能写 icon_create_function 像这个例子一样效果

https://leaflet.github.io/Leaflet.markercluster/example/marker-clustering-custom.html

这里我有这样的东西

import numpy as np

size = 100
lons = np.random.randint(-180,180,size=size)
lats = np.random.randint(-90,90,size=size)

locations = list(zip(lats,lons))
popups = ["lon:{}<br>lat:{}".format(lon,lat) for (lat,lon) in locations]

icon_create_function = """\
function(cluster) {
    return L.divIcon({
    html: '<b>' + cluster.getChildCount() + '</b>',className: 'marker-cluster marker-cluster-large',iconSize: new L.Point(20,20)
    });
}"""

from folium.plugins import MarkerCluster

m = folium.Map(
    location=[np.mean(lats),np.mean(lons)],tiles="Cartodb Positron",zoom_start=1
)

marker_cluster = MarkerCluster(
    locations=locations,popups=popups,name="1000 clustered icons",overlay=True,control=True,icon_create_function=icon_create_function,)

marker_cluster.add_to(m)

folium.LayerControl().add_to(m)

m

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。