我正在尝试完成相当于找到here的Ghybs Leaflet示例,其中选择/取消选择覆盖组显示/隐藏组的标记并使用R的传单包相应地更新聚类。
R here有一个部分解决方案:
quakes <- quakes %>%
dplyr::mutate(mag.level = cut(mag,c(3,4,5,6),
labels = c('>3 & <=4', '>4 & <=5', '>5 & <=6')))
quakes.df <- split(quakes, quakes$mag.level)
l <- leaflet() %>% addTiles()
names(quakes.df) %>%
purrr::walk( function(df) {
l <<- l %>%
addMarkers(data=quakes.df[[df]],
lng=~long, lat=~lat,
label=~as.character(mag),
popup=~as.character(mag),
group = df,
clusterOptions = markerClusterOptions(removeOutsideVisibleBounds = F),
labelOptions = labelOptions(noHide = F,
direction = 'auto'))
})
l %>%
addLayersControl(
overlayGroups = names(quakes.df),
options = layersControlOptions(collapsed = FALSE)
)
此解决方案不会跨群组聚集标记,即使它们是邻近点。对于尝试重新创建此解决方案的任何人,都需要先处理:您需要删除label=~as.character(mag),
和labelOptions = labelOptions(noHide = F, direction = 'auto')
才能运行代码。
如何在保持图层控制的同时完成跨组群集?