同一座标上有多个标记 [英] Multiple markers on same coordinate

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

问题描述

从r包传单数据中以完全相同的坐标绘制交互式worlmap上的标记时,它们将相互重叠.

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

请参见以下示例:

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

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

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.

请参见下面的示例:

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

我对我想要的解决方案有所了解,但是我不知道如何在r传单代码/程序包中实现它. https://github.com/jawj/OverlappingMarkerSpiderfier-Leaflet

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)

推荐答案

您可以稍微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)

这样,您仍然需要放大标记以使其分开,需要放大多远取决于jitter()中的factor属性.

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

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

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

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

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