remove mapedit features programmatically

喜你入骨 提交于 2021-02-08 20:29:31

问题


With mapedit it is possible to clear drawn features using the 'trash' icon built into the drawbar UI. It is also possible to clear features associated with the leaflet map using clearMarkers() and leafletProxy(), as laid out in this issue. However, leafletProxy does not clear any features drawn by the user. How do I programmatically clear these features? (e.g. after clicking an actionButton).

Here is a simple shiny app and more explanation:

library(mapedit)
library(mapview)
library(shiny)

ui <- fluidPage(
  fluidRow(
    editModUI("editor"),
    actionButton('clear', "Clear features")
  )
)
server <- function(input, output, session) {

  edits <- callModule(editMod, "editor", mapview()@map)

  observeEvent(input$clear, {
    ### some other things will happen here like uploading dropbox
    # then I need to clear the output of edits()
    print(edits())

    ##cannot do this
    # edits()$drawn <- NULL
  })
}
shinyApp(ui, server)

UPDATE: A somewhat hacky solution is to call the module again within the clear event. Is there a better solution?:

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

  edits <- callModule(editMod, "editor", mapview()@map)

  observeEvent(input$clear, {
    ### some other things will happen here like uploading dropbox
      edits <- callModule(editMod, "editor", mapview()@map)
  })
}

来源:https://stackoverflow.com/questions/52503864/remove-mapedit-features-programmatically

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!