作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何在R的传单包中自定义addMarkers函数的颜色?
群集的默认颜色是:
leaflet(quakes) %>% addTiles() %>% addMarkers(
clusterOptions = markerClusterOptions()
)
最佳答案
您可以使用iconCreateFunction
中的markerClusterOptions
创建自己的自定义图标功能来显示聚类标记。
在您的示例中,您可能只需要修改默认标记功能(找到here),然后修改if/else循环来设置标记的CSS类即可。可以为标记着色的默认CSS可以找到here。如果您想进行更多定制,则可以创建自己的类。
这是一个代码示例(大号是红色,中号是黄色,小号是绿色,所以我只是切换了默认代码以匹配您的条件):
library(leaflet)
leaflet(quakes) %>% addTiles() %>% addMarkers(
clusterOptions = markerClusterOptions(iconCreateFunction=JS("function (cluster) {
var childCount = cluster.getChildCount();
var c = ' marker-cluster-';
if (childCount < 100) {
c += 'large';
} else if (childCount < 1000) {
c += 'medium';
} else {
c += 'small';
}
return new L.DivIcon({ html: '<div><span>' + childCount + '</span></div>', className: 'marker-cluster' + c, iconSize: new L.Point(40, 40) });
}"))
)
关于r - R : How to customize the coloring of clusters?的传单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33600021/
我是一名优秀的程序员,十分优秀!