如何在 mapview::addFeatures 内更改圆圈标记属性(例如不透明度和填充不透明度)

How to change circle marker attributes (e.g. opacity & fillOpacity) within mapview::addFeatures

我已经能够在 R-Shiny 应用程序中生成地图,该应用程序允许通过组合 mapview、mapedit 和传单包来选择多个标记。 在功能上一切都很好,除了我想修改标记属性,更具体地说是增加 fillOpacity。

mapview AddFeatures 的文档建议它应该接受传单中用于 addCircleMarkers 的相同参数。我也尝试过使用函数 addCircleMarkers 而不是 addFeatures 但没有成功。

addFeatures doco

... Further arguments passed to the respective leaflet::add* functions. See addCircleMarkers, addPolylines and addPolygons.

但是好像忽略了参数;权重、不透明度和填充不透明度。我在下面的独立代码中标记了参数是否有效。

我是不是做错了什么,或者你认为这是一个错误?

# devtools::install_github("r-spatial/sf")
# devtools::install_github("r-spatial/mapview@develop")
# devtools::install_github("bhaskarvk/leaflet.extras")
# devtools::install_github("r-spatial/mapedit")
library(tidyverse)
library(sf)
library(leaflet)
library(mapedit)
library(mapview)
library(shiny)
library(shinyjs)

locnCoord <-
  data.frame(location = c('Sit1','Site2','Site3'),
             lat=c(-18.1, -18.3, -18.4),
             lon=c(145.8, 145.9, 145.9)) %>%
  mutate(depth = runif(3))

locnSF <- st_as_sf(locnCoord, coords = c('lon','lat'), crs="+proj=longlat +datum=WGS84 +no_defs")

#### User input

ui <- fluidPage(
  shinyjs::useShinyjs(),
  shinyjs::extendShinyjs(text = "shinyjs.refresh = function() { location.reload(); }"),
  fluidRow(
    # edit module ui
    column(6,
           selectModUI("selectmap"),
           actionButton("refresh", "Refresh Map")
           ),
    column(6,
           h3("Point of Depth"),
           plotOutput("selectstat")
           )
    )
  )

#### Server

server <- function(input, output, session) {

  observeEvent(input$refresh, {
    shinyjs::js$refresh()
  })

  g_sel <- callModule(
    selectMod,
    "selectmap",
    leaflet() %>%
      addTiles() %>%
      addFeatures(
      # addCircleMarkers(
        data = locnSF,
        layerId = ~location,
        stroke = TRUE, # This is effective
        color = 'red', # This is effective
        weight = 150, # This is ignored    ####
        opacity = 0, # This is ignored     ####
        fill = TRUE, # This is effective
        fillColor = 'blue', # This is effective
        fillOpacity=1, # This is ignored   ####
        radius=20) # This is effective
  )

  rv <- reactiveValues(selected=NULL)

  observe({
    gs <- g_sel()

    if(length(gs$id) > 0) {
      rv$selected <- locnSF %>% filter(location %in% gs$id)
    } else {
      rv$selected <- NULL
    }
  })

  output$selectstat <- renderPlot({
    ggplot()
    if(!is.null(rv$selected) && nrow(rv$selected) > 0) {
      ggplot(data=rv$selected, aes(location, depth))+
        geom_point(color='red', size=5)
    } else {
      ggplot()
    }
  })
}
shinyApp(ui, server)

他们没有被忽视。如果您尝试作为独立的 mapview 调用,您会发现它们有效。在您的应用程序中,它们被 mapedit 模块 selectMod 屏蔽,该模块允许您分别设置 opacityfillOpacityweight,以应对通过参数选择和未选择功能的情况分别为 styleTruestyleFalse。当您设置这些时,您将获得所需的行为。因此,更改调用 selectMod 模块的部分,如下所示:

g_sel <- callModule(
    selectMod,
    "selectmap",
    leaflet() %>%
      addTiles() %>%
      addFeatures(
        # addCircleMarkers(
        data = locnSF,
        layerId = ~location,
        stroke = TRUE, # This is effective
        color = 'red', # This is effective
        # weight = 150, # This is ignored    ####
        # opacity = 0, # This is ignored     ####
        fill = TRUE, # This is effective
        fillColor = 'blue', # This is effective
        # fillOpacity=1, # This is ignored   ####
        radius=20), # This is effective
    styleFalse = list(fillOpacity = 0.5, weight = 0, opacity = 0), 
    styleTrue = list(fillOpacity = 1, weight = 5, opacity = 1)
  )