同一坐标上的多个标记 [英] Multiple markers on same coordinate

查看:9
本文介绍了同一坐标上的多个标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当从 r 包传单数据中绘制交互式世界地图上的标记时,坐标完全相同.

请看下面的例子:

库(传单)数据<-结构(列表(名称=结构(1:3,.Label = c(M1",M2",M3"),类=因子"),纬度= c(52L,52L,51L), 经度 = c(50L, 50L, 50L), 高度 = c(97L, 97L, 108L)), .Names = c("名称", "纬度", "经度", "高度"), 类 = "data.frame", row.names = c(NA, -3L))传单(数据 = 数据)%>%addProviderTiles("Esri.WorldImagery", options = providerTileOptions(noWrap = TRUE)) %>%addMarkers(~Longitude,~Latitude, popup = ~as.character(paste(sep = "","<b>",姓名,"</b>","<br/>", "海拔: ",海拔)))

可以使用集群选项显示所有坐标,但这远非我的目标.我不想要集群,并且在完全放大时只显示重叠的标记.当完全放大背景地图时,会变成灰色(地图数据尚不可用").重叠标记的蜘蛛视图是我想要的,但在完全放大时不是.

请看下面的例子:

传单(数据=数据)%>%addProviderTiles("Esri.WorldImagery", options = providerTileOptions(noWrap = TRUE)) %>%addMarkers(~Longitude,~Latitude, popup = ~as.character(paste(sep = "","<b>",Name,"</b>","<br/>", "海拔: ",Altitude)), clusterOptions = markerClusterOptions())

我找到了一些关于我想要的解决方案的文献,但我不知道如何在 r 传单代码/包中实现它.https://github.com/jawj/OverlappingMarkerSpiderfier-Leaflet

另外,如果还有其他方法可以处理重叠标记,请随时回答.(例如一个弹出窗口中的多个标记信息)

解决方案

你可以稍微jitter()你的坐标:

图书馆(地图视图)图书馆(SP)数据<-结构(列表(名称=结构(1:3,.Label = c(M1",M2",M3"),类=因素"),纬度 = c(52L, 52L, 51L),经度 = c(50L, 50L, 50L),海拔 = c(97L, 97L, 108L)),.Names = c("姓名", "纬度", "经度", "海拔"),类 = data.frame", row.names = c(NA, -3L))Data$lat <- jitter(Data$Latitude, 因子 = 0.0001)Data$lon <- jitter(Data$Longitude, factor = 0.0001)坐标(数据) <- ~ lon + latproj4string(数据) <- "+init=epsg:4326"地图视图(数据)

这样你还是需要放大标记才能分开,你需要放大多少取决于jitter()中的factor属性.p>

请注意,为了简单起见,我在示例中使用了 library(mapview).

When plotting out markers on a interactive worlmap from the r package leaflet data with exactly the same coordinates will overlap each other.

See the example below:

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)))

There is a possibilty to show all coordinates with the cluster option, but this is far from my goal. I dont want clusters and only the overlapping Markers are shown when fully zoomed in. When fully zoomed in the background map turns into grey("Map data not yet available"). The spider view of the overlapping markers is what i want, but not when fully zoomed in.

See example below:

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())

I found some literatur about the solution i want but i dont know how to implement it in the r leaflet code/package. https://github.com/jawj/OverlappingMarkerSpiderfier-Leaflet

Also if there are other approaches to handle overlapping Markers, feel free to answer. (for example multiple Markers info in one popup)

解决方案

You could jitter() your coordinates slightly:

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)

This way you still need to zoom in for the markers to separate, how far you need to zoom in depends on the factor attribute in jitter().

Note that I am using library(mapview) in the example for simplicity.

这篇关于同一坐标上的多个标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆