r - 在 rShiny 应用程序中使用markerClusterOptions() 时弹出传单

标签 r leaflet gis leaflet.markercluster rshiny

我的困难是,当使用markerClusterOptions()时,无法单击最接近分解圆的点。远离聚类标记的点没有问题。在下面的示例中,弹出窗口适用于距离稍远的 3 个标记,但不适用于距离圆以北最近的标记。有没有办法设置距聚类标记的最小距离或解决此问题的替代方法?

数据集的表示

b <- structure(list(unique_id = c("jm_1987_sierraleone", "jm_1987_sierraleone", 
                             "jm_1987_sierraleone", "jm_1987_sierraleone"), town_village = c("Yengema", 
                                                                                             "Yengema", "Yengema", "Yengema"), classification = c("mastomys natalensis", 
                                                                                                                                                  "mastomys natalensis", "mastomys natalensis", "mastomys natalensis"
                                                                                             ), assay = c("path_1_tested", "path_2_tested", "ab_ag_path_1_positive", 
                                                                                                          "ab_ag_path_2_positive"), number = c(8, 8, 0, 0), pathogen_tested = c("lassa_mammarenavirus", 
                                                                                                                                                                                "lassa_mammarenavirus", "lassa_mammarenavirus", "lassa_mammarenavirus"
                                                                                                          ), pa_colour = c("#f1a340", "#f1a340", "#f1a340", "#f1a340"), 
               lat = c(`12747` = 8.33333301544189, `12748` = 8.33333301544189, 
                       `12749` = 8.33333301544189, `12750` = 8.33333301544189), 
               lon = c(`12747` = -10.6333332061768, `12748` = -10.6333332061768, 
                       `12749` = -10.6333332061768, `12750` = -10.6333332061768)), row.names = c(NA, 
                                                                                                 -4L), sf_column = "geometry", agr = structure(c(unique_id = NA_integer_, 
                                                                                                                                                 town_village = NA_integer_, 
                                                                                                                                                 classification = NA_integer_, assay = NA_integer_, number = NA_integer_, 
                                                                                                                                                 pathogen_tested = NA_integer_, pa_colour = NA_integer_, 
                                                                                                                                                 lat = NA_integer_, lon = NA_integer_), .Label = c("constant", 
                                                                                                                                                                                                   "aggregate", "identity"), class = "factor"), class = "data.frame")

传单代码

leaflet() %>%
  addTiles() %>%
  setView(lng = 0, lat = 10, zoom = 5) %>%
  addCircleMarkers(data = b,
                   fillColor = "black",
                   fillOpacity = 0.3,
                   stroke = F,
                   radius = 1) %>%
  addCircleMarkers(lng = b$lon,
                   lat = b$lat,
                   fillColor = b$pa_colour,
                   fillOpacity = 0.8,
                   stroke = F,
                   radius = 6,
                   popup = paste0("Study ID: ", b$unique_id,
                                  "<br>",
                                  "Rodent species: ", b$classification,
                                  "<br>",
                                  "Microorganism tested: ", b$pathogen_tested,
                                  "<br>",
                                  "Village/Region: ", b$town_village),
                   clusterOptions = markerClusterOptions()) %>%
  clearControls() %>%
  addLegend("topright",
            title = "Presence or Absence",
            colors = c("#f1a340", "#998ec3"),
            labels = c("Absence", "Presence"),
            opacity = 0.8)

挑战的屏幕截图。

Exploded points, popups not shown

Exploded point with popup

最佳答案

一种选择是通过向 markerClusterOptions 添加 spiderfyDistanceMultiplier 来增加蜘蛛化标记距中心的距离,例如:

clusterOptions = markerClusterOptions(spiderfyDistanceMultiplier=1.5)

参见https://github.com/Leaflet/Leaflet.markercluster#customising-the-clustered-markers

关于r - 在 rShiny 应用程序中使用markerClusterOptions() 时弹出传单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67703980/

相关文章:

r - 使用变量名在 R 中创建一个向量

R 和 HDF5 问题

r - ggplot2:在准时间轴上绘制时间序列和多点预测

javascript - 哪个 Leaflet 库或解决方法来控制工具栏大小

json - 将 geojson/json 文件读入 R 以便在 map 上绘制时遇到问题

javascript - Angular leaflet指令点击事件在移动设备上不起作用

r - 在 R 中拆分名称并创建矩阵

google-maps - 带有大陆轮廓/边界的 KML 文件

python - 使用 Shapely 查找多边形的最大内接矩形

compression - 使用 gdal_translate 将 Geotiff 转换为 NetCDF : Huge increase in filesize