如何自定义 R 传单包中 addMarkers 函数的颜色?
簇的默认颜色是:
- 1-10 绿色
- 11-100黄色
- 100+ Red
我想将范围和颜色更改为:
- 1-100 红色
- 101-1000黄色
- 1000+ 绿色
JS Leaflet有这个功能:https://github.com/Leaflet/Leaflet.markercluster#customising-the-clustered-markers
这可以通过 R 包中的markerClusterOptions 参数实现吗?
leaflet(quakes) %>% addTiles() %>% addMarkers(
clusterOptions = markerClusterOptions()
)
您可以使用iconCreateFunction
in the markerClusterOptions
创建您自己的自定义图标函数来显示聚类标记。
在您的示例中,您也许可以只修改默认标记函数(发现here)并只需修改 if/else 循环设置标记的 CSS 类。可以找到为标记着色的默认 CSShere。如果您想要更多定制,您可以创建自己的类。
这是一个代码示例(大是红色,中是黄色,小是绿色,所以我只是切换默认代码以匹配您的条件):
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) });
}"))
)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)