传单标签重叠修复 - 传单:: addMarkers

时间:2017-09-25 15:50:22

标签: r maps leaflet

在使用R函数leaflet :: addMarkers时,我正在寻找重叠标签的修复。

long <- c(147.768, 147.768, 147.768,147.768, 147.768, 147.768)
lat <- c(-36.852, -36.852, -36.852,-36.852, -36.852, -36.852)
label <- c('long label1', 'long label2', 'long label3','long label4', 'long label5', 'long label6')

markers <- data.frame(lat,long,label)


leaflet() %>%
  addTiles() %>%  # Add default OpenStreetMap map tiles
  addMarkers(lng=markers$long, lat= markers$lat, 
             popup="The birthplace of R",
             label = markers$label,
             labelOptions = labelOptions(noHide = T, direction = 'auto'),
            clusterOptions = markerClusterOptions()
             )

1 个答案:

答案 0 :(得分:1)

您可以在labelOptions

中设置noHide = F而不是noHide = T

您可以尝试添加options = markerOptions(riseOnHover = TRUE)以在标记顶部添加标签。

最终代码为:

leaflet() %>%
  addTiles() %>%  # Add default OpenStreetMap map tiles
  addMarkers(lng=markers$long, lat= markers$lat, 
             popup="The birthplace of R",
             label = markers$label,
             labelOptions = labelOptions(noHide = F, direction = 'auto'),
             options = markerOptions(riseOnHover = TRUE),
             clusterOptions = markerClusterOptions()
             )