R 的传单:如何自定义集群的颜色?

编程入门 行业动态 更新时间:2024-10-09 21:23:31
本文介绍了R 的传单:如何自定义集群的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何自定义 R 的传单包中的 addMarkers 函数的颜色?

How do I customize the coloring of the addMarkers function in the leaflet package for R?

簇的默认颜色是:

  • 1-10 绿色
  • 11-100 黄色
  • 100+ 红色

我想将范围和颜色更改为:

I'd like to change the ranges and colors to something like:

  • 1-100 红色
  • 101-1000 黄色
  • 1000+ 绿色

JS Leaflet 具有以下功能:github/Leaflet/Leaflet.markercluster#customising-the-clustered-markers

JS Leaflet has this capability: github/Leaflet/Leaflet.markercluster#customising-the-clustered-markers

这可以通过 R 包中的 markerClusterOptions 参数实现吗?

Is this possible through a markerClusterOptions parameter in the R package?

leaflet(quakes) %>% addTiles() %>% addMarkers( clusterOptions = markerClusterOptions() )

推荐答案

您可以使用 markerClusterOptions 中的 iconCreateFunction 创建自己的自定义图标函数来显示集群标记.

You can use the iconCreateFunction in the markerClusterOptions to create your own custom icon function to display the cluster markers.

在您的示例中,您可以只修改默认标记函数(找到 here),只需修改 if/else 循环设置标记的 CSS 类.可以在此处找到为标记着色的默认 CSS.如果您想要更多的自定义,您可以创建自己的类.

In your example, you can maybe just modify the default marker function (found here) and just modify the if/else loops setting the CSS class of the markers. The default CSS that colors the markers can be found here. You can create your own classes if you want more customisation.

这是一个代码示例(大是红色,中是黄色,小是绿色,所以我只是切换了默认代码以匹配您的条件):

Here's a code example (large is red coloring, medium is yellow, and small is green so I just switched the default code around to match your conditions):

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 的传单:如何自定义集群的颜色?

本文发布于:2023-07-19 13:46:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1157108.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   传单   集群   颜色

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!