R Shiny Leaflet显示重叠标记/多边形的数量?

huangapple go评论51阅读模式
英文:

R Shiny Leaflet Show number of overlapping markers / polygons?

问题

以下是您要翻译的内容:

我正在处理一大批位置数据,发现很多位置共享相同的经度和纬度数值。有没有办法通过弹出窗口或其他小部件来显示重叠的标记/多边形数量?

我无法从我的数据集中删除共享经度和纬度数值的站点。

#############################################
# 必需的库和输入文件

library(shiny)
library(shinydashboard)
library(leaflet)

## 数据
Point_ID = c("A1", "B1", "C1")
Latitude = c(38.00, 38.00, 38.00)
Longitude = c(-107.00, -107.00, -107.00)
Map_DF <- data.frame(Point_ID, Latitude, Longitude)

choiseList <- c("A1", "B1", "C1")

#############################################
# 用户界面
ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(checkboxGroupInput(inputId = "IDPointInput", label = "选择点ID", choices = choiseList, selected = choiseList)),
  dashboardBody(fluidRow(leafletOutput(outputId = 'mapA')))
)

#############################################
# 服务器
server <- function(input, output, session) {

  ## 过滤器
  filter_df <- reactive({
    Map_DF[sapply(Map_DF$Point_ID, function(p) {any(input$IDPointInput %in% p)}), ]
  })

  ## 创建基础地图
  output$mapA <- renderLeaflet({
    leaflet() %>%
      addProviderTiles(
        providers$Esri.DeLorme,
        options = providerTileOptions(
          updateWhenZooming = FALSE,
          updateWhenIdle = TRUE)
      ) %>%
      setView(lng = -107.50, lat = 39.00, zoom = 7)
  })

  ## 使用过滤选择更新地图
  observe({
    leafletProxy("mapA", session) %>%
      clearMarkers() %>%
      addCircleMarkers(
        data = filter_df(),
        radius = 10,
        color = "red",
        lat = ~Latitude,
        lng = ~Longitude,
        popupOptions(autoPan = FALSE),
        popup = ~paste("PointID: ", filter_df()$Point_ID))
        # 显示重叠站点的数量
  })
}

############################################
shinyApp(ui = ui, server = server)
英文:

I'm working with a large set of location data, and it turns out a lot of my locations share longitude and latitude values. Is there a way to show the number of markers / polygons that overlap, either through a popup or some other widget?

I can not remove sites that share longitude and latitude values from my dataset.

#############################################
# Needed Libraries &amp; Input Files
library(shiny)
library(shinydashboard)
library(leaflet)
## The Data
Point_ID = c(&quot;A1&quot;, &quot;B1&quot;, &quot;C1&quot;)
Latitude = c(38.00, 38.00, 38.00)
Longitude = c(-107.00, -107.00, -107.00)
Map_DF &lt;- data.frame(Point_ID, Latitude, Longitude)
choiseList &lt;- c(&quot;A1&quot;, &quot;B1&quot;, &quot;C1&quot;)
#############################################
# UI
ui &lt;- dashboardPage(
dashboardHeader(),
dashboardSidebar(checkboxGroupInput(inputId = &quot;IDPointInput&quot;, label = &quot;Select Point ID&quot;, choices = choiseList, selected = choiseList)),
dashboardBody(fluidRow(leafletOutput(outputId = &#39;mapA&#39;)))
)
#############################################
# SERVER
server &lt;- function(input, output, session) {
## The Filter
filter_df &lt;- reactive({
Map_DF[sapply(Map_DF$Point_ID, function(p) {any(input$IDPointInput %in% p)}), ]
})
## Base Map Creation
output$mapA &lt;- renderLeaflet({
leaflet() %&gt;%
addProviderTiles(
providers$Esri.DeLorme,
options = providerTileOptions(
updateWhenZooming = FALSE,
updateWhenIdle = TRUE)
) %&gt;%
setView(lng = -107.50, lat = 39.00, zoom = 7)
})
## Update Map with Filter Selection
observe({
leafletProxy(&quot;mapA&quot;, session) %&gt;%
clearMarkers() %&gt;%
addCircleMarkers(
data = filter_df(),
radius = 10,
color = &quot;red&quot;,
lat = ~Latitude,
lng = ~Longitude,
popupOptions(autoPan = FALSE),
popup = ~paste(&quot;PointID: &quot;, filter_df()$Point_ID))
# Show number of sites that overlap oneanother
})
}
############################################
shinyApp(ui = ui, server = server)

答案1

得分: 2

addAwesomeMarkers在您这里工作吗?

英文:

Does addAwesomeMarkers work for you?

library(shiny)
library(shinydashboard)
library(leaflet)
## The Data
Point_ID = c(&quot;A1&quot;, &quot;B1&quot;, &quot;C1&quot;)
Latitude = c(38.00, 38.00, 38.00)
Longitude = c(-107.00, -107.00, -107.00)
Map_DF &lt;- data.frame(Point_ID, Latitude, Longitude)
choiseList &lt;- c(&quot;A1&quot;, &quot;B1&quot;, &quot;C1&quot;)
#############################################
# UI
ui &lt;- dashboardPage(
dashboardHeader(),
dashboardSidebar(checkboxGroupInput(inputId = &quot;IDPointInput&quot;, label = &quot;Select Point ID&quot;, choices = choiseList, selected = choiseList)),
dashboardBody(fluidRow(leafletOutput(outputId = &#39;mapA&#39;)))
)
#############################################
# SERVER
server &lt;- function(input, output, session) {
## The Filter
filter_df &lt;- reactive({
Map_DF[sapply(Map_DF$Point_ID, function(p) {any(input$IDPointInput %in% p)}), ]
})
## Base Map Creation
output$mapA &lt;- renderLeaflet({
leaflet(filter_df()) %&gt;% 
addProviderTiles(
providers$Esri.DeLorme,
options = providerTileOptions(
updateWhenZooming = FALSE,
updateWhenIdle = TRUE)
)  %&gt;%
setView(lng = -107.50, lat = 39.00, zoom = 7) %&gt;% 
# use addAwesomeMarkers #
addAwesomeMarkers(
lat = ~Latitude,
lng = ~Longitude,
icon=~makeAwesomeIcon(
icon = &#39;ios-close&#39;,
iconColor = &#39;black&#39;,
library = &#39;ion&#39;,
markerColor = &#39;orange&#39;),
label=~as.character(Point_ID),
popup = ~paste(&quot;PointID: &quot;, Point_ID),
clusterOptions = markerClusterOptions()
)
})
}
############################################
shinyApp(ui = ui, server = server)

huangapple
  • 本文由 发表于 2023年2月7日 02:02:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/75364972.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定