当从r包中绘制出交互式worlmap上的标记时,具有完全相同坐标的小叶数据将相互重叠.
请参阅以下示例:
library(leaflet)
Data <- structure(list(Name = structure(1:3, .Label = c("M1", "M2", "M3"), class = "factor"), Latitude = c(52L, 52L, 51L), Longitude = c(50L, 50L, 50L), Altitude = c(97L, 97L, 108L)), .Names = c("Name", "Latitude", "Longitude", "Altitude"), class = "data.frame", row.names = c(NA, -3L))
leaflet(data = Data) %>%
addProviderTiles("Esri.WorldImagery", options = providerTileOptions(noWrap = TRUE)) %>%
addMarkers(~Longitude, ~Latitude, popup = ~as.character(paste(sep = "",
"<b>",Name,"</b>","<br/>", "Altitude: ",Altitude)))
Run Code Online (Sandbox Code Playgroud)
使用群集选项显示所有坐标是可能的,但这远非我的目标.我不想要聚类,只有在完全放大时才显示重叠的标记.完全放大后,背景地图变成灰色("地图数据尚未可用").重叠标记的蜘蛛视图是我想要的,但在完全放大时则不然.
见下面的例子:
leaflet(data = Data) %>%
addProviderTiles("Esri.WorldImagery", options = providerTileOptions(noWrap = TRUE)) %>%
addMarkers(~Longitude, ~Latitude, popup = ~as.character(paste(sep = "",
"<b>",Name,"</b>","<br/>", "Altitude: ",Altitude)), clusterOptions = markerClusterOptions())
Run Code Online (Sandbox Code Playgroud)
我找到了一些关于我想要的解决方案的文献,但我不知道如何在r传单代码/包中实现它. https://github.com/jawj/OverlappingMarkerSpiderfier-Leaflet
此外,如果有其他方法来处理重叠标记,请随时回答.(例如,一个弹出窗口中的多个标记信息)
Tim*_*bim 11
你jitter()
的坐标可以略微:
library(mapview)
library(sp)
Data <- structure(list(Name = structure(1:3, .Label = c("M1", "M2", "M3"),
class = "factor"),
Latitude = c(52L, 52L, 51L),
Longitude = c(50L, 50L, 50L),
Altitude = c(97L, 97L, 108L)),
.Names = c("Name", "Latitude", "Longitude", "Altitude"),
class = "data.frame", row.names = c(NA, -3L))
Data$lat <- jitter(Data$Latitude, factor = 0.0001)
Data$lon <- jitter(Data$Longitude, factor = 0.0001)
coordinates(Data) <- ~ lon + lat
proj4string(Data) <- "+init=epsg:4326"
mapview(Data)
Run Code Online (Sandbox Code Playgroud)
这样你仍然需要放大标记来分开,你需要放大多远取决于factor
属性jitter()
.
请注意,我library(mapview)
在示例中使用的是为了简单起见.