如何在R的传单包中自定义addMarkers函数的着色?
群集的默认着色是:
我想将范围和颜色更改为:
JS Leaflet具有以下功能:https: //github.com/Leaflet/Leaflet.markercluster#customising-the-clustered-markers
这是否可以通过R包中的markerClusterOptions参数实现?
leaflet(quakes) %>% addTiles() %>% addMarkers(
  clusterOptions = markerClusterOptions()
)
您可以使用iconCreateFunction中markerClusterOptions创建自己的自定义图标功能来显示群集标记.
在您的示例中,您可以只修改默认标记函数(在此处找到),只需修改if/else循环设置标记的CSS类.可以在此处找到为标记着色的默认CSS .如果需要更多自定义,可以创建自己的类.
这是一个代码示例(大的是红色,中间是黄色,小是绿色,所以我只是切换默认代码以匹配您的条件):
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) });
  }"))
)
| 归档时间: | 
 | 
| 查看次数: | 5018 次 | 
| 最近记录: |