英文:
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 & Input Files
library(shiny)
library(shinydashboard)
library(leaflet)
## The Data
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
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(checkboxGroupInput(inputId = "IDPointInput", label = "Select Point ID", choices = choiseList, selected = choiseList)),
dashboardBody(fluidRow(leafletOutput(outputId = 'mapA')))
)
#############################################
# SERVER
server <- function(input, output, session) {
## The Filter
filter_df <- reactive({
Map_DF[sapply(Map_DF$Point_ID, function(p) {any(input$IDPointInput %in% p)}), ]
})
## Base Map Creation
output$mapA <- renderLeaflet({
leaflet() %>%
addProviderTiles(
providers$Esri.DeLorme,
options = providerTileOptions(
updateWhenZooming = FALSE,
updateWhenIdle = TRUE)
) %>%
setView(lng = -107.50, lat = 39.00, zoom = 7)
})
## Update Map with Filter Selection
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))
# 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("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
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(checkboxGroupInput(inputId = "IDPointInput", label = "Select Point ID", choices = choiseList, selected = choiseList)),
dashboardBody(fluidRow(leafletOutput(outputId = 'mapA')))
)
#############################################
# SERVER
server <- function(input, output, session) {
## The Filter
filter_df <- reactive({
Map_DF[sapply(Map_DF$Point_ID, function(p) {any(input$IDPointInput %in% p)}), ]
})
## Base Map Creation
output$mapA <- renderLeaflet({
leaflet(filter_df()) %>%
addProviderTiles(
providers$Esri.DeLorme,
options = providerTileOptions(
updateWhenZooming = FALSE,
updateWhenIdle = TRUE)
) %>%
setView(lng = -107.50, lat = 39.00, zoom = 7) %>%
# use addAwesomeMarkers #
addAwesomeMarkers(
lat = ~Latitude,
lng = ~Longitude,
icon=~makeAwesomeIcon(
icon = 'ios-close',
iconColor = 'black',
library = 'ion',
markerColor = 'orange'),
label=~as.character(Point_ID),
popup = ~paste("PointID: ", Point_ID),
clusterOptions = markerClusterOptions()
)
})
}
############################################
shinyApp(ui = ui, server = server)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论